#!/usr/bin/perl #H# This script reads a list of parameters from the command line and prints them out in reverse order. #H# This is useful to reverse the order of the shell globbing. #H# I originally wrote this because I wanted to be able to run du -shc somebackup.yyyy-mm-dd.HH-MM-ss #H# but have the order reversed so that the most recent backup is shown first. Now I can do that with: #H# du -shc `rglob somebackup.*` # print out help info if requested if ($ARGV[0] eq "-h" || $ARGV[0] eq "--help" || $ARGV[0] eq "help" || $ARGV[0] eq "") { open (SELF, $0); while () { if ($_ =~ /^#H# /) { $_ =~ s/^#H# //; print $_; } } exit; } @RArgs=(); # step through the ARGV array one by one and stuff the entries into the RArgs array backwards. while ($#ARGV) { push (@RArgs, pop(@ARGV)); } # need one more to handle case of $#ARGV=0 which actually means there is 1 left. push (@RArgs, pop(@ARGV)); # final output. print "@RArgs\n";