slu*_*man 2 perl foreach for-loop
我有一个简单的问题.我一直在使用zoidberg perl shell让我自己熟悉perl交互式.在我充实脚本之前,我喜欢能够在飞行中测试我的东西.(我是新手学习者.)
我的问题是,在shell中我可以执行以下操作:
@a = `df -h | grep /dev/mapper | cut -c 48-`
for $i (@a) { @b=`ls $i` }
print @b;
Run Code Online (Sandbox Code Playgroud)
但是,当我把它放在linux中的脚本中时:
#!/bin/perl
Run Code Online (Sandbox Code Playgroud)
我运行脚本时看到以下错误:
syntax error at perl_diskstats.perl line 5, near "$i ( "
Execution of perl_diskstats.perl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)
我在这里做些明显的事吗?我究竟做错了什么?我以为格式是......
foreach $var (@array) { codeblock }
Run Code Online (Sandbox Code Playgroud)
... 对?