Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Subtle omission in perlop?

by davido (Archbishop)
on Aug 30, 2005 at 17:06 UTC ( #487843=perlquestion: print w/replies, xml ) Need Help??
davido has asked for the wisdom of the Perl Monks concerning the following question:

The other day I quoted a couple of paragraphs out of perlop relating to how the 'stuff' within angle brackets gets parsed. Ever since then this has bugged me, as I believe it's a mistaken omission in perlop. Here are the paragraphs in question. I've underlined the sentence that's bothering me.

If what's within the angle brackets is neither a filehandle nor a simple scalar variable containing a filehandle name, typeglob, or typeglob reference, it is interpreted as a filename pattern to be globbed, and either a list of filenames or the next filename in the list is returned, depending on context. This distinction is determined on syntactic grounds alone. That means <$x> is always a readline() from an indirect handle, but <$hash{key}> is always a glob(). That's because $x is a simple scalar variable, but $hash{key} is not--it's a hash element.

One level of double-quote interpretation is done first, but you can't say <$foo> because that's an indirect filehandle as explained in the previous paragraph. (In older versions of Perl, programmers would insert curly brackets to force interpretation as a filename glob: <${foo}> . These days, it's considered cleaner to call the internal function directly as glob($foo), which is probably the right way to have done it in the first place.)

I think it should say...

...but you can't say <"$foo"> because...

The sentence is discussing what happend when you double-quote the contents of the angle bracket operator, but gives an example that isn't double-quoted. This is a subtle omission, but it damages the clarity of the assertion. Readers have to reflect on the gory details of quoting to realize the implications since the double-quotes are omitted from the example given.

Before I submit a perlbug report and patch I just wanted to confirm with the PerlMonks that I'm on the right channel. Comments welcomed...


Replies are listed 'Best First'.
Re: Subtle omission in perlop?
by chromatic (Archbishop) on Aug 30, 2005 at 17:39 UTC

    I think it's correct, and that it does the interpolation without the quotes being there. That's why it's surprising that <$foo> is a readline() call on the filehandle in $foo.

Re: Subtle omission in perlop?
by chester (Hermit) on Aug 30, 2005 at 17:36 UTC
    It looks OK to me the way it is. The way I interpret the underlined sentence is "Whatever is inside the <> is parsed like it was double-quoted so that you can do globs on the contents of variables among other things, but you can't do a glob using <$foo> because any time you use a simple scalar inside <>, it's interpreted as a filehandle." The point being, to glob $foo you need to use glob($foo) or <${foo}>.

    It says double-quote interpretation "is done first", it doesn't say anything about using literal double-quotes inside angle brackets. But I may be misinterpreting.

Re: Subtle omission in perlop?
by tlm (Prior) on Aug 30, 2005 at 18:06 UTC

    For example:

    DB<1> $dir = '.' DB<2> print "$_\n" while <$dir/*.c> ./bar.c ./baz.c ./foo.c

    the lowliest monk

Re: Subtle omission in perlop?
by chas (Priest) on Aug 30, 2005 at 17:47 UTC
    I thought that meant interpretation of double quotes inside (i.e. in the contents of) the variable (in the case that it is interpreted as a pattern to be globbed.) Perhaps I've just been confused, though...Hopefully, someone will clear this up in their reply.

      No, what that paragraph is meant to mean is that angle-brackets are a double-quote context. I.e., just as variables are interpolated in double quotes, so shall they be interpolated in angle brackets (except for the case of <$foo> which is always interpretted as a readline() on the $foo filehandle)

      In fact, I don't know why the docs don't say these very words.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://487843]
Approved by Old_Gray_Bear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2018-03-24 04:53 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (297 votes). Check out past polls.