Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Separating substrings from a main string

by Athanasius (Abbot)
on Jan 24, 2013 at 14:25 UTC ( #1015175=note: print w/ replies, xml ) Need Help??


in reply to Separating substrings from a main string

Another approach (using a regex, and assuming you want to keep the whitespace):

#! perl use strict; use warnings; my $string = <<END; > abcd1234 abcd abcd >xyz123 xyz END if ($string =~ />(.*?)\n(.*?)>/s) { print "First substring is '$1'\n"; print "Second substring is '$2'\n"; }

Output:

0:23 >perl 497_SoPW.pl First substring is ' abcd1234' Second substring is 'abcd abcd ' 0:23 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


Comment on Re: Separating substrings from a main string
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2015-07-01 21:19 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 (22 votes), past polls