Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Good Morning Venerable Monks,

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)?


In reply to What are multiple $_[0] =~ operations doing? by Plotinus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (5)
    As of 2021-01-23 20:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?