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: $!";

When I execute this perl script I am getting the
following error message:


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.