Gossamer Forum
Home : General : Perl Programming :

just a thought

Quote Reply
just a thought
just a question:
if I should print file data(into a file) taken from a form and use CGI.pm then I must use the
Code:
$q->textfield(-name=>"name")
.
But if I must have that code inside a
Code:
print FILE "code here";
, it will crash because of the four " and not 2 ". If you know what I mean.
Can I avoid them by using a backslash(\)?
Like this:
Code:
print DATA "$q->textfield(-name=>\"name\")\n";
??

_________________________________________________
Quote Reply
Re: [perlman] just a thought In reply to
Nope. You can't call methods and subroutines inside quoted strings....well you *can* but it requires some jiggery pokery to reference and dereference, for example:

Code:
print DATA "@{[ $q->url() ]}";

Anyway to do what you want you should do:

Code:
print DATA $q->textfield(-name=>"name") . "\n";

I've not used the textfield() method before but I assume you could shorten it to:

Code:
print DATA $q->param("name") . "\n";

Last edited by:

Paul: Feb 21, 2003, 2:47 PM
Quote Reply
Re: [Paul] just a thought In reply to
Quote:
I've not used the textfield() method before but I assume you could shorten it to

No, textfield() prints an HTML form element: <input type="text" name="$name" > sort of thing.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] just a thought In reply to
Ah right.

I've never really understood the need for CGI.pm to handle html. Mmm.
Quote Reply
Re: [Paul] just a thought In reply to
In Reply To:
I've never really understood the need for CGI.pm to handle html.
It also has all sorts of useful features to handle form variables (including limiting the length of data reaching the program), cookies, headers etc.

It is a little slow and bloated if you're just printing plain HTML to a browser though.
Quote Reply
Re: [wysardry] just a thought In reply to
If you run a hello world type script and then add use CGI; to the top you can actually see the extra time it takes to compile CGI.pm Frown
Quote Reply
Re: [Paul] just a thought In reply to
Well, it is about 200Kb or something stupid.

Using CGI.pm to print a basic "hello world" script is overkill in most people's eyes though.

I'm not a fan of CGI.pm either, but if you're going to use a lot of its features in a largish program, there's probably little difference in compile time between using it, your own custom subroutines or writing headers, tables etc. out manually.
Quote Reply
Re: [Paul] just a thought In reply to
I've not known if I could use the param instead of textfield, but I got confused of all the talking here.
Isn't there any differense between them?

_________________________________________________
Quote Reply
Re: [perlman] just a thought In reply to
Ignore that - Alex pointed out that they are different so keep using what you are using.
Quote Reply
Re: [wysardry] just a thought In reply to
Quote:
Using CGI.pm to print a basic "hello world" script is overkill in most people's eyes though.

Yes of course I realise that - I wouldn't use CGI.pm for a hello world script Sly

The point I was making was one of how noticable the compilation time of CGI.pm is :)
Quote Reply
Re: [Paul] just a thought In reply to
got it now. didn't quite understand. Wasn't that much I wrote wrong so it will work now.

one more question:
Code:
if ($picture !~ /\.jpg$/i or $picture !~ /\.gif$/i) {
error("If you want to use a picture it must be a .jpg or .gif picture. We don't support .bmp or other types.\n");
}

Will this line work? I am not sure. Can you help?

Wink Thanks.

__________________________________________________

Last edited by:

perlman: Feb 22, 2003, 2:29 AM