Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: basic question:how to print a reversed array from STDIN

by poolpi (Hermit)
on Dec 04, 2008 at 14:14 UTC ( [id://727983]=note: print w/replies, xml ) Need Help??


in reply to basic question:how to print a reversed array from STDIN

;)

chop( $_ = <STDIN> ); print chop while $_;

PooLpi

'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

Replies are listed 'Best First'.
Re^2: basic question:how to print a reversed array from STDIN
by ikegami (Patriarch) on Dec 04, 2008 at 16:57 UTC
    Three bugs:
    • It doesn't print the last character of the input if the line has no line ending.
    • It doesn't print a trailingleading zero.
    • It's a poor way of achieving the goal.

      Dear ikegami,

      I had never have the intention to submit this little piece of code to Perl 6 core modules...

      For me, it was just a funny variation on chomp.

      To be constructive, please give some examples because i can't reproduce two of your three remarks

      Laziness, impatience, hubris and why not humility.

      hth,
      PooLpi

      'Ebry haffa hoe hab im tik a bush'. Jamaican proverb
        I use an in-memory file, but a real file will do just as well.
        { my $f; { open(my $fh, '>', \$f) or die $!; print $fh "abc"; } { open(my $fh, '<', \$f) or die $!; chop( $_ = <$fh> ); print chop while $_; # ba print"\n"; } } { my $f; { open(my $fh, '>', \$f) or die $!; print $fh "012\n"; } { open(my $fh, '<', \$f) or die $!; chop( $_ = <$fh> ); print chop while $_; # 21 print"\n"; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://727983]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-19 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found