Akatsuki has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks, I need your guidance with an issue. I have a script that I want to use on multiple files from the same folder with the script and write the output for each file with a different extension. For example: file1.txt file2.txt file3.txt after being processed by my script become file1.csv file2.csv file3.csv My script is
#!/usr/bin/env perl use strict; use warnings; print "Enter the name of the original file(including termination): "; my $original = <STDIN>; chomp ($original); print "Enter the name of the final file(including termination): "; my $final = <STDIN>; chomp ($final); open( my $original_fh, "<", $original ) or die $!; open( my $final_fh, ">", $final ) or die $!; my $first = <$original_fh>; print $final_fh $first; my @replace = $first =~ /"([^"]*)"/g; while (my $line = <$original_fh>) { print "Enter the desired number of columns: "; my $nr = <STDIN>; chomp($nr); $line =~ s/((\w\w\t){$nr})/$1\n/g; $line =~ s/\t/,/g; $line =~ s/(\d{2})/$replace[$1]/g; print $final_fh $line; } close $original_fh; close $final_fh;
I want this script to read all files with a specified extension from it's folder so I don't have to enter the files manually when there are to many files. I have tried a few methods unsuccessfully, but I am new to perl and still learning the basics...thank you for any help I can get!
|
|---|