in reply to CGI script to read CSV file and modify for web output
use Fcntl qw(LOCK_EX LOCK_UN); my $header = 'foo'; my $footer = 'bar'; my $prefix = 'baz'; open CSV,$csvfile; open OUTPUT,">$header"; flock OUTPUT,LOCK_EX; $, = ","; # output field seperator, joins lists passed to print while (<CSV>){ print OUTPUT $prefix,$_; # no need to split; # just so you know : @list = split(/,/,$_); # will do the trick better than $var1,$var2... # but you want to chomp($_) first, and set $\ to "\n" perh +aps # then you print OUTPUT $prefix,@list # and CSV is done for you. } print OUTPUT $footer; flock OUPTUT,LOCK_UN; # not really needed, i think close OUTPUT; close CSV;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Urgent help required
by ronan76 (Initiate) on Oct 18, 2002 at 11:19 UTC |