Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Sending variables to subs

by Anonymous Monk
on Jun 29, 2002 at 03:47 UTC ( [id://178198]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Ok I tried
if(! -d param('home')) { &inerror("we couldnt find param('home') please check path"); }
But how can I make param('home') print as its variable, all it prints is "param('home')", I tried stuff like
&inerror("we couldnt find ", param('home')," please check path");
But of course youll get an error.

Replies are listed 'Best First'.
Re: Sending variables to subs
by rattusillegitimus (Friar) on Jun 29, 2002 at 03:56 UTC

    Try

    &inerror('we couldnt find ' . param('home') . ' please check path');
Re: Sending variables to subs
by cLive ;-) (Prior) on Jun 29, 2002 at 04:55 UTC
    Another useful thing to know is that you can dump the contents of param() into a hash ref using:
    my $param = Vars();
    then
    $param->{'home'}
    would interpolate as you expect

    .02

    cLive ;-)

    --
    seek(JOB,$$LA,0);

Re: Sending variables to subs
by amphiplex (Monk) on Jun 29, 2002 at 10:44 UTC
    Another way to easily access form parameters when using CGI.pm is to use import_names.

    For example:
    .... use CGI; my $q = new CGI; $q->import_names('Q'); .... inerror("we couldn't find $Q::home, please check path");

    From "perldoc CGI":
    IMPORTING ALL PARAMETERS INTO A NAMESPACE: $query->import_names('R'); This creates a series of variables in the 'R' namespace. For example, $R::foo, @R:foo. For keyword lists, a vari­ able @R::keywords will appear. If no namespace is given, this method will assume 'Q'. WARNING: don't import any­ thing into 'main'; this is a major security risk!!!! In older versions, this method was called import(). As of version 2.20, this name has been removed completely to avoid conflict with the built-in Perl module import opera­ tor.

    ----- kurt
Re: Sending variables to subs
by thunders (Priest) on Jun 29, 2002 at 03:58 UTC
    you can use the concat operator,
    &inerror("we couldnt find ".param('home')." please check path");
    with the commas it is seen as three arguements
Re: Sending variables to subs
by krisahoch (Deacon) on Jun 29, 2002 at 06:19 UTC
    AM,

    I am not entirely sure what it is you are doing, but it looks like you are using CGI.

    If so try something like this..
    use strict; use diagnostics; use CGI; #Create an instance of the object my $CGI_object = new CGI; # Set a new varible for easier manipulation. my $HOME = undef; $HOME = $CGI_object->param('home'); # if $HOME is not defined ==[ (!($HOME)) ]== OR ==[ || ]== # if $HOME is not a directory ==[ (!($HOME)) ] ==, then # do the inerror thing. if( (!($HOME)) || (!(-d $HOME)) ) { &inerror("We couldn't find '$HOME' in the path."); }

    If that is not what you are trying to do, then please ignore this post.
    Hope this helps.
    Kristofer

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://178198]
Approved by Mr. Muskrat
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-20 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found