Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Using Substitution Operator In Perl Script

by duckyd (Hermit)
on Aug 28, 2007 at 16:58 UTC ( [id://635648] : note . print w/replies, xml ) Need Help??

in reply to Using Substitution Operator In Perl Script

ikegami has noted the reason that your script will not run, however I think it's worth mentioning that you may want to consider a more robust way to generate your CSV than simply using tr//. For example, if your input file has double quotes or commas the resulting output will not be valid CSV. There are many modules on CPAN that can help with CSV, Text::CSV_XS is an example:
use Text::CSV_XS; my $csv = Text::CSV_XS->new; while(<DATA>){ chomp; my @columns = split /\t/; $csv->combine( @columns ) or die "could not combine due to ",$csv- +>error_input()," in input\n"; print $csv->string, "\n"; } __DATA__ first second "hello" 100,000 bye He said "bye"
first,second """hello""","100,000" bye,"He said ""bye"""
Whereas using tr/\t/,/ will give you:
first,second "hello",100,000 bye,He said "bye"
which is not valid CSV.