printing quotes with print command 
Author Message
 printing quotes with print command

Hello

I hope you do not mind me asking a question about perl.

I am trying to do this
print NEWFILE "  <body bgcolor="#FFFFFF"
background="../backgrounds/ruff.jpg">";
but I get a malformed header error. I am assuming this is because of the
quotes inside the quotes.  Is there a way to do this and not cause an error.  
I tried using %22 but did not give me the proper background color or the
background so i am assuming this was not correct.  Can you tell me how to do
this or if I can do it at all.




Mon, 05 Jun 2000 03:00:00 GMT  
 printing quotes with print command

Quote:

> Hello

> I hope you do not mind me asking a question about perl.

In this newsgroup, that's the only thing we cannot object to! 8-}

Quote:

> I am trying to do this
> print NEWFILE "  <body bgcolor="#FFFFFF"
> background="../backgrounds/ruff.jpg">";

use single quotes to encase the literal string containing the double
quotes,like so:  print NEWFILE '<body....".....">';

Or, even more work, you could use double quotes as you did but put a
backslash
before each of the nested double quotes.

Quote:
> but I get a malformed header error. I am assuming this is because of
> the
> quotes inside the quotes.  Is there a way to do this and not cause an
> error.
> I tried using %22 but did not give me the proper background color or
> the
> background so i am assuming this was not correct.  Can you tell me how
> to do
> this or if I can do it at all.





Mon, 05 Jun 2000 03:00:00 GMT  
 printing quotes with print command

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Quote:
>I am trying to do this
>print NEWFILE "  <body bgcolor="#FFFFFF"
>background="../backgrounds/ruff.jpg">";
>but I get a malformed header error. I am assuming this is because of the
>quotes inside the quotes.  Is there a way to do this and not cause an error.  
>I tried using %22 but did not give me the proper background color or the
>background so i am assuming this was not correct.  Can you tell me how to do
>this or if I can do it at all.

Escape the quotes with backslashes, like so:

print NEWFILE "<body bgcolor=\"#FFFFFF\" background=\"./background.ruff.jpg\">"

Of course, double quotes are only needed if you're doing variable interpretation
inside the string, so since there aren't any variables in here you could also
just single quote it:

print NEWFILE '<body bgcolor="#FFFFFF" background="./background.ruff.jpg">'

- --
Stephen P. Clouse

Grand Design, Inc. (http://www.granddesign.com) -- Quality Business Web Design
The Warp Core (http://www.warpcore.org) -- The Web's Premier Descent Site
PGP-Encrypted E-Mail Preferred (Key available at www.granddesign.com/~stephenc)
Fight Spam/UCE -- http://www.cauce.org

-----BEGIN PGP SIGNATURE-----
Version: PGP for Business Security 5.5

iQA/AwUBNJoKVWOLD55Fj/ZkEQIO5gCfcTw5gQn1u7Jvrm8P5tK6iNw26jwAoNxS
LK8tws/tuaqmUA9GIeCwbNpI
=i/ht
-----END PGP SIGNATURE-----

This article was posted from <A HREF="http://www.slurp.net/">Slurp Net</A>.



Tue, 06 Jun 2000 03:00:00 GMT  
 printing quotes with print command

Quote:

>I hope you do not mind me asking a question about perl.

not if you don't mind me answering it...

Quote:
>I am trying to do this
>print NEWFILE "  <body bgcolor="#FFFFFF"
>background="../backgrounds/ruff.jpg">";

perhaps one of the most fun things about perl (besides singing it
happy birthday over the phone from a new york street corner) is
generalized quoting, IMO. in this case you can use qq (p. 41
of the blue Camel) [1]

   print NEWFILE
 qq{<body bgcolor="#FFFFFF" background="../backgrounds/ruff.jpg">};

which can be {*filter*}ed to one of my favorite constructions as of late:

   print NEWFILE
   q q<body bgcolor="#FFFFFF" background="../backgrounds/ruff.jpg">q;

you can also use a here document (p. 43 of the blue camel):

   print NEWFILE <<'HERE'
<body bgcolor="#FFFFFF" background="../backgrounds/ruff.jpg">
HERE

good luck!

"Hope that helps!" - anonymous

[1]
Programming Perl
Larry Wall, Tom Christensen & Randal L. Schwartz
ISBN 1-56592-149-6
<URL: http://www.*-*-*.com/ >

--

Meta Meta FAQ <URL: http://www.*-*-*.com/ ;
CGI Meta FAQ <URL: http://www.*-*-*.com/ ;
maybe i shouldn't post when i'm drunk.



Tue, 06 Jun 2000 03:00:00 GMT  
 printing quotes with print command


said:

Glen> Hello I hope you do not mind me asking a question
Glen> about perl.

Hmmmm, well, this _is_ a perl newsgroup :-)

Glen> I am trying to do this print NEWFILE " <body
Glen> bgcolor="#FFFFFF"
Glen> background="../backgrounds/ruff.jpg">"; but I get a
Glen> malformed header error. I am assuming this is because
Glen> of the quotes inside the quotes.  Is there a way to do
Glen> this and not cause an error.  I tried using %22 but
Glen> did not give me the proper background color or the

There's a number of ways of doing this.

You can

a) escape the quotes you want to appear in the output as \"

        print "string \"containing\" literal quotes\n";

b) use <<

        print <<EOT;
        string "containing" literal quotes
        EOT

c) use a different quoting character, e.g.

        print qq(string "containing" literal quotes\n);

and probably some other more obscure ones.

hth,
tony



Tue, 06 Jun 2000 03:00:00 GMT  
 printing quotes with print command


# Hello
#
# I hope you do not mind me asking a question about perl.
#
# I am trying to do this
# print NEWFILE "  <body bgcolor="#FFFFFF"
# background="../backgrounds/ruff.jpg">";
# but I get a malformed header error. I am assuming this is because of the
# quotes inside the quotes.  Is there a way to do this and not cause an error.  
# I tried using %22 but did not give me the proper background color or the
# background so i am assuming this was not correct.  Can you tell me how to do
# this or if I can do it at all.

use either
print NEWFILE
    qq|<body bgcolor="#FFFFFF" background="../backgrounds/ruff.jpg">|;
or
print NEWFILE
    "<body bgcolor=\"#FFFFFF\" background=\"../backgrounds/ruff.jpg\">";
#

#
done.



Tue, 06 Jun 2000 03:00:00 GMT  
 printing quotes with print command


: -----BEGIN PGP SIGNED MESSAGE-----
: Hash: SHA1



: >I am trying to do this
: >print NEWFILE "  <body bgcolor="#FFFFFF"
: >background="../backgrounds/ruff.jpg">";
: >but I get a malformed header error. I am assuming this is because of the
: >quotes inside the quotes.  Is there a way to do this and not cause an error.  
: >I tried using %22 but did not give me the proper background color or the
: >background so i am assuming this was not correct.  Can you tell me how to do
: >this or if I can do it at all.

: Escape the quotes with backslashes, like so:

: print NEWFILE "<body bgcolor=\"#FFFFFF\" background=\"./background.ruff.jpg\">"

: Of course, double quotes are only needed if you're doing variable interpretation
: inside the string, so since there aren't any variables in here you could also
: just single quote it:

: print NEWFILE '<body bgcolor="#FFFFFF" background="./background.ruff.jpg">'

There's two ways. I'll point out two more ways to be able to use
double quotes without escaping them, yet still get variable interpolation.

If the path to the background JPEG is in $bg ($bg = '../backgrounds/ruff.jpg'):

1) alternative double quote delimiters.

   print NEWFILE qq!<body bgcolor="#FFFFFF" background="$bg">!;

I used ! as the delimiter. Since that character is not in my string,
I won't need to escape it. The 'qq' marker informs perl that you
want to use a delimiter different from the usual double quote.

There are other "markers" for using delimiters alternative to normal
single quotes and backwards single quotes.

These are described in the 'perlop' man page.

2) "here-doc"

print NEWFILE <<EOF;
<body bgcolor="#FFFFFF" background="$bg">
EOF

This is described in the 'perldata' man page.

--
    Tad McClellan                          SGML Consulting

    Fort Worth, Texas



Tue, 06 Jun 2000 03:00:00 GMT  
 printing quotes with print command



[snip]

:    print NEWFILE
:  qq{<body bgcolor="#FFFFFF" background="../backgrounds/ruff.jpg">};

: which can be {*filter*}ed to one of my favorite constructions as of late:

:    print NEWFILE
:    q q<body bgcolor="#FFFFFF" background="../backgrounds/ruff.jpg">q;
     ^
     ^

Note that those two constructions are not equivalent, they just
work the same because it is a constant string.

You get no variable interpolation with the second one, for that you'd want:

   qq q<body bgcolor="#FFFFFF" background="../backgrounds/ruff.jpg">q;

--
    Tad McClellan                          SGML Consulting

    Fort Worth, Texas



Wed, 07 Jun 2000 03:00:00 GMT  
 printing quotes with print command

Quote:



>:    print NEWFILE
>:  qq{<body bgcolor="#FFFFFF" background="../backgrounds/ruff.jpg">};

>: which can be {*filter*}ed to one of my favorite constructions as of late:

>:    print NEWFILE
>:    q q<body bgcolor="#FFFFFF" background="../backgrounds/ruff.jpg">q;
>     ^
>Note that those two constructions are not equivalent, they just
>work the same because it is a constant string.

having never claimed that they were equivalent, we could point out all
sorts of other things.  however, i don't like the symmetry of

   qq q...q;

as much as

   q q...q;

the real mistake here is breaking my own style guide in the first
example - i used qq{} when i had no variables to interpolate.  in my
book that's {*filter*}. :)

--

Meta Meta FAQ <URL: http://www.*-*-*.com/ ;
CGI Meta FAQ <URL: http://www.*-*-*.com/ ;



Fri, 09 Jun 2000 03:00:00 GMT  
 printing quotes with print command

Quote:

> I am trying to do this

> print NEWFILE "  <body bgcolor="#FFFFFF" background="../backgrounds/ruff.jpg">";

print NEWFILE "  <body bgcolor='#FFFFFF'
background='../backgrounds/ruff.jpg'>";

IMHO it is simpler than both backslashing the double
quotes and using generalized quotes.

Peter



Sun, 25 Jun 2000 03:00:00 GMT  
 printing quotes with print command

Quote:



> > > print NEWFILE "  <body bgcolor="#FFFFFF"
> > background="../backgrounds/ruff.jpg">";

> >print NEWFILE "  <body bgcolor='#FFFFFF'
> >background='../backgrounds/ruff.jpg'>";

> Not really on-topic here but:

> 1. Using single quotes in tags is not in compliance with
>    the HTML specs and:

Since we're at it, let me quote the HTML 3.2 spec
(http://www.w3.org/TR/REC-html32.html)

  Attribute values can be quoted using double or single
  quote marks (ASCII decimal 34 and 39 respectively).

Quote:
> 2. Simply doesn't work with all browsers (e.g. Netscape 1.2).

People using Netscape 1.2 should do the same as those
using Perl 4. Upgrade.

Peter



Sun, 25 Jun 2000 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. ?? How to print to 2 files with one print command

2. print command and system command

3. print + double quotes around object

4. $x{$y} inside double quotes in print problem

5. quote & print confusion

6. Printing quote punctuation in strings to e-mail

7. Dereference in double quotes for a print

8. CGI module prints stuff I didn't print

9. Print before sleep prints after sleep

10. Print,send the printed, then do the action (CGI)

11. Print outputs despite no value to print out??

12. print in different codepage = overload print?

 

 
Powered by phpBB® Forum Software