logo       


Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: fun with hashes!: msg#00012

Subject: Re: fun with hashes!
Uri Guttman wrote:
"AP" == A Pagaltzis <pagaltzis@xxxxxx> writes:

  AP> * Jerrad Pierce <belg4mit@xxxxxxx> [2007-11-23 22:50]:
  >> exists( $dispatch{$sub} ) ? $dispatch{$sub}->() :
  >> warn "Key <$sub> does not exist in the dispatch table";

  AP>     ( $dispatch{$sub} || sub { warn "no such action '$sub'" } )->();

some variations on that:

        my $sub = $dispatch{$key} or die "trying to call missing code" ;
        $sub->() ;

or:

        my %dispatch = (
                foo     => \&foo,
                ...
                default => \&default
        ) ;

        $key = 'default' unless exists( $dispatch{ $key } ;
        $sub = $dispatch{ $key } ;

or:
        my $sub = $dispatch{ $dispatch{ $key } ?
                        $key : $dispatch{ 'default' } } ;

Shouldn't this be?

 my $sub = $dispatch{ $dispatch{ $key }
                    ? $key
                    : 'default'
                    };



or:

        my $sub = $dispatch{ $key } || $dispatch{ 'default' } ;


as you can see there are various ways to handle a missing dispatch
key. this is not a hash issue but a detail about doing dispatch tables
cleanly. sometimes you want to predefine a default code ref in the
dispatch table and other times you want to handle the missing key when
you make the call through the dispatch table.

uri


Or:

 my $sub = ( exists $dispatch{ $key } && ref( $dispatch{ $key } ) eq 'CODE' )
         ? $dispatch{ $key }
         : $dispatch{ 'default' };

Just because you're not paranoid doesn't mean computers don't hate you :)
--
Just my 0.00000002 million dollars worth,
 Shawn

+------------\
| Shangri La  \
| 40,000 km   /
+------------/



Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
db.firebase.por...    text.xml.xalan....    qnx.openqnx.dev...    user-groups.zar...    internationaliz...    kde.devel.konve...    finance.e-gold....    emacs.latex.pre...    gis.therion/200...    web.webmin.gene...    yellowdog.gener...    vserver/2003-08...    redhat.release....    sysutils.tivoli...    xfree86.expert/...    mail.becky.user...    hardware.netapp...    netbsd.ports.xe...    python.distutil...    boot-loaders.gr...    culture.interne...    java.springfram...    activedir/2006-...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe