in reply to Re: Perl : Split/Regex
in thread Perl : Split/Regex
Since the OP mentions that the "Y" will be at the end, why not use a [ -1 ] subscript to avoid the "defined" complication? You could also use a single push with the conditional and target arrays in a ternary. Some may find this less readable than the if ... else ... but I prefer it for simple "push to this or that depending" situations.
$ perl -Mstrict -Mwarnings -E ' open my $inFH, q{<}, \ <<EOD or die $!; ws.abc.dsfsfsfwerfrwef std 13232 ws.dfsdferferfregregrgr std 99868 Y ws.abc.asddwefewfewfewf std 45345 fwfrwfrefergegregerefds std 36754 Y ws.abc.fferfergregrfreg std 45435 EOD my @streams; my @spaces; while ( <$inFH> ) { my @flds = split; push @{ $flds[ -1 ] eq q{Y} ? \ @streams : \ @spaces }, $flds[ 0 ]; } say qq{@streams}; say qq{@spaces};' ws.dfsdferferfregregrgr fwfrwfrefergegregerefds ws.abc.dsfsfsfwerfrwef ws.abc.asddwefewfewfewf ws.abc.fferfergregrfreg $
I hope this is of interest.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl : Split/Regex
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 | |
|
Re^3: Perl : Split/Regex
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 |