Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: getting a sequence of numbers and leters

by johngg (Canon)
on Mar 23, 2020 at 23:17 UTC ( [id://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.

Cheers,

JohnGG

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found