Thanks Curtis ...

-----Original Message-----
From: Curtis Poe [mailto:[EMAIL PROTECTED]]
Sent: July 05, 2001 15:27
To: CGI
Subject: RE: Opening HTML file from PERL


--- "Moon, John" <[EMAIL PROTECTED]> wrote:
> Don't know if this will help but I am doing something similar 
> 
> ...
> use strict;
> no strict "refs"; 
> 
> ...
> my %DISPLAY = (
> # *form value* => *sub name*   
>            10  => 'Personnel',
>            20  => 'DataCom',
>            80  => 'Unisys',
>            30  => 'IBM',
>            100 => 'Unix',
>            5251=> 'Oracle',
>            90  => 'MS_Unisys',
>            40  => 'MS_IBM',
>            2610=> 'MS_Unix',
>            410 => 'FRC',
>            60  => 'MiscServ',
>             );
> 
> ...
> 
>  my $sub = $DISPLAY{*form value returned*};
>  &{$sub}(); # jump to sub to display requested report 
>  ...

There's no need to turn of strict 'refs'.  Make the %DISPLAY values
references to the subs:

 use strict;

 ...
 my %DISPLAY = (
 # *form value* => *sub name*    
            10  => \&Personnel,
            20  => \&DataCom,
            80  => \&Unisys,
            30  => \&IBM,
            100 => \&Unix,
            5251=> \&Oracle,
            90  => \&MS_Unisys,
            40  => \&MS_IBM,
            2610=> \&MS_Unix,
            410 => \&FRC,
            60  => \&MiscServ,
             );
 
 ...
 
  my $sub = $DISPLAY{*form value returned*};
  &$sub if $sub; # jump to sub to display requested report 

This is much cleaner and you won't have to worry about getting bitten by "no
strict" problems
later in your script.  Further, by making those values references to the
subs, Perl will check
those references *at compile time* and let you know immediately if it can't
find one of the subs.

Oh, and it will run faster too.

Cheers,
Curtis Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Reply via email to