Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Perl
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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?
Reply With Quote
  #2 (permalink)  
Old May 10th, 2011, 12:28 AM
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
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:51 PM.


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