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

Re^4: How to get at perl's options in a program

by tobyink (Abbot)
on Nov 06, 2012 at 22:09 UTC ( #1002585=note: print w/ replies, xml ) Need Help??


in reply to Re^3: How to get at perl's options in a program
in thread How to get at perl's options in a program

That's actually a pretty flaky technique.

use strict; use warnings; use Data::Dumper; package Foo; 1; package main; print "Data::Dumper was ", defined $Data::{'Dumper::'} ? "loaded\n" : +"not loaded\n"; print "Foo was ", defined $::{'Foo::'} ? "loaded\n" : "not loaded\n"; print "Eata::Dumper was ", defined $Eata::{'Dumper::'} ? "loaded\n" : +"not loaded\n"; # Here's a false positive! # "Data::Dumper" was loaded, and that makes it look like # "Data" has also been loaded... # print "Data was ", defined $::{'Data::'} ? "loaded\n" : "not loaded\n" +; # Here's another false positive! # When we checked if "Eata::Dumper" was loaded, # autovivification makes it look like "Eata" was loaded. # print "Eata was ", defined $::{'Eata::'} ? "loaded\n" : "not loaded\n" +;

It's much better to check for the existence of the actual functions/methods you wish to use:

my $Dumper = UNIVERSAL::can('Data::Dumper', 'can') && 'Data::Dumper'->can('Dumper'); print $Dumper->($hashref) if defined $Dumper;
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re^4: How to get at perl's options in a program
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2015-07-07 19:58 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 (93 votes), past polls