in reply to Switching the Order of Lines

If you reverse the line order and the order of characters within your lines, it should do the trick (if I understood what you are looking for). This is a Perl one-liner used on one program random file sitting in my main directory:

$ perl -e '@c = reverse <>; for (@c) {$d = reverse $_; print $d}' coderef.pl

On my file, I get the following reesult

;)f$(evitatnet } ;))0 == ruoter_edoc$( && ) 1 => sevitatnet_bn$(( elihw } ;--sevitatnet_bn$ ;ruoter_edoc$ tnirp ;))(>-g$( lave = ruoter_edoc$ ym { od ;3 = sevitatnet_bn$ ym ;tfihs = g$ ym { evitatnet bus ;};"otot" tnirp{ bus = f$ ym ;sgninraw esu ;tcirts esu

The last line above is a reverse 'use strict;' line that was at the beginning of my file.

Replies are listed 'Best First'.
Re^2: Switching the Order of Lines
by hdb (Monsignor) on Oct 29, 2013 at 07:31 UTC

    In order to print the whole file reversed, it is easier to slurp it into a string:

    perl -e "local $/; print scalar reverse <>" coderef.pl

      Yes, indeed, you are right. I wanted to keep the two-step approach shown by others before, but there is no real reason to do so.