> Must I abandon trying to get double-quote marks
> into my hash element?

No, it would be silly if the language didn't support that.  And I want to
apologize for my long winded answer that is to follow... I guess I just felt
like typing.

...

As for an answer I think some explanation is needed, otherwise it won't help
much the next time you have a problem.

The hash value is just a scalar value, and a scalar can hold ANY type of
data... even binary.

There are several ways to quote a scalar value...

Single-quotes: 'Hello World'

The value in the quotes is NOT interpolated (meaning it won't look for
variables in the value), and the single-quote (') must be escaped with a
backslash if you want to have one in the string (e.g. 'The\'re here').

Double quotes: "Hello World"

The value in the quotes IS interpolated (meaning variables in the value are
converted to their string value), and double-quotes(") must be escaped with
a backslash if you want to have one in the string (e.g. "Robert \"The
Hacker\" Hanson").

The q() operator: q(Hello World)

The value is treated like a single-quoted string, EXCEPT that the delimiter
is not a single-quote('), it is the character following the "q".  The end
delimiter is either the closing brace/bracket/paren OR the same character as
the opening delimiter.  Some examples: q|Hello World|, q{Hello World},
q*Hello World*.

The qq() operator: qq(Hello World)

Same as the q() operator, but acts like the double-quotes because it does
interpolate.

Anyway, there are several solutions to your problem, which can be handled
however you like best (1 uses the escape (\), the others use a different
delimiter)...

%database = (
...
q_1 => "\"Excretion" is getting rid of ______ material.",
q_2 => '"Excretion" is getting rid of ______ material.',
q_3 => q{"Excretion" is getting rid of ______ material.},
q_4 => qq|"Excretion" is getting rid of ______ material.|,
...
);

BTW - I unquoted the hash keys.  They only need to be quoted if there are
spaces or special characters in them.  In this case they will automatically
be treated as single quoted strings without having to actually use quotes
around them.  It's really a matter of preference on if you want to
explicitly quote them, I tend to prefer not to (less quotes = less clutter).

Rob

-----Original Message-----
From: Rick Triplett [mailto:[EMAIL PROTECTED] 
Sent: Sunday, February 08, 2004 5:26 PM
To: [EMAIL PROTECTED]
Subject: quote marks in DBM

The following snippet of code is from "Programming the Perl DBI" and 
shows the storing of a hash element that contains both a comma and a 
sort-of double quote. (In the book, double quotes are shown; in the 
book-file, it looks like back tics and single quotes.)

...
### Insert some data rows
$database{'Callanish I'} =
     "This site, commonly known as the ``Stonehenge of the North'' is in 
the
form of a buckled Celtic cross.";
...

The next snippet is from code I wrote which didn't compile (choked on 
the repeated double quote marks as I attempted to put the word 
"Excretion" in quotes.

%database = (
...
"a4_2" => "releasing energy from food",
"q_3"  => ""Excretion" is getting rid of ______ material.",
"a1_3" => "excess",
...
);

Must I abandon trying to get double-quote marks into my hash element 
for later printing to the screen? I can live with single-quotes if I 
must.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to