modification of script in perl -


currently have following script

#!/usr/bin/env perl use strict; use warnings;  %seen;  $header = <> . <>; print $header;  $last_sequence_number = 0;  open( $output, ">", "output.$last_sequence_number.out" ) or die $!; print {$output} $header; $seen{$last_sequence_number}++;  while (<>) {     ($key) = split;     next unless $key =~ m/^\d+$/;     $sequence_number = int( $key / 1000 );     if ( not $sequence_number == $last_sequence_number ) {         print "opening new file $sequence_number\n";         close($output);         open( $output, ">", "output.$sequence_number.out" ) or die $!;         print {$output} $header unless $seen{$sequence_number}++;         $last_sequence_number = $sequence_number;     }     print {$output} $_; } 

the script splits file other files pattern file 1 file 2 ... need pass script parameter allows specify prefix output if additional input 1 output be

1_file1,1_file2....and on.. how that?

i know

use getopt::long; 

could used?

tried this

#!/usr/bin/env perl use strict; use warnings;  %seen;  $header = <> . <>; print $header; ( $suffix, $filename ) = @argv; open ( $input, "<", $filename ) or die $!;                                    $last_sequence_number = 0;  open( $output, ">", "output.$last_sequence_number.out" ) or die $!; print {$output} $header; $seen{$last_sequence_number}++;  while (<$input>) {     ($key) = split;     next unless $key =~ m/^\d+$/;     $sequence_number = int( $key / 1000 );     if ( not $sequence_number == $last_sequence_number ) {         print "opening new file $sequence_number\n";         close($output);         open( $output, ">", "output.$sequence_number.out" ) or die $!;         print {$output} $header unless $seen{$sequence_number}++;         $last_sequence_number = $sequence_number;     }     print {$output} $_; } 

but not working. wrong?

i

 no such file or directory @ ./spl.pl line 10, <> line 2. 

after header printed.

as sobrique says, problem magical nature of <>. don't think it's hard deal thinks.

the point <> looks @ current value of @argv. can add other command line arguments long ensure have removed them @argv before use <> first time.

so change code starts this:

my %seen;  $prefix = shift;  $header = <> . <>; 

you can call program this:

$ your_program.pl prefix_goes_here list of file names... 

everything else should work same does, have prefix stored away in $prefix can use in print statements.

i hope that's wanted. question isn't particularly clear.


Comments