[Israel.pm] CSV
Eitan Schuler
Eitan.schuler at exlibris.co.il
Wed Feb 25 00:30:59 PST 2004
Try something like this:
my $header;
$sw_get_first_part=0;
$sw_new_block=0;
while (<>){
chomp;
$line=$_;
next if $line=~/^\s*$/;
print "# Output Block\n" if $sw_new_block==1;
if ($line =~ /^\# Input Blocks/){
$sw_new_block=1;
next;
}
$sw_new_block=0;
if ($line=~/,id,sex,/ ){
print $line."\n";
next;
}
if($line=~/category,class/){
print $line;
$sw_get_first_part=1;
next;
}
if ($sw_get_first_part==1){
$line_first_part=$line;
$sw_get_first_part=0;
next;
}
$normal_line=$line_first_part.$line."\n";
print $normal_line;
}
It's not perfect code, but more-or-less works.
Use standard input.
Eitan
More information about the Perl
mailing list