Saturday, February 5, 2011

PERL : File I/O Rename

nano rename1.pl
#!/usr/bin/perl -w
open (HAN, "teststrings.txt") || die "Problem : $!";
@f1 = <HAN>;
foreach(@f1)
{
print $_;#we don't need new line characters
}
#end
chmod u+x rename1.pl
./rename1.pl


#!/usr/bin/perl -w
open (HAN, "teststrings.txt") || die "Problem : $!";
@f1 = <HAN>;
foreach(@f1)
{
print $_;#we don't need new line characters
$new = uc;#converts the string to upper case; lc-lower case
#ucfirst -upper case the first character
#lcfirst -lower case the first character
print $new;
}
#end


#!/usr/bin/perl -w
$DIR = "/root/temp2/perl/FILE*";
@filelist = `ls -A $DIR`;
foreach(@filelist)
{
print $_;
chomp;
$new = lcfirst;
print $new;
rename ($_,$new);#rename the file using lower case
}
#end
touch FILE{1,2,3,4,5}


#!/usr/bin/perl -w
$DIR = "/root/temp2/perl/";
$FILES = "FILE*";
@filelist = `ls -A $DIR/$FILES`;
foreach(@filelist)
{
print $_;
chomp;
$new = lcfirst;
print $new;
rename ("$DIR/$_","$DIR/$new");#rename the file using lower case
}
#end

No comments:

Post a Comment