in reply to Writing files in reverse..and more

You kids are verbose. A round of Perl Golf, shall we?
print scalar( reverse substr( $_, 0, rindex($_," //") ) ) while (<>);
Update davorg is correct - I fixed a few syntax errors. I had the "\n" on the command line I used to test, but apparently missed it when submitting the article. davorg's solution is better than mine - the map is a nice touch.

mikfire

Replies are listed 'Best First'.
RE: RE: Writing files in reverse..and more
by davorg (Chancellor) on Jul 28, 2000 at 20:30 UTC

    Cheat! You just corrected the first problem that I saw (incorrect arguments to rindex).

    The other problem is that it runs all of the lines together, you need to print "\n" at the end of each line like this:

    print scalar( reverse substr( $_, 0, rindex($_," //") ) ), "\n" while +(<>);

    but if we're playing golf then you can save a couple of strokes by using map

    print map { scalar reverse(substr( $_, 0, rindex($_," //") )), "\n" } +<>;
    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000, ICA, London
    <http://www.yapc.org/Europe/>
      A slightly more full featured try with a few more strokes (outside the map), using davorgs origional post meathod of spliting.
      { local $\="\n" => select STDOUT; # Or what ever FileHandle map { print scalar reverse( (split m!\s+//!)[0] ) } <DATA> }
      Enjoy!
      --
      Casey
      
Re^2: Writing files in reverse..and more
by Anonymous Monk on Jul 16, 2004 at 02:05 UTC
    salut monkey tu es con et encule