[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] More help



At 12:23 PM 11/30/00, Thomas Wegner wrote:
>Hi Amitava,
>
>1. ...

[snip]

>
>And here is the corrected script, which should compile without syntax errors:
>___________

Good suggestions, but even catching a few typos*, it still won't work :-).

* typo:
<input type=text size=32 maxlength=20
name="First Name" value=Registration data{"FirstName"}>
........................^...........^

I suggest some study of Perl quoting. For one thing, the last 
"here-doc" has the wrong type of quoting:

  print <<'TEST';
<hr noshade>
<center>
<Form Method=POST Action="/cgibook/regs.cgi">
<input type=hidden name=SavedName 
value="registration_data{'FirstName'}$registration_data {'LastName'}">

[snip]

If you want the script to interpolate the variables ( such as 
$registration_data {'LastName'} ), then you want to use a quoting 
method that is interpolative. Saying

   print <<'TEST';
...
TEST

is the equivalent of single-quote string quoting. If you use the statements:

  my $secret = 'my elbows are rough';
  print 'The secret is $secret.';  # Note single quotes

what prints is:

The secret is $secret.

If you say

  print "The secret is $secret.";  # Note double quotes

what prints is:

The secret is my elbows are rough.

The variable $secret has been interpolated into its value.

The whole point of being able to use different types of quotes is to 
get different results, and this applies to here-docs, which are just 
another way of quoting.

Using

<<TEST;   # No quotes around the terminating string
  ...
TEST

is interpolative, as is

<<"TEST"  # Double quotes around the terminating string
...
TEST

I use double quotes around the here-doc terminating string when I 
need indenting within my code or want to use a terminating string 
that has spaces. Otherwise, no quotes (and no space between the << 
and the string) gives me interpolation, which is usually what I want 
because I'm using the here-doc as a handy way to return long strings 
of text with some interpolated variables thrown in.

Not-so-incidentally, one of the beauties of interpolative here-doc 
quoting is that you may use quotes _within_ the quoted material, and 
they stay as they are. This allows what Amitava's script is doing to 
work properly, i.e., to return HTML text with quoted attributes 
within it, without having to 'escape' the quotes!

<input type=text size=32 maxlength=20
name="First Name" value="Registration_data{'First Name'}">

A simple example:
#!perl -w

my $secret = 'my elbows are rough';

print <<HERE;
Now and then I find that $secret.
I wonder, "What can I do about this?"
HERE

__END__

returns:

Now and then I find that my elbows are rough.
I wonder, "What can I do about this?"

Anyway, review Perl quoting; there are some other quoting 
inconsistencies and potential error in this script. Also, I know it's 
tempting to jump right into a script that does everything you want 
from the start, please pardon my broken-record teacherly advice is: 
start with a very simple script and build from there.

Hang in there Amitava!

1;

- Bruce

__Bruce_Van_Allen___Santa_Cruz_CA__

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org