View Single Post
  #2 (permalink)  
Old May 10th, 2011, 12:28 AM
chorny chorny is offline
Authorized User
Points: 93, Level: 1
Points: 93, Level: 1 Points: 93, Level: 1 Points: 93, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2009
Location: Moldova
Posts: 23
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by PerlProgrammer View Post
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 View Post
unlike this one which works

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

Why is that ,please advice?
Reply With Quote