Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: ?: (conditional operator)

by Cine (Friar)
on Aug 23, 2001 at 17:49 UTC ( [id://107322]=note: print w/replies, xml ) Need Help??


in reply to ?: (conditional operator)

This looks like a bug in perl. It seems that both the true and false part is evalueted wrongly, if there is '=' in the false case.
I've tried the following:
perl -e '$x="\nYo "; print ($x ? $x.="hello" : $x.="Bye");' => 'Yo hel +loBye' perl -e '$x="\nYo "; print ($x ?($x.="hello") : ($x.="Bye"));' => 'Yo +hello' perl -e '$x="\nYo "; print ($x ? $x."hello" : $x."Bye");' => 'Yo hello +' perl -e '$x="\nYo "; print ($x ? $x."hello" : $x.="Bye");' => Can't mo +dify concatenation (.) or string in concatenation (.) or string at -e + line 1, near ""Bye")" Execution of -e aborted due to compilation errors. perl -e '$x="\nYo "; print ($x ? $x."hello" : ($x.="Bye"));' => 'Yo he +llo'


Update:

Nope, not a bug, perl just doenst do what you expect ;( It's a precedence fault as masem points out.

T I M T O W T D I

Replies are listed 'Best First'.
Re: Re: ?: (conditional operator)
by echo (Pilgrim) on Aug 23, 2001 at 18:08 UTC
    doesn't do what you expect

    Remember the Camel's words: Perl does what you expect, provided you expect the right thing.

Log In?
Username:
Password:

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

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

    No recent polls found