Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: s/this/$that/ Gives Variable Name, Not Contents of Variable

by Corion (Pope)
on Oct 07, 2013 at 15:27 UTC ( #1057268=note: print w/ replies, xml ) Need Help??


in reply to s/this/$that/ Gives Variable Name, Not Contents of Variable

I can't reproduce that:

my $foo = "stuff"; @data = <DATA>; foreach (@data) { s/XXYY/$foo/; print; } __DATA__ <XXYY> XXYY XXYY test

gives the following output:

>perl -w tmp.pl <stuff> stuff XXYY test

Maybe you are looking at the wrong output file?

In any case, you most likely want a /g at the end of your substitution, so that the second input line becomes stuff stuff on output.


Comment on Re: s/this/$that/ Gives Variable Name, Not Contents of Variable
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (15)
As of 2014-12-22 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (119 votes), past polls