Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Reverse standard input

Reply
Thread Tools

Reverse standard input

 
 
perler wannabe
Guest
Posts: n/a
 
      11-01-2010
Hi,

Why my script doesn't reverse my input?

#!/usr/bin/perl -w
@lines=<STDIN>;
@backwardlines=reverse @lines;
print @backwardlines;

This script print the same thing as my keyboard input.

So if I input:
beginning perl

the output will be:
beginning perl

I am expecting the following output though:
perl beginning

Am I missing something?

Thanks
 
Reply With Quote
 
 
 
 
Mart van de Wege
Guest
Posts: n/a
 
      11-01-2010
perler wannabe <(E-Mail Removed)> writes:

> Hi,
>
> Why my script doesn't reverse my input?
>
> #!/usr/bin/perl -w
> @lines=<STDIN>;
> @backwardlines=reverse @lines;
> print @backwardlines;
>
> This script print the same thing as my keyboard input.
>
> So if I input:
> beginning perl
>
> the output will be:
> beginning perl
>
> I am expecting the following output though:
> perl beginning
>
> Am I missing something?


Yup.

The <> operator is called readline for a reason.

You're trying to reverse the order between a single line and itself.

Mart

--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
 
Reply With Quote
 
 
 
 
Vivien MOREAU
Guest
Posts: n/a
 
      11-01-2010
On 2010-11-01, bugbear wrote:

> Mart van de Wege wrote:
>>
>> Yup.
>>
>> The <> operator is called readline for a reason.

>
> But, from the camel book:
>
> >> However, if you use the operator in a list context, a list consisting of all remaining input lines is returned, one line per list element.


Yes, one line of input per list element:
__EXAMPLE__
hello world
42
__END__

is ('hello world', '42').

--
Vivien MOREAU

 
Reply With Quote
 
Vivien MOREAU
Guest
Posts: n/a
 
      11-01-2010
On 2010-11-01, Tad McClellan wrote:

> What happened to the newlines?


I ate them. Sorry, you're right.

--
Vivien MOREAU

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What are the standard network functions provided in standard C? disappearedng@gmail.com C Programming 5 06-10-2008 08:57 PM
add pexpect to the standard library, standard "install" mechanism. funkyj Python 5 01-20-2006 08:35 PM
bitset<> consumes input in the reverse order. Artemis Fowl C++ 5 10-28-2005 02:34 PM
How standard is the standard library? steve.leach Python 1 04-18-2005 04:07 PM
Stacks Queues Reverse Reverse Polish dogbite C++ 4 10-10-2003 05:06 AM



Advertisments