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

My program works on this machine:
perl -v "This is perl, version 5.005_03 built for sun4-solaris"

But, not on this machine:
perl -v "This is perl, version 5.003_26"

Here's the portion of code that fails:
50. foreach $key (keys %hash) { 51. my $tmp = $_; 52. my $cmd = "$program $key $matrix "; 53. $cmd .= "$config_path/CISCO_$tmp.clean " for @{$hash{$key}}; 54. system($cmd) == 0 || die "$cmd failed:$!\n"; 55. }
Here's what it fails with:
syntax error at ./cflowd-config-gen.pl line 53, near ""$config_path/CI +SCO_$tmp.clean " for " syntax error at ./cflowd-config-gen.pl line 53, near "}}" Execution of ./cflowd-config-gen.pl aborted due to compilation errors.
I have no idea why this is failing. And, it needs to be run on the machine that it fails on.

Replies are listed 'Best First'.
(tye)Re: Works on one machine, fails on another
by tye (Sage) on Feb 01, 2001 at 23:04 UTC

    for wasn't allowed as a statement modifier before 5.005. Check the Changes* files of the source distribution for much more information.

    Change your "statement for expr" to "for(expr){statement}" to make your code portable to older versions of Perl.

            - tye (but my friends call me "Tye")
Re: Works on one machine, fails on another
by runrig (Abbot) on Feb 01, 2001 at 22:57 UTC
    system() should return zero (false) on success, so use an 'and', not an 'or' operator. I don't have the precedence of operators memorized, but I'd also change the '||' to 'and' and not '&&'.

    Update:After checking the precedence, it's not really necessary to use 'and' instead of '&&' here, but to me it makes the intention more clear.

    Ups! duh. missed the '== 0'. More coffee for me please.

      ups! Yes, system returns 0 on success, so with the explict system('foo') ==0 || die "bar"; in this situation, that's just what's wanted. If the LHS of the || evaluates as true, Perl won't bother with the RHS.

      The use of &&/and you point to is equivalent to an if : If the LHS of an && is true, Perl goes on to evaluate the RHS, but doesn't bother if the LHS is false. So his code is correct on that aspect.

      I don't know enough Perl history to answer the original question, though =(

      Just for the record, the 'english' and and or are 'super-low precedence' versions of && and ||

      Philosophy can be made out of anything. Or less -- Jerry A. Fodor