in reply to Can anyone simplify this code
It can be cleaned up a little using statement modifiers and defaults for split:
use strict; use warnings; my $word="test"; while(<DATA>) { next if ! /\b($word)\b/; my @arr = split; my $col = ""; my $i=0; foreach my $k (@arr) { $i++; $col .= "$i\t" if $k eq $word; } print "The word repeated in Line $. and in column $col\n"; } __DATA__ This is a test from tester okay nothing message test center test test in proress ... test one test two
Prints:
The word repeated in Line 1 and in column 4 The word repeated in Line 3 and in column 2 4 The word repeated in Line 4 and in column 1 5 7
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can anyone simplify this code
by Anonymous Monk on Jan 11, 2007 at 12:28 UTC |