Plotinus has asked for the wisdom of the Perl Monks concerning the following question:
This is more of an rambling inquiry into understanding some code I've come across, hope you don't mind.
I'm trying to move from Sys Admin with some scripting ability to actual coder with sys admin skills (if you're in the UK you'll understand this strange distinction). Anyway I picked an open source project (in perl) to try my hand at, as well as hopefully breaking the M$ monopoly at work. All the modules use a particular way of assigning strings to variables as shown below:
$_[0] =~ s/%HTTP_HOST%/&handleEnvVariable('HTTP_HOST')/ge; $_[0] =~ s/%REMOTE_ADDR%/&handleEnvVariable('REMOTE_ADDR')/ge; $_[0] =~ s/%REMOTE_PORT%/&handleEnvVariable('REMOTE_PORT')/ge; $_[0] =~ s/%REMOTE_USER%/&handleEnvVariable('REMOTE_USER')/ge;
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. Wierd but having read perlsub and the following line: "In particular, if an element $_[0] is updated, the corresponding argument is updated (or an error occurs if it is not updatable)." it seems to me that $_[0] is being used as some kind of dynamic referencing to change each of the s/// substitutions being done on the right hand side one after the other without having to use numerous user defined variable simply once (i.e. it is a shortcut for lazy coders - and I do know that laziness is a virtue). Is this correct?
Also: the =~ operator. How is binding (=~) different from assignment (=, ==, or eq)?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: What are multiple $_[0] =~ operations doing?
by davido (Cardinal) on Apr 01, 2005 at 09:44 UTC | |
by jhourcle (Prior) on Apr 01, 2005 at 13:02 UTC | |
Re: What are multiple $_[0] =~ operations doing?
by ambs (Pilgrim) on Apr 01, 2005 at 09:39 UTC | |
Re: What are multiple $_[0] =~ operations doing?
by Enlil (Parson) on Apr 01, 2005 at 09:49 UTC | |
Re: What are multiple $_[0] =~ operations doing?
by cog (Parson) on Apr 01, 2005 at 09:43 UTC | |
Re: What are multiple $_[0] =~ operations doing?
by polettix (Vicar) on Apr 01, 2005 at 10:14 UTC |