eudoro has asked for the wisdom of the Perl Monks concerning the following question:

I am new to Perl programming. I just got a script, but I get an error when executing. This perl script will show you the amount of CPU for each user on an AIX machine. Where is the error? Thanks, Eudoro
#!/usr/bin/perl -w use strict; my(@proc,%cpu,%mem,$cpu,$mem,$user,$key,$lup); @proc = `ps -Ao "%U:%C:%z"`; for ($lup=1;$lup<=$#proc;$lup++) { ($user,$cpu,$mem)=split(/:/,$proc[$lup]); $cpu{$user}+=$cpu; $mem{$user}+=$mem; } foreach $key(keys %cpu) { print "$key\t\t$cpu{$key}\t\t$mem{$key}\n"; }
Error Message: ksh: 0403-057 Syntax error: `(' is not expected.

Replies are listed 'Best First'.
Re: Syntax Error
by Abigail-II (Bishop) on Jan 20, 2004 at 15:35 UTC
    Error Message: ksh: 0403-057 Syntax error: `(' is not expected.
    Try feeding the program to perl. (Perl, that is. Perl, perl, perl. No 'a' in it).

    Abigail

      Sorry about the 'a'. How do I feed it to perl? I thought I just had to place the statement: #!/usr/bin/perl -w in the script. Eudoro
        There are a couple of possibilities here.

        1 -- The 'shebang line' ("#! /user ...") may have a leading space. The Shell, not finding '#!' as the first two characters takes off an tries to parse/run the "ksh" script it has just discovered.

        2 -- The first line in the file is empty, so the Shell having no other guidance takes off and fails during the parse.

        ----
        I Go Back to Sleep, Now.

        OGB

        Placing a she-bang line is only half the trick - the kernel must also sniff at it. How are you calling your program, and what are its execution bits?

        Abigail

Re: Syntax Error
by Anonymous Monk on Jan 21, 2004 at 14:39 UTC
    If I type: perl test.pl it works. Thanks to everyone for all your help. Eudoro