#!/usr/bin/perl ###################################################################### # Name: cda.pl # Desc: CD to alternate directory (optionally to sub-directory). ###################################################################### use strict; use warnings; my $dir = "\\newdir"; if (@ARGV) { $dir .= "\\subdir" . rj(2,'0',shift); } my $ofile = "\\bat\\aa.bat"; open(OFILE, '>', $ofile) or die "Error opening $ofile: $!\n"; print OFILE "cd $dir\n"; print OFILE "cls\n"; print OFILE "dir /p /ogen\n"; close OFILE; exit; ################################################################### # This subroutine adds commas and right-justifies input number. ################################################################### sub rj { my $pad = shift; my $dlm = shift; local($_)=@_; 1 while s/(.*\d)(\d\d\d)/$1,$2/; $_ = ${dlm}x($pad-length($_)).$_; }