On Fri, 18 Feb 2005, Jeremy Mates wrote:

> Warning! The qq[] syntax produces different output than the heredoc:
> 
> my $foo = <<EOD;
> asdf
> EOD
> 
> my $bar = qq[
> asdf
> ];
> 
> print "uh oh" unless $foo eq $bar;

Right. The qq[] syntax above & as I offered earlier, tacks on newlines. 

These are identical:

  $ cat ptest
  #!/usr/bin/perl

  my $foo = <<EOD;
  asdf
  EOD

  my $bar = qq[asdf
  ];

  print "uh oh" unless $foo eq $bar;

  print qq{
    \$foo:
    [$foo]

    \$bar:
    [$bar]
  };
  $ perl ptest

    $foo:
    [asdf
  ]

    $bar:
    [asdf
  ]
  $

That's just wacky that I had to force a newline on the qq form to get a 
match; I don't see this as validating the heredoc approach at all.

I find the qq[] form so much more readable & forgiving than heredocs 
that I generally never even consider using them unless I'm maintaing 
something that uses them heavily or are otherwise forced to use them. 
They have so little to offer though that I avoid them otherwise...

But as I say, YMMV...


-- 
Chris Devers

Reply via email to