Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Can you guess the result? Is it a bug?

by edoc (Chaplain)
on Jul 31, 2003 at 03:28 UTC ( [id://279465]=note: print w/replies, xml ) Need Help??


in reply to Can you guess the result? Is it a bug?

hmmm.. what am I doing wrong here? (perl, v5.8.0 built for i686-linux)

]$ perl -wMstrict -e"if( my($test) = 0 ) { print 'Passed'; } else { pr +int 'Failed'; }" Can't declare stub in "my" at -e line 1, near ") =" Execution of -e aborted due to compilation errors. ]$ perl -wMstrict -e"if( my($test) = '' ) { print 'Passed'; } else { p +rint 'Failed'; }" Can't declare stub in "my" at -e line 1, near ") =" Execution of -e aborted due to compilation errors. ]$ perl -wMstrict -e"if( my($test) = undef ) { print 'Passed'; } else +{ print 'Failed'; }" Can't declare stub in "my" at -e line 1, near ") =" Execution of -e aborted due to compilation errors. ]$ perl -wMstrict -e "if( my $test = undef ) { print 'Passed'; } else +{ print 'Failed'; }" syntax error at -e line 1, near "my =" Execution of -e aborted due to compilation errors.

I had to swap "/' to get it to run..

]$ perl -wMstrict -e 'if( my ($test) = undef ) { print "Passed"; } els +e { print "Failed"; }' Passed ]$ perl -wMstrict -e 'if( my $test = undef ) { print "Passed"; } else +{ print "Failed"; }' Failed

cheers,

J

Replies are listed 'Best First'.
Re: Re: Can you guess the result? Is it a bug?
by The Mad Hatter (Priest) on Jul 31, 2003 at 03:47 UTC
    Because $test is in double-quotes, your shell is trying to interpolate it. Since it isn't set though (and there aren't such things as warnings and strict for the shell ; ), it is replaced with nothing and becomes:
    perl -wMstrict -e"if( my() = 0 ) { print 'Passed'; } else { print 'Fai +led'; }"
    If you escape the $ you'll be fine.
    perl -wMstrict -e"if( my(\$test) = 0 ) { print 'Passed'; } else { prin +t 'Failed'; }"
      A better way is to make sure the shell doesnt even try...
      perl -wMstrict -e'if( my() = 0 ) { print "Passed"; } else { print "Failed"; }'

      T I M T O W T D I
Re: Re: Can you guess the result? Is it a bug?
by BrowserUk (Patriarch) on Jul 31, 2003 at 03:45 UTC

    Different command line semantics between Win32 and linux shells.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://279465]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found