in reply to Can anyone simplify this code
while(<DATA>) { while(/\b$word\b/g) { print "The word repeated in Line $. and in column ", scalar(split /\s+/, $`)+1,"\n"; } }
although this throws
Use of implicit split to @_ is deprecated
if running with -w. Dunno why - I'm splitting $PREMATCH, no?
<update>
ambrus and Melly pointed me into the right direction - I overlooked the to. In void or scalar context, split will assign it's result to @_, which usage is deprecated.
scalar(my @s = split /\s+/, $`)+1
fixes that. This version produces the OP's output:
while(<DATA>) { my @arr = (); push @arr, scalar(my @s=split/\s+/,$`)+1 while /\b$word\b/g; print "The word repeated in Line $. and in column ", join("\t",@arr) ,"\n" if @arr; }
</update>
Note also that this has performance hits. See Devel::SawAmpersand. (Anybody knows how to rewrite this using captures and $1 instead of $` ?)
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can anyone simplify this code
by Anonymous Monk on Jan 11, 2007 at 12:32 UTC |