Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Why is this split not doing anythine?

by Marshall (Canon)
on Feb 22, 2023 at 19:03 UTC ( [id://11150535]=note: print w/replies, xml ) Need Help??


in reply to Why is this split not doing anythine?

As Rolf said, you want to print the entire array, not just the blank line at the beginning. Better yet, remove blank lines and also perhaps the extra blank after the keyword?

use strict; use warnings; my $string="TOPO_DOM 1; /note=Cytoplasmic; /evidence=ECO:0000269|PubMe +d:24744376; TOPO_DOM 25..74; /note=Extracellular; /evidence=ECO:00002 +69|PubMed:24744376; TOPO_DOM 100..115; /note=Cytoplasmic; /evidence=E +CO:0000269|PubMed:24744376; TOPO_DOM 141..159; /note=Extracellular; / +evidence=ECO:0000269|PubMed:24744376; TOPO_DOM 183..227; /note=Cytopl +asmic; /evidence=ECO:0000269|PubMed:24744376"; my @split_topodom = split(/TOPO_DOM\s*/, $string); @split_topodom = grep {/\S/}@split_topodom; # remove blank lines print join "\n",@split_topodom; __END__ 1; /note=Cytoplasmic; /evidence=ECO:0000269|PubMed:24744376; 25..74; /note=Extracellular; /evidence=ECO:0000269|PubMed:24744376; 100..115; /note=Cytoplasmic; /evidence=ECO:0000269|PubMed:24744376; 141..159; /note=Extracellular; /evidence=ECO:0000269|PubMed:24744376; 183..227; /note=Cytoplasmic; /evidence=ECO:0000269|PubMed:24744376
Update: Of course you can combine the grep that removes blank lines into the split line.
my @split_topodom = grep{/\S/}split(/TOPO_DOM\s*/, $string);

Replies are listed 'Best First'.
Re^2: Why is this split not doing anythine?
by Anonymous Monk on Feb 22, 2023 at 21:52 UTC
    Oh wow, I did not notice THAT!! I feel so stupid now :P Thank you both!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-24 12:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found