in reply to Perms Perms Perms
As others have said, those READ and WRITE constants are actually Perl subroutines. You can't use "READ" the string as if it were READ the subroutine.
However, you can find the subroutine using the string name and then call it. There are two ways to do this. The first is to use string references and the second is to use the package "stash". Here's a short demo:
use strict; sub READ () { 34 } { no strict 'refs'; print &{'READ'}(), "\n"; } { print &{$main::{'READ'}}(), "\n"; }
You "use strict" so you'll probably want to use the second method. Here's the change you need to make to your program:
&{$main::{$folder_ace}}() | &{$main::{$subfolder_ace}}()
Be sure to include those empty parens -- when calling subs using the '&', the prototype is ignored and the current '@_' will always be passed to the sub unless an explicit argument list is given. The empty parens means the sub gets an empty argument list.
WARNING! This technique is not safe to use unless you trust the input -- it can allow people to call any subroutine in your package. I think it's ok to use in the example without any checking, but if you are very concerned about security, check the strings before looking up the subroutine.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Perms Perms Perms
by blackadder (Hermit) on Sep 16, 2002 at 15:13 UTC |