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
In reply to Re^2: Perl : Split/Regex
by johngg
in thread Perl : Split/Regex
by sravs448
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |