#! perl -- use strict; use warnings; @ARGV == 3 or die "usage: $0 ID-file CSV-file CSV-output\n"; my $forextract = shift; # IDs to be extracted, 1 per row , further +info tab delimited #header[0] is matched against header of dtp_al +l my $dtp_all = shift; # csv CANCER60xxx.lis.... my $dtp_my = shift; # csv output print "Warning: The file with items to extract has to have a header - +the first column name will be matched.\n"; open my $IDS, '<', $forextract or die "Opening $forextract failed: $!" +; my ( $myID, %ids ); while ( <$IDS> ) { /^\s*([^\t]+?)\s*\t/ or next; if ( $. == 1 ) { $myID = $1; } else { $ids{ $1 } = 1; } } close $IDS; open my $ALL, '<', $dtp_all or die "Opening $dtp_all failed: $!"; open my $MY, '>', $dtp_my or die "Opening $dtp_my failed: $!"; # copy the header my $header = <$ALL>; print $MY $header; my @colnames = split /,/, $header, -1; my $colN; for my $col ( 0 .. $#colnames ) { if ( $colnames[ $col ] eq $myID ) { $colN = $col; last; } } unless ( defined $colN ) { die "Column $myID not found.\n"; } # parse the input line by line, when ids matched write the line into t +he output while ( my $line = <$ALL> ) { my $col = ( split /,/, $line, -1 )[ $colN ]; s/^\s+//, s/\s+$// for $col; if ( exists $ids{ $col } ) { print $MY $line; } } close $MY or die "Not completed $dtp_my\n"; close $ALL;
In reply to Re: Uninitialized value in string eq error but I initialized
by jwkrahn
in thread Uninitialized value in string eq error but I initialized
by karpatov
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |