Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Separating substrings from a main string

by blue_cowdawg (Monsignor)
on Jan 24, 2013 at 14:19 UTC ( #1015173=note: print w/ replies, xml ) Need Help??


in reply to Separating substrings from a main string

my $string=qq(> abcd1234 abcd abcd >xyz123 xyz); $string =~s/[\s\n]+//g; #squash out the whitespace and newlines my @f=split(/[\>]/,$string; # CAVEAT: just wrote the off the top of my head...
Give that a whirl.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg


Comment on Re: Separating substrings from a main string
Download Code
Re^2: Separating substrings from a main string
by newbie1991 (Acolyte) on Jan 24, 2013 at 14:29 UTC

    this works, but only for the first instance. As in, @f is >abcd1234, but the correct output should be >abcd1234 >xyz123 Would it be more convenient if $string was an array?

      I gave you a template. If you have other requirements please engage your creativity and modify the template to suit you. Here's one way:

      $ cat splitter.pl use strict; use Data::Dumper; my $foo=qq(> abcd1234 abcd abcd >xyz123 xyz); $foo =~ s/\n//g; my @f = split(/[\>]/,$foo); $_ = '>' . $_ foreach @f; print Dumper(\@f); $ perl splitter.pl $VAR1 = [ '>', '> abcd1234abcd abcd ', '>xyz123 xyz' ];


      Peter L. Berghold -- Unix Professional
      Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-12-18 04:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls