Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Think about Loose Coupling
 
PerlMonks  

Re: How can I run only a determined part of script not using if/then statements

by hakkr (Chaplain)
on Jan 15, 2002 at 13:11 UTC ( [id://138896]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to How can I run only a determined part of script not using if/then statements

You can use a hash of function refs to simulate a switch statement. You'll need to break your blocks of code into subroutines.
#!/usr/bin/perl use CGI; use strict; use warnings; my $query = new CGI; my $func = $query->param("func"); my $file = $query->param("file"); my @text = $query->param("text"); print $query->header ( ); my %functions=('rm'=>\&rm, 'edit'=>\&edit, 'vi'=>\&vi); #call your block of code $functions{$func}; sub rm { `rm /home/3dwccom/www/$file` || die "couldn't remove file"; print "Success"; } sub vi { open (FILE, ">/home/3dwccom/www/$file") || die "file must have .extension"; print FILE @text; close (FILE); print "File created successfully!"; } sub edit { open (PAGE, ">../$file") || die print "couldn't open file"; print PAGE @text; close (PAGE); print "File successfully edited"; }
  • Comment on Re: How can I run only a determined part of script not using if/then statements
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://138896]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.