David Gilden writes ..

>Original from the class:
>
>print "<input type=\"checkbox\" name=\"delete\" value=\"yes\" checked>\n";
>
>
>Is this bad style?

yep .. avoid backwhacks at all costs - that's my opinion


>print '<input type="checkbox" name="delete" value="yes" checked>',"\n";
>
>better?

yep .. much better

>print '<input type="checkbox" name="delete" value="yes" checked>'. "\n";

also good - but generally accepted as inferior to the second snippet

>I do believe that these 3 statements are all equivalent. 

nope .. but the differences are subtle .. the first one is essentially
equivalent to the last one .. but the one with the comma is different in
that it passes two parameters as a list to the print function and can be
affected by the built-in variable $,

to see the difference try this code snippet

  $, = '_wow_';

  print 'foo', 'bar', "\n";

  print 'foo'. 'bar'. "\n";

but - use of $, is pretty rare and usually discouraged and the second
snippet that you showed is the best of the three

even better is to realise that double-quotes are operators .. specifically
they're shorthand for the qq// operator .. in other words the following two
are EXACTLY equivalent to Perl

  print "foobar\n";
  print qq/foobar\n/;

so .. when you want to include double-quotes AND have the string
interpolated you can do this

  print qq/<input type="checkbox" name="delete" value="yes" checked>\n/;

also note that the '/' character is not the only delimiter that you can use
.. you can use anything .. so the following are all equivalent to the above

  print qq#<input type="checkbox" name="delete" value="yes" checked>\n#;
  print qq*<input type="checkbox" name="delete" value="yes" checked>\n*;
  print qq|<input type="checkbox" name="delete" value="yes" checked>\n|;

even the rather obfuscated

  print qq q<input type="checkbox" name="delete" value="yes" checked>\nq;

you can even use bracketing constructs and Perl will pair them up .. so the
following works a treat

  print qq(some more parens () in here - perl isn't fooled\n);


Manual Refereces:

  "Quote and Quote-like Operators" section of perlop manual

-- 
  jason king

  No children may attend school with their breath smelling of "wild
  onions" in West Virginia. - http://dumblaws.com/

Reply via email to