http://qs321.pair.com?node_id=465851


in reply to Split using multiple conditions

Nother alternative is to remove the brackets first, then split.

my ($nobrackets = $_) =~ s/(\[|\])//g; my @feeder_line = split ' ', $nobrackets;

Replies are listed 'Best First'.
Re^2: Split using multiple conditions
by kaif (Friar) on Jun 13, 2005 at 01:56 UTC

    Unfortunately, this doesn't do quite what the original poster asked for. Consider [id://bart]'s code snippet above and plug it into yours:

    $_ = 'FDR [62.10060.051-F] [62.10051.381] [this includes spaces!] 0 1 +0'; ($nobrackets = $_) =~ s/(\[|\])//g; @feeder_line = split ' ', $nobrackets; $\ = "\n"; print for @feeder_line; __END__ FDR 62.10060.051-F 62.10051.381 this includes spaces! 0 1 0

    N.B.: I have removed the mys because my ($nobrackets = $_) ... results in the error message Can't use global $_ in "my" at - line 1, near "= $_" (the correct syntax is (my $nobrackets = $_) ...