I have a perl script that converts a tab delimited file
to a comma delimited file - simple stuff. The script
reads STDIN from the input tab delimited file and
outputs to a CSV file.
The simple code is as follows:
############################################################# # # tab2comma.pl # Convert Tab Delimited File to Comma Delimited File (CSV) # ############################################################ while ( <> ) { tr/\t/,/; print; }
I execute this from the command line as follows:
perl tab2comma.pl psa.tab > psa.csv
where psa.tab is the input tab-delimited file and
psa.csv is the output comma-delimited file.
I am attempting to modify this script, so that it can
be included as a snippet in a larger perl script. I am
not quite sure how to do this and I am getting an
error message which I am not familiar with.
My modified code is:
############################################################ # testtab2comma.pl # Convert Tab Delimited File to Comma Delimited File (CSV) # ############################################################ my $file = "sortpsalog.dat"; open (my $fh,"<", $file) or die "Can't open file $file: $!"; open (my $OUT,">","sortpsalog2.csv") or die "Can't open sort output fi +le: $!"; while <my $line = <$fh>) { chomp($line); ## $line =~ tr/\t/,/; $line =~ s/\t/,/g; print $OUT "$line \n"; } close $fh or die "Can't close input file: $!"; close $OUT or die "Can't close output csv file: $!";
Glob not terminated at testtab2comma.pl line 17.
Line 17 is the while loop statement. I would appreciate
any assistance on how to convert from the 1st technique
to the 2nd technique or if someone could help me with
the 2nd technique I am devising and the error message
I am getting.
In reply to Using Substitution Operator In Perl Script by country1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |