Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: strange behavior of indexed list of globs

by davido (Archbishop)
on Aug 03, 2013 at 21:43 UTC ( #1047745=note: print w/replies, xml ) Need Help??

in reply to strange behavior of indexed list of globs

Are you asking about the behavior of <$simple_scalar> versus <$more[$complex]>? That's a readline versus a glob. perlop says:

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. Even <$x > (note the extra space) is treated as glob("$x ") , not readline($x).

The feature is probably going to go down already recorded in history as one of Perl's warts. :) And the confusion that the angle brackets operator leads to is the primary motivation behind Perl Best Practice's advice to "Use glob, not <...>" (Globbing, page 167).


Replies are listed 'Best First'.
Re^2: strange behavior of indexed list of globs
by jabowery (Beadle) on Aug 03, 2013 at 23:32 UTC
    Thanks for the heads up. Perl does what I think it will enough of the time, without reference to documentation, that tolerating its few documented warts is worth it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047745]
[marioroy]: LA my @music_times = qx(find \$HOME/Music/ Albums -type f -iname \'*.mp3\' -exec mp3info -p \"%S\\n\" {} \\;);
[marioroy]: Only 2 backslash \\n
[marioroy]: LA no space before Albums
[Lady_Aleena]: Good guh! I think I will use File::Find when working in perl. That is too many toothpicks.
[marioroy]: mp3info must be in the PATH
[marioroy]: LA ++
[Lady_Aleena]: marioroy, this is forcing me to learn perl modules to use instead.
[marioroy]: qx isn't fun if having to backslash ' and " and \.
[marioroy]: LA ++ ok.

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2017-04-23 21:26 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.