Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: FileHandles in a Hash (<> ambiguity)

by morgon (Deacon)
on May 28, 2014 at 22:10 UTC ( #1087727=note: print w/ replies, xml ) Need Help??


in reply to Re: FileHandles in a Hash (<> ambiguity)
in thread FileHandles in a Hash

For my own understanding I try to reformulate what is happening:

When you do open $teamAccts{$key}.. the expression $teamAccts{$key} refers to a reference to a GLOB.

When you put that into angles it should (from my point of view) be interpreted as a filehandle but for whatever reason it is not - rather it is treated as a glob-pattern that is first stringified (that gives the GLOB(...) value which is then "globbed". Because no file in the current directory matches that pattern, the pattern is returned.

This behaviour of glob is probably to mimik the broken glob-behaviour of shells:

perl -e print glob("hubba"); # prints "hubba" even if you don't have +a file "hubba"
whereas:
perl -e print glob("hubba*"); # prints nothing, provided no file matc +hes
So this is why <$teamAccts{$key}> returns GLOB(...) For my taste this is not simply a wart but a hunchback with a wart on top of perl...

You have tried to combine in a natural way two of perl's features (hashes and the angle-operator) and and were bitten by a total lack of orthogonality. Really nothing to boast about...


Comment on Re^2: FileHandles in a Hash (<> ambiguity)
Select or Download Code
Re^3: FileHandles in a Hash (<> ambiguity)
by LanX (Canon) on May 29, 2014 at 01:58 UTC
    Well Perl started as a script language, that's why it mimics glob.

    I rarely use <> for globbing, and I wouldn't mind if this feature would be disabled. And I agree that this DWIM logic is somehow surprising.

    But everybody is free to overload <> to do so.

    Your second critic about glob() is somehow cryptic for me, if you say touch hubba you don't want to touch "nothing" because hubba doesn't already exist.

    Perl's success in its early years came from its compatibility with established tools.

    Otherwise we wouldn't be here discussing Perl...

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1087727]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-12-21 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (107 votes), past polls