in reply to Perl : Split/Regex
Use split to split your $result on whitespace, and push to the right array depending on whether you're seeing a "Y":
foreach my $result (@result) { my @fields = split /\s+/, $result; if($fields[3] // "" eq "Y") { push @streams, $fields[0]; } else { push @spaces, $fields[0]; } }
A note on the // "" bit: $fields[3] may be undefined if your $result didn't have enough fields, so I'm using the defined-or operator there to avoid spurious warnings ("Use of uninitialized value $fields[3] in string eq at 1099476.pl line 21").
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl : Split/Regex
by johngg (Canon) on Sep 03, 2014 at 23:01 UTC | |
by AppleFritter (Vicar) on Sep 03, 2014 at 23:08 UTC | |
by 2teez (Vicar) on Sep 03, 2014 at 23:19 UTC | |
by AppleFritter (Vicar) on Sep 03, 2014 at 23:29 UTC | |
by 2teez (Vicar) on Sep 03, 2014 at 23:39 UTC | |
by GrandFather (Saint) on Sep 03, 2014 at 23:47 UTC | |
by AnomalousMonk (Archbishop) on Sep 04, 2014 at 00:57 UTC | |
by GrandFather (Saint) on Sep 04, 2014 at 01:48 UTC | |
by AnomalousMonk (Archbishop) on Sep 04, 2014 at 02:22 UTC |