regex - How to extract third column from multiple lines using perl split? -


to extract third column sentence of multiple lines in file tried using map , split. fine result , tried extract using split:

#!usr/local/bin/perl  @arr=<data>;   foreach $m (@arr) { @res=split(/\s+/,$m[3]); print "@res\n"; } 

__data__ time 9.00am time 10.00am time 11.00am time 12.00am time 13.00pm 

in example taking whole data in array , trying split $m[3] i.e referring $m array, $mis scalar. when use use strict , use warnings, error:

global symbol "@m" requires explicit package name @ data.pl 

that's why not getting output. should try this:

#!usr/local/bin/perl  use strict; use warnings;   @arr=<data>; foreach $m (@arr) { @res=split(/\s+/,$m); # $m contain each line of file split 1 or more spaces print "$res[3]\n"; # print fourth field } 

a shorter version be:

print ((split)[3]."\n") while(<data>); 

output:

9.00am 10.00am 11.00am 12.00am 13.00pm 

Comments