in reply to Re: Separating substrings from a main string
in thread Separating substrings from a main string

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?

  • Comment on Re^2: Separating substrings from a main string

Replies are listed 'Best First'.
Re^3: Separating substrings from a main string
by blue_cowdawg (Monsignor) on Jan 24, 2013 at 14:55 UTC

    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