ways to change the first char from a filename (with full path)

From: Rod Za (rodzadra_at_yahoo.com)
Date: 06/29/04


Date: Tue, 29 Jun 2004 09:03:42 -0700 (PDT)
To: beginners@perl.org

Hi all,

i'm trying to make a code that get a file name (with full path) and change the first char of the
filename. Someone can say me if there's a better way to do this?:

_BEGIN_
#!/usr/bin/perl -w
my($file) = $ARGV[0]; #receives the filename
my @tmp = split(/\//,$file); #split the path
$tmp[$#tmp] =~ s/.(\w+)/c$1/g; #change the first char of the filename
my $IPPFile = join('/',@tmp); #join again path+'/'+filename
print "Original Filename: $file - Changed Filename: $IPPFile\n"; #print the result
_END_

e.g. ./filename.pl /var/spool/cups/d00001
will print:

Original Filename: /var/spool/cups/d00001 - Changed Filename: /var/spool/cups/c00001

Thank you.

Rod

        
                
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail



Relevant Pages