Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: unknown code

by ikegami (Pope)
on Feb 14, 2018 at 08:16 UTC ( #1209110=note: print w/replies, xml ) Need Help??

in reply to unknown code

  1. Looks safe because it looks like a comment is being evaluated, but what if $nada contained a newline? If text is being inserted in to code without first being converted into code, you have a code injection bug.

  2. [See (6) first] _ refers to *_, the glob (symbol table entry) that contains $_, @_, etc. Here, it's used as a file handle, presumably populated by an earlier stat or -X operator.

  3. s/// returns true if it matched, so this code repeatedly performs the substitution until it doesn't match. This pattern is usually buggy. Replacing the whole with a single s///eg will solve these bugs.

  4. [See (6) first] Creates a lexical variable named $a and aliases $_ to it until the end of the current lexical scope. Note that creating a lexical named $a will cause problems for sort and similar functions.

  5. $h{$i, $j, ...} is equivalent to $h{join($;, $i, $j, ...)}.

  6. *name is a typeglob, or just glob for short. Globs are used as the entries of the symbol table, so a glob is a struct with a slot for each type of variable (scalar, array, hash, glob, code) and few others (file handle, directory handle, format). I could be missing some. One might say it's a bunch of variables of different types, perhaps even a glob of types... Globs are weird because they are both a type of variable (e.g. *foo) and a type of scalar (e.g. $foo = *foo;).

Update: Added missing answer for (6).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1209110]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2018-06-18 13:55 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.