Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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. :-(

TStanley
--------
Never underestimate the power of very stupid people in large groups -- Anonymous


Comment on Re: confused
Download Code
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;
    --
    <http://www.dave.org.uk>

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (16)
As of 2015-07-02 22:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (45 votes), past polls