You're pretty close:
use strict; use warnings; my @lines; foreach my $file ( reverse @ARGV ) { open my $fh, '<', $file or die "Bleah: $!"; my( @slurp ) = <$fh>; push @lines, reverse @slurp; close $fh; } print foreach @lines;

This could be done with a lot more memory efficiency (without slurping the files) if you take steps to read the file in backwards in the first place (using File::ReadBackwards or Tie::File). But I kept it to stuff that you would probably find explained in the Llama book.

You usually automagically open the contents of @ARGV with the bare <> operator. Since I wanted to treat the files in reverse order, I didn't use <>'s magic, and instead opened the files explicitly. Actually that step could have been avoided if I had reversed the contents of @ARGV first, and then still relied upon <> to do its magic.

UPDATE: I wanted to go ahead and show how it is simplified by letting <> do its magic. Here goes:

use strict; use warnings; my @lines; @ARGV = reverse @ARGV; foreach ( @ARGV ) { my( @slurp ) = <>; push @lines, reverse @slurp; } print foreach @lines;

Enjoy!


Dave


In reply to Re: Llama ./tac stumper by davido
in thread Llama ./tac stumper by bluethundr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.