Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
use strict; my $data_file = $ARGV[0]; #input file my $old_delim = $ARGV[1]; # old delimeter my $output_file = $ARGV[2]; # out put file my $new_delim = $ARGV[3]; # new delimeter my $count =0; print "\n$0 Started.....\n\n"; print " Input file name: $data_file\n"; print " File delimiter $old_delim\n"; print " Output file name: $output_file\n"; print " File delimiter $new_delim\n"; open(INFILE, "$data_file") || die "INPUT ERROR: $!\n"; #open file or k +ill the script and return the error die "INPUT ERROR: input file is empty\n" if( -s $data_file < 1); # if +the file is empty, kill the script and print out an error message open(OUTFILE, ">$output_file") || die "OUTPUT ERROR: $!\n"; while(<INFILE>){ $_ =~ s/,\s*(\".*?), (.*?)\"/$1-=O=-$2/g; $_ =~ tr/\\\"//d; my @words = split($old_delim,$_); my $newline = join($new_delim,@words); $newline =~ s/-=O=-/,/g; print OUTFILE $newline; $count++; } print "line count: $count\n"; print ("\n\nCompleted.\n\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regexp problems
by diotalevi (Canon) on Nov 27, 2002 at 04:11 UTC | |
by Anonymous Monk on Nov 27, 2002 at 08:22 UTC | |
by diotalevi (Canon) on Nov 27, 2002 at 08:27 UTC | |
|
Re: regexp problems
by pg (Canon) on Nov 27, 2002 at 04:24 UTC |