Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Prevent Strings From Being Interpreted As A File Handle

by Anonymous Monk
on Apr 27, 2014 at 11:13 UTC ( [id://1083989]=note: print w/replies, xml ) Need Help??


in reply to Re: Prevent Strings From Being Interpreted As A File Handle
in thread Prevent Strings From Being Interpreted As A File Handle

disambiguation with local
$ perl -fle " sub Snacks::Ahoy { q{Nom} } open Snacks , q{<}, \q{Rice} +; local *Snacks; print Snacks::->Ahoy " Nom

Replies are listed 'Best First'.
Re^3: Prevent Strings From Being Interpreted As A File Handle
by amon (Scribe) on Apr 27, 2014 at 14:33 UTC

    This is clever. I like it.

    So we'd end up with something inconvenient like

    sub invoke_static { my ($class, $method, @args) = @_; no strict 'refs'; # I'd like to only localize *{$class}{IO}, # but we can't have everything, right? local *{$class}; $class->$method(@args); }

    or something insane like

    sub safe_from_evil_filehandles(&) { my ($cb) = @_; my @evil_globs; ... # walk through %:: and list all globs # where *{$entry}{IO} is defined # unless they're OK like "STDOUT" my $localizer; $localizer = sub { return $cb->() unless @evil_globs; local *{shift @evil_globs}; return $localizer->(); }; return $localizer->(); }
Re^3: Prevent Strings From Being Interpreted As A File Handle
by tobyink (Canon) on Apr 27, 2014 at 14:05 UTC

    This works. Good job.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found