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"; } }