http://www.perlmonks.org?node_id=968970

perllearner007 has asked for the wisdom of the Perl Monks concerning the following question:

I have tab delim file as follows
#file1 #version1.1 #columns with the information as follows state1 class1 report_version_1.1 9428 4567 . . cal +l=1;times=5;toss=head->tail;sno=A1B1;effect=positive state1 class1 report_version_1.1 3862 4877 . . cal +l=1;times=5;toss=head->tail;sno=A1B2;effect=negative state1 class1 report_version_1.1 2376 4567 . . cal +l=1;times=5;toss=head->tail;sno=;effect=positive state2 class1 report_version_1.1 4378 2345 . . cal +l=1;times=5;toss=tail->tail;sno=A1B3;effect=positive,negative, both state2 class1 report_version_1.1 1289 4835 . . cal +l=1;times=5;toss=head->tail;sno=;effect=positive

Note: There are no column headers in the file just the three top comments.
I am trying to parse out the 8 column(starting from call=1) which is basically a string separated by semi colons. I need to remove all the entries that have part1: no sno (value/name) (for eg: for 3 row sno=; i.e there is no record) and also part2: those that have same toss results i.e toss=tail->tail is not needed since both are tail. Since I am learning perl I try and divide such things in parts and hence Here is what I have come up with so far for the part1: sno…
#!usr/bin/perl use warnings; #inputfile my $input_file = "/Users/myfolder/myfile.txt"; die "Cannot open $input_file \n" unless (open(IN, $input_file)); #open file my @LINES =<IN>; #output file #Open output file and write the needed results die "output1.txt" unless(open( OUT,"> output1.txt")); my @infos; while(<IN>){ my @fields = split ';', $_; my $state = $fields[1]; my $class1 = $fields[2]; my $report_version_1.1 = $fields[3]; my $value1 = $fields[4]; my $value2 = $fields[5]; my $dot1 = $fields[6]; my $dot2 = $fields[7]; my $info = $fields[8]; if ( $fields[8] =~ /^[sno]/ =~ /^[sno]/ ) { push @infos, $_; print OUT " $state\ $class\ $report_version_1.1\ $value1\ $value2\ $do +t1 \ $dot2 \ $info\n"; } } exit;
Any other better ways to solve this for both sno and toss parts together?