Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: What are multiple $_[0] =~ operations doing?

by Enlil (Parson)
on Apr 01, 2005 at 09:49 UTC ( #444132=note: print w/ replies, xml ) Need Help??


in reply to What are multiple $_[0] =~ operations doing?

As a neophyte it initially looks like the same reference is being sequentially updated with new substitutions and it'll simply end up with the last value.

well sort of. What happens is that all the occurances of the string %HTTP_HOST% will be replaced with whatever is returned from &handleEnvVariable('HTTP_HOST') in $_[0], and THEN all the occurances of the string '%REMOTE_ADDR%' will be replaced with whatever is returned by &handleEnvVariable('REMOTE_ADDR')... and so on. . .

So in each line the string is modified by substitutions if the pattern exists in the line.

It could be shortened down to:

$_[0] =~ s/% (HTTP_HOST| (?:REMOTE_ (?:ADDR|PORT|USER)) %/&handleEnvVariable($1)/gex;
You might want to take a look at perlop(Regexp Quote-Like Operators) and perlre for more info.

-enlil


Comment on Re: What are multiple $_[0] =~ operations doing?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-12-20 15:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (96 votes), past polls