in reply to In place search and replace with a hash

Looks like you are trying to use $1 , $2 from one regex within another one, which of course resets them again to undef.

Copy them to new variables before using them.

edit

Not sure why you even need two nested regexes here... One s/// should be sufficient.

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

  • Comment on Re: In place search and replace with a hash

Replies are listed 'Best First'.
Re^2: In place search and replace with a hash
by hkates (Novice) on Dec 28, 2014 at 02:36 UTC

    Thanks Rolf, I am not sure this is what you meant but I changed it to:

    while (<FH>) { if (/(\S+):(\S+).*\n/) { $var1 = "$1"; $var2 = "$2"; s/$var1/$hash{$var1}_$var/g; } }

    and now I get a different Use of uninitialized value error, which seems better?:

    "Use of uninitialized value within %hash in concatenation (.) or string at test_perl.pl line 41"

    I don't understand your comment about nested regexes, could you elaborate? Thanks in advance for any help