Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^6: Private Utilities

by thor (Priest)
on Dec 02, 2005 at 20:22 UTC ( #513709=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Private Utilities
in thread Private Utilities

# Choose the Nth FASTA record # Called as "perl script_name.pl line_number file_name" use warnings; use strict; $/= '>'; my $line_number = shift; while(<>) chomp; if ($.-1 == $line_number ) { print; exit 0; } }
# Choose any Range of FASTA records # Called as perl script_name.pl --start start_line --end end_line file +_name # both --start and --end are optional; # no --start => start reading from end of file, end at --end # no --end => start reading from --start, read to end of file # neither => print every line use warnings; use strict; use Getopt::Long; my ($start, $end) = (undef, undef); GetOptions( "start=i" => \$start, "end=i" => \$end, ); $/='>'; while(<>) { if( (!defined($start) || $start <= $.) && (!defined($end) || $. <= $end) ) { print; }
In reality, the second script subsumes the first as a special case (set start and end to the same value).

As for your "show the number of lines" example, I don't understand it. From the looks of it, it looks like it counts the number of lines in the file that have a whitespace character in it. Is this really what you want?

thor

The only easy day was yesterday


Comment on Re^6: Private Utilities
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2014-08-22 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (154 votes), past polls