http://www.perlmonks.org?node_id=85452

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have been trying to get links to work in perl generated html pages, but it won't allow double quotes so I can't use links. Any suggestions??

Edit 2001-06-04 by mirod: changed the title

  • Comment on how to put double quotes inside strings? (was: Double Quoutes)

Replies are listed 'Best First'.
Re: Double Quotes
by boo_radley (Parson) on Jun 04, 2001 at 16:46 UTC
    Double quotes can be escaped or quoted inside of double quotes : print " she said \"hello, world!\"";.
    this also works with single quotes : print ' she said \'hello, world!\'';.
    for more info, see perlop manpage.
Re: Double Quoutes
by mirod (Canon) on Jun 04, 2001 at 16:52 UTC

    There are plenty of ways, here are some:

    • using CGI.pm: print a( {href => "$link"}, "foo");
    • using alternate delimiters: print qq{ <a href="$foo">foo</a>};
    • the dirtiest: print '<a href="', $link, '">foo</a>';
Re: Double Quotes
by one4k4 (Hermit) on Jun 04, 2001 at 16:49 UTC
    print "<a href=\"http://www.perlmonks.org\">Perlmonks</a>";
    Should work just fine. You have to add a \ to anything you want to print that would normally be in a perl statement. (For the life of me the word for the concept of \(something) wont come to me. Its on the tip of my tongue... It's Monday, I suppose.)

    _14k4 - webmaster@poorheart.com (www.poorheart.com)

      Or, of course, you can use alternative quoting operators to remove the need to use ugly escaping characters.

      print qq(a href="http://www.perlmonks.org">Perlmonks</a>);
      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

      fyi, It's called "escaping"
Re: how to put double quotes inside strings? (was: Double Quoutes)
by fenonn (Chaplain) on Jun 04, 2001 at 18:14 UTC
    Just place the \ character before any " that is part of your data.