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