in reply to help with a regex
You are printing the return value of s///, which is the number of substitutions made. If there was only 1 substitution, it prints 1, which just happens to match the hash value. You should print $_ instead:
use warnings; use strict; my %words = (word => 1, word2 => 1, word3 =>1); my $temp = 'WORD2'; my $temp1 = 'word2'; $_ = 'here is word2'; s/$temp1/$words{$temp1} ? "$temp " : "[$temp] "/ex; print "$_\n"; __END__ here is WORD2
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: help with a regex
by Athanasius (Archbishop) on Feb 02, 2013 at 03:27 UTC | |
by AnomalousMonk (Archbishop) on Feb 02, 2013 at 12:29 UTC |
In Section
Seekers of Perl Wisdom