Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: exists *{$glob} ? (+)

by broquaint (Abbot)
on Sep 09, 2004 at 08:20 UTC ( #389586=note: print w/ replies, xml ) Need Help??


in reply to Re: exists *{$glob} ? (+)
in thread exists *{$glob} ? (+)

Further that to that you should also check for glob-ness since non-globs can live in symbol tables e.g

use strict; sub exists_glob { my $tbl = \%main::; $tbl = $tbl->{"$_\::"} for split '::', scalar caller; return exists $tbl->{$_[0]} && 'GLOB' eq ref \$tbl->{$_}; } $main::{foo} = "I'm a string"; *bar = \"I'm in a glob"; printf "%s is%s a glob\n", $_, (exists_glob($_) ? '' : "n't") for qw/ foo bar /; __output__ foo isn't a glob bar is a glob
HTH

_________
broquaint


Comment on Re^2: exists *{$glob} ? (+)
Download Code
Re^3: exists *{$glob} ? (+)
by ysth (Canon) on Sep 09, 2004 at 15:43 UTC
    Replacing the $main::{foo} line with sub foo (I am a string); gives a more realistic example.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (18)
As of 2015-07-01 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (6 votes), past polls