Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Replacing string with regexp without using modules

by almut (Canon)
on Aug 06, 2008 at 01:58 UTC ( #702537=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Replacing string with regexp without using modules
in thread Replacing string with regexp without using modules

Could it be the hash reference ...?

Yes, in pc88mxer's code, $hash is a hash reference, so it must be dereferenced. In your case, it's a normal hash.  So either don't dereference

$hash{a} = "go"; $string =~ s{\$(\w+)}{$hash{$1}}ge;

or create a reference

$hash->{a} = "go"; $string =~ s{\$(\w+)}{$$hash{$1}}ge;

or even use the normal arrow syntax in both the assignment $hash->{a} = ..., and when you access it $hash->{$1}:

$hash->{a} = "go"; $string =~ s{\$(\w+)}{$hash->{$1}}ge;


Comment on Re^3: Replacing string with regexp without using modules
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://702537]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2014-07-30 03:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls