parsing - In perl, how to loop through file, parse line and then compare values in the lines? -


i'm new perl , trying figure out how parse lines within tab-delimited file , compare values parsed lines value , print line.

for example: want print out lines have numbers greater 3.

a 5.4 6.9 3.1

b 10.2 3.4 7.6

c 1.9 2.6 2.3

i output

a 5.4 6.9 3.1

b 10.2 3.4 7.6

thanks in advance

edit: sorry, explanation not clear , test case not good. find lines have numbers greater 3.

for example: if change 5.4 of line 2.4, don't want code print line because contains number less 3.

the program below you. works reading data filehandle data can incorporated program itself. read data elsewhere have open source , read filehandle instead.

each line read $_ system variable , divided fields using split which, default, splits $_ on whitespace. fields put array @data.

the grep function returns number of elements of list pass given test. slice @data[1..$#data] of @data array except first element (as array indices start @ zero).

the call print prints $_ if count of elements greater 3 non-zero.

use strict; use warnings;  while (<data>) {   @data = split;   print if grep $_ > 3, @data[1..$#data]; }  __data__ 5.4 6.9 3.1  b 10.2 3.4 7.6  c 1.9 2.6 2.3 

output

a 5.4 6.9 3.1 b 10.2 3.4 7.6 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -