Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A little question about "print"

Status
Not open for further replies.

moroshko

Programmer
May 24, 2008
14
IL
Hello !

Can someone explain me please why
print 3==4;
prints nothing ?

I would expect 3==4, which is false, to be converted to 0, so I expect "print" to print "0". Where am I wrong ?

Thanks !
 
perlsyn said:
The number 0, the strings '0' and '', the empty list (), and undef are all false in a boolean context. All other values are true. Negation of a true value by ! or not returns a special false value. When evaluated as a string it is treated as '', but as a number, it is treated as 0.

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Hi Franco,
Thank you for the explanation.
I agree with what you said, but still cannot understand the issue.
What do you mean by "special false value" ? Does Perl has "false value" and "special false value" ?
As I understand, 3==4 evaluates as false, but "print" expect list, so 3==4 evaluated in list context, right ?
Is there some rule that 'false' in list context is evaluated as empty list, (), and 'true' in list context is evaluated as this list: (1) ?
Thank you in advance !
 
That was a quote from perl documentation, so that's not me!
It's a perl rule indeed that everything that evaluates as false in a boolean operation will return something that I don't know exactly what it is (but does it matter?), but might be called a null (term that's not used by perl): once you understand that just use [tt]print 3==4?1:0;[/tt] instead.

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top