Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: confused

by TStanley (Canon)
on May 15, 2002 at 15:10 UTC ( #166741=note: print w/ replies, xml ) Need Help??

in reply to @ARGV / Command Line Arguments

Personally, I would have written your code as follows: (UNTESTED !!!)
#!/usr/local/bin/perl -w use strict; my $params=@ARGV; my ($input,$output,$length); if($params < 3){ die "Not enough parameters"; }else{ ($input,$output,$length)= @ARGV; } open(INFILE,"$input")||die "Can't open $input: $!\n"; open(OUTFILE,">$output")||die "Can't open $output: $!\n"; my $count=1; while(<INFILE>){ chomp; if(/>/){ ++$count; } if(length($_) >= $length){ print "\>$count\n",$line,"\n\n"; print OUTFILE "\>$count\n",$line,"\n\n"; } } close INFILE; close OUTFILE;

UPDATE:Changed code per Biker's suggestion. And what is really sad, is that I actually had it right the first time, and changed it. :-(

Never underestimate the power of very stupid people in large groups -- Anonymous
Comment on Re: confused
Download Code
Replies are listed 'Best First'.
Re: Re: confused
by Biker (Priest) on May 15, 2002 at 15:20 UTC

    I believe this line:

    ($input,$output,$length)= shift @ARGV;
    should read:
    ($input,$output,$length)= @ARGV;

    Everything went worng, just as foreseen.

Re: Re: confused
by davorg (Chancellor) on May 15, 2002 at 15:26 UTC

    If it was my script, I'd write it like this:

    #! /usr/local/bin/perl -w use strict; die "Not enough params!!!\n" if @ARGV < 3; my ($input, $output, $length) = @ARGV; open INPUT, $input or die "unable to open $input: $!\n"; open OUTFILE, ">$output" or die "unable to open $output: $!\n"; my $count = 1; while (<INPUT>) { chomp; ++$count if />/; if (length >= $length) print ">$count\n$_\n\n"; print OUTFILE ">$count\n$_\n\n"; } } close INPUT; close OUTFILE;

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://166741]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2016-05-02 13:24 GMT
Find Nodes?
    Voting Booth?