Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Perl
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 9th, 2011, 06:29 AM
Registered User
 
Join Date: May 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
 
Old May 10th, 2011, 12:28 AM
Authorized User
 
Join Date: Aug 2009
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?





Similar Threads
Thread Thread Starter Forum Replies Last Post
C# Reverse Compilation yycheah C# 2008 aka C# 3.0 1 October 2nd, 2009 11:01 AM
How to reverse an array here? code_lover C++ Programming 3 February 25th, 2009 09:10 AM
Reverse Feed senthilworld VB How-To 1 October 25th, 2007 03:07 PM
scalar and reverse crmpicco Perl 2 February 16th, 2007 08:18 AM
Reverse Engineering abdul_owiusa General .NET 0 July 18th, 2006 10:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.