Thank you very much for your help, but after I turn my code into a function, I still can't figure out how to read all the files and replace the extension...I wrote something like this:
#!/usr/bin/perl use warnings; use strict; sub process_file { my ($original, $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; } my @files = glob '*.txt'; my $new_file = $name =~ s/txt$/csv/r; process_file($files, $new_file);
but I know it can't run...I didn't quite understand how can I use the substitution that you wrote because I know that $name is not declared. I appreciate any advice you can give me!
In reply to Re^2: Read from multiple files change the data with a script and the write the respective output files with a different extension
by Akatsuki
in thread Read from multiple files change the data with a script and the write the respective output files with a different extension
by Akatsuki
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |