Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: getting a sequence of numbers and leters

by johngg (Canon)
on Mar 23, 2020 at 23:17 UTC ( #11114586=note: print w/replies, xml ) Need Help??

in reply to getting a sequence of numbers and leters

It might be easier to split the line on white space and slice out the relevant items.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' open my $inFH, q{<}, \ <<__EOD__ or die $!; BOGUS PPI3_SYNY3 276 aa linear BCT 13-NOV-2019 __EOD__ chomp( my $line = <$inFH> ); close $inFH or die $!; my( $bogus, $acids ) = ( split m{\s+}, $line )[ 1, 2 ]; say qq{Bogus : $bogus\nNumber of amino acids : $acids} +;' Bogus : PPI3_SYNY3 Number of amino acids : 276

I hope this is helpful.



Replies are listed 'Best First'.
Re^2: getting a sequence of numbers and leters
by Marshall (Canon) on Mar 24, 2020 at 18:21 UTC
    I work with many space separated files and I agree that split is often the easiest way to go. I would recommend using the character form of the "split on whitespace" in this situation because it has the property of ignoring leading whitespace, as I demo at Re: But I want null values in my array. This is just one of many, "yeah but's" and exceptions that I've discovered over time.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2023-01-31 13:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found