p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Perl (http://p2p.wrox.com/forumdisplay.php?f=196)
-   -   reverse not working (http://p2p.wrox.com/showthread.php?t=83582)

PerlProgrammer May 9th, 2011 06:29 AM

reverse not working
 
Hi All,

The piece of code below doesnot print the string backwards

while(<STDIN>)
{
print "Backwards is ",reverse($_),"\n";
}

unlike this one which works

while(<STDIN>)
{
my $reverse = reverse $_;
print "Backwards is $reverse \n";
}

Why is that ,please advice?

chorny May 10th, 2011 12:28 AM

Quote:

Originally Posted by PerlProgrammer (Post 271888)
Hi All,

The piece of code below does not print the string backwards

while(<STDIN>)
{
print "Backwards is ",reverse($_),"\n";
}

See http://p3rl.org/reverse . First example has list context, so it reverses list which contains only one element. Second example forces scalar context.

Quote:

Originally Posted by PerlProgrammer (Post 271888)
unlike this one which works

while(<STDIN>)
{
my $reverse = reverse $_;
print "Backwards is $reverse \n";
}

Why is that ,please advice?



All times are GMT -4. The time now is 06:42 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.