CGI.pm doesn't like this... 
Author Message
 CGI.pm doesn't like this...

Using CGI.pm 2.21 and Perl 5.001m, I get a compile error of

"Can't modify subroutine entry in scalar assignment at xxxx line xx, near
tr/A-Z/a-z/;"

When trying to do this:

$form->param('userid') =~ tr/A-Z/a-z/;

I'm assuming that the construct is invalid, but wondering how to get around the
problem.  Should I just assign the parameter to a new variable and work from
there, or is there a more elegant way of doing it?

Thanks in advance for any advice :)

Cheers,
Kris Lizuck



Sat, 02 Jan 1999 03:00:00 GMT  
 CGI.pm doesn't like this...


Quote:
> Using CGI.pm 2.21 and Perl 5.001m, I get a compile error of

> "Can't modify subroutine entry in scalar assignment at xxxx line xx, near
> tr/A-Z/a-z/;"

> When trying to do this:

> $form->param('userid') =~ tr/A-Z/a-z/;
> Should I just assign the parameter to a new variable and work from
> there,

Yes. You can do this with a temporary variable like this. (I _think_ this
is what you're trying to do.)

   {
     my($uid) = $form->param('userid');
     $uid =~ tr/A-Z/a-z/;
     $form->param('userid', $uid);
   }

Although I'd be tempted to do this.

   $form->param('userid', lc($form->param('userid')));

HTH!

-- Tom Phoenix            http://www.teleport.com/~rootbeer/




Sat, 02 Jan 1999 03:00:00 GMT  
 CGI.pm doesn't like this...

Quote:

> Yes. You can do this with a temporary variable like this. (I _think_ this
> is what you're trying to do.)

>    {
>      my($uid) = $form->param('userid');
>      $uid =~ tr/A-Z/a-z/;
>      $form->param('userid', $uid);
>    }

> Although I'd be tempted to do this.

>    $form->param('userid', lc($form->param('userid')));

Thanks very much, Tom!  That's a great help :)

Following on the heels of that, though - and I've not seen anybody ask
about this before - can I call param() from within a here file in order
to interpolate a variable, as in:

     open (MAIL, "| $mailprog -t -oi") || die "blah";
     print <<EO_MAIL;
     $header            <-- assume it's predefined.  I'm lazy :)

     Good morning, $form->param('morning_person')!!
     EO_MAIL
     close(MAIL);

I tried this once and got what looks like a reference...  

    Good morning, CGI=HASH(0x40090b2c)->param('morning_person')!!

(Okay, so it DOESN'T work....  but is it another case of assigning to a
local var ouside the here file?)

I apologize for the idiocy of this and my previous question, but the
docs for CGI.pm don't cover this, and I'm still a little green as far as
working with Perl5 modules goes.

Thanks a lot for any advice :)

Kris Lizuck



Sun, 03 Jan 1999 03:00:00 GMT  
 CGI.pm doesn't like this...

Quote:

> can I call param() from within a here file in order
> to interpolate a variable, as in:

>      open (MAIL, "| $mailprog -t -oi") || die "blah";
>      print <<EO_MAIL;
>      $header            <-- assume it's predefined.  I'm lazy :)

>      Good morning, $form->param('morning_person')!!
>      EO_MAIL
>      close(MAIL);

> I tried this once and got what looks like a reference...

>     Good morning, CGI=HASH(0x40090b2c)->param('morning_person')!!

As you saw, that doesn't work. It interpolates only $form, since -> is an
operator. But within double-quotish strings (which your here-doc is) you
can use a surprisingly-attractive construct to do what you want. I haven't
tried this, but I think it'll work:


This trick is tucked away in the docs; I found it in perlref(1). Handy,
isn't it?

-- Tom Phoenix            http://www.teleport.com/~rootbeer/




Sun, 03 Jan 1999 03:00:00 GMT  
 CGI.pm doesn't like this...

Quote:

>As you saw, that doesn't work. It interpolates only $form, since -> is an
>operator. But within double-quotish strings (which your here-doc is) you
>can use a surprisingly-attractive construct to do what you want. I haven't
>tried this, but I think it'll work:

>This trick is tucked away in the docs; I found it in perlref(1). Handy,
>isn't it?

Curses!  I read the damn page trying to remember how to do this (I was sure
you could do it!), but I blew right past this bit. [1]

Which just goes to prove, the man pages have everything :-). [2]

[1] Syntactically, I still prefer the idea of using CGI::import_names
    and using the "named" parameters to solve the original
    problem.
[2] unless it's in the FAQ, of course [3]
[3] or in Tom/Randal/Larry's head

************************************************************************
Michael J. Suzio                    | Friends don't let friends use

http://www.umd.umich.edu/~msuzio    |
************************************************************************
 postal://USA/48141/MI/Inkster/355+Cherry+Valley+Dr:Q21/M.+Suzio
************************************************************************



Mon, 04 Jan 1999 03:00:00 GMT  
 CGI.pm doesn't like this...


Quote:
>can I call param() from within a here file in order
>to interpolate a variable, as in:
>     open (MAIL, "| $mailprog -t -oi") || die "blah";
>     print <<EO_MAIL;
>     $header            <-- assume it's predefined.  I'm lazy :)
>     Good morning, $form->param('morning_person')!!
>     EO_MAIL
>     close(MAIL);
>I tried this once and got what looks like a reference...  
>    Good morning, CGI=HASH(0x40090b2c)->param('morning_person')!!
>(Okay, so it DOESN'T work....  but is it another case of assigning to a
>local var ouside the here file?)

It works, just not the way you wrote it. Try this:

    print <<EO_MAIL;
[...]

    EO_MAIL


'{}' denotes a block returning a list reference, and the '[]' creates a
reference to an anonymous list which is the value returned by the method
invocation.

--
 Dave Wolfe    *Not a spokesman for Motorola*
 Motorola MMTG  6501 Wm. Cannon Dr. W. OE112  Austin  TX  78735-8598



Mon, 04 Jan 1999 03:00:00 GMT  
 CGI.pm doesn't like this...

Quote:

>Following on the heels of that, though - and I've not seen anybody ask
>about this before - can I call param() from within a here file in order
>to interpolate a variable, as in:
>     open (MAIL, "| $mailprog -t -oi") || die "blah";
>     print <<EO_MAIL;
>     $header            <-- assume it's predefined.  I'm lazy :)
>     Good morning, $form->param('morning_person')!!
>     EO_MAIL
>     close(MAIL);
>I tried this once and got what looks like a reference...  

Indeed.  This is how any sort of interpolation of this is going
to proceed; the $form variable without any disambiguation is going to
be evaluated by itself, which in my tests ended up giving roughly
the same results as calling $form->dump().  You need to clue Perl in on
how to parse this, the default evaluation order is going to fail to do
what you want, because TERMS are of the highest precedence in Perl (above
the arrow operator), and $form is a legal variable -- it's a reference
to a hash.

I'm sure a guru could tell me how to make this work, but I really
can't see (after much man page reading) how to make a method call
interpolate into a quoted string (which is what the "here document" is).

So, save some mental anguish, and try importing the data into a namespace,
and using that to refer to the variables (this is what I always do).  This
makes them simple scalar or array values:

...
$form->import_names('Q');
print MAIL <<EOM;
From: $Q::name <$Q::email>
To: $Q::to
Reply-To: $Q::email
...
...
EOM

************************************************************************
Michael J. Suzio                    | If life is like a box of chocolates,

http://www.umd.umich.edu/~msuzio    |
************************************************************************
 postal://USA/48141/MI/Inkster/355+Cherry+Valley+Dr:Q21/M.+Suzio
************************************************************************



Mon, 04 Jan 1999 03:00:00 GMT  
 CGI.pm doesn't like this...

Michael> [3] or in Tom/Randal/Larry's head

If it's only in my head, it's pretty lonely. :-)

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $18,720.69 collected, $172,159.85 spent; just 774 more days

--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying

Web: <A HREF="http://www.teleport.com/~merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me



Tue, 05 Jan 1999 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. perl cgi (win95) doesn't work with CGI.pm

2. cgi.pm->checkbox_group doesn't work?!

3. CGI.pm - Doesn't recognize consecutive blank spaces

4. CGI.pm: uploadInfo doesn't work

5. CGI.pm - Doesn't recognize consecutive white spaces

6. ODBC.PM and sql's Like doesn't work

7. Safe.pm doesn't catch match?

8. GD.pm doesn't install

9. SunOS: GD.pm doesn't install

10. Expect.pm doesn't work on FreeBSD ?

11. Mysql.pm doesn't get good $dbh back from DBI _new_handle, apparently

12. Installing 5.00502 - CPAN.pm doesn't work

 

 
Powered by phpBB® Forum Software