Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: how to pass operators as arguments to a sub

by borisz (Canon)
on May 03, 2006 at 09:45 UTC ( [id://547096]=note: print w/replies, xml ) Need Help??


in reply to how to pass operators as arguments to a sub

Here is a template without eval.
use warnings; use strict; my %h = ( -r => sub { -r shift }, -w => sub { -w shift }, ); my $testDir = '/tmp/'; checkDir( $testDir, '-w' ); checkDir( $testDir, '-r' ); sub checkDir { my ( $dir, $perm ) = @_; die '???' unless exists $h{$perm}; if ( $h{$perm}($dir) ) { print "Can $perm $dir\n"; } else { print "Can not $perm $dir\n"; } }
Boris

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-24 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found