2

I have a simple question. I have been using the zoidberg perl shell to get myself familiarized with perl interactively. I like being able to test my stuff on the fly before I flesh out a script. (I am a novice learner.)

My question is, in the shell I can do the following:

@a = `df -h | grep /dev/mapper | cut -c 48-`

for $i (@a) { @b=`ls $i` }
print @b;

However, when I put this in a script in linux:

#!/bin/perl

I see the following error when I run the script:

syntax error at perl_diskstats.perl line 5, near "$i ( "
Execution of perl_diskstats.perl aborted due to compilation errors.

Am I doing something obvious here? What exactly am I doing wrong? I thought the format was..

foreach $var (@array) { codeblock }

... right?

3
  • 4
    You're missing a semi-colon at the end of your first line. Commented Jun 13, 2012 at 22:29
  • holy moly you are awesome, and I am so dumb thank you! Commented Jun 13, 2012 at 22:30
  • @ire_and_curses You should make that comment an answer. Commented Jun 13, 2012 at 22:57

2 Answers 2

7

You're missing a semi-colon at the end of your first line.

Sign up to request clarification or add additional context in comments.

Comments

0

Also you are missing use strict, and the my declarations.

use strict;

my @a = `df -h | grep /dev/mapper | cut -c 48-`;

my @b;
for my $i (@a) { @b=`ls $i` }

print @b;

Start off on the habit of use strict now, while you're still beginning. It will save you in the longterm.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.