I have a perl program where the user enters in the file they want to "pad" variable length files to fixed length files based on the longest line,
EX: INPUT "variable"
I wish to pad this
file
into fixed
length.
EX: OUTPUT "fixed"
I wish to pad this
fileXXXXXXXXXXXXXX
into fixedXXXXXXXX
length.XXXXXXXXXXX
I have the code completed to do all of this but I need a way to take the file they entered and call it that filenamepad.ext? Here's what I have.
my $padchar = 0;
#this is given to the user from another program
print "enter the number of characters to pad to";
chomp ($padchar = <STDIN>);
print "enter file to pad"; #say padthis.txt
chomp ($file = <STDIN>);
open (FILE, "<$file"
or die "can't open $!\n";
while (<FILE>){
$linelength = length ($_);
$bufferlength = $padchar - $linelength;
print $_;
for ($i=0; $i<$bufferlength; $i++){
print "X";
}
close FILE;
it works sending to the screen but I need it to go to padthisdpad.txt leaving the original untouched. also I cant hard code the file name because each file that needs to be padded may have different extensions based on what ever they enter. Is there a way I can take the file they entered and rename it without hardcoding the filename? I hope I explained it well enough.
EX: INPUT "variable"
I wish to pad this
file
into fixed
length.
EX: OUTPUT "fixed"
I wish to pad this
fileXXXXXXXXXXXXXX
into fixedXXXXXXXX
length.XXXXXXXXXXX
I have the code completed to do all of this but I need a way to take the file they entered and call it that filenamepad.ext? Here's what I have.
my $padchar = 0;
#this is given to the user from another program
print "enter the number of characters to pad to";
chomp ($padchar = <STDIN>);
print "enter file to pad"; #say padthis.txt
chomp ($file = <STDIN>);
open (FILE, "<$file"
while (<FILE>){
$linelength = length ($_);
$bufferlength = $padchar - $linelength;
print $_;
for ($i=0; $i<$bufferlength; $i++){
print "X";
}
close FILE;
it works sending to the screen but I need it to go to padthisdpad.txt leaving the original untouched. also I cant hard code the file name because each file that needs to be padded may have different extensions based on what ever they enter. Is there a way I can take the file they entered and rename it without hardcoding the filename? I hope I explained it well enough.