in reply to Re: HTML and CGI coding
in thread HTML and CGI coding

Sorry, but this is wrong. A leading minus in hash keys is so common that it has been special cased to not be interpreted as a mathematical operation when so used (Im not sure of the exact details of when it is legal). However the same is not true for +, nor is it true for an inline - of which I notice the OP has at least three.
# inline hyphens will cause problems D:\Temp>perl -MData::Dumper -e "use strict; print Dumper({-leading_min +us=>1,+plus=>1,in-line-minus=>1})" Bareword "in" not allowed while "strict subs" in use at -e line 1. Bareword "line" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. # what happened to the plus? D:\Temp>perl -MData::Dumper -e "use strict; print Dumper({-leading_min +us=>1,+plus=>1,'in-line-minus'=>1})" $VAR1 = { 'in-line-minus' => 1, '-leading_minus' => 1, 'plus' => 1 }; # this works fine D:\Temp>perl -MData::Dumper -e "use strict; print Dumper({-leading_min +us=>1,'+plus'=>1,'in-line-minus'=>1})" $VAR1 = { 'in-line-minus' => 1, '-leading_minus' => 1, '+plus' => 1 };
Cheers,

UPDATE:If in doubt use either Text::Quote->quote_key() or qw:

{qw( -align CENTER -valign TOP -BGCOLOR blue -font-color yellow -FONT-FAMILY verdana,arial,helvetica -FONT-SIZE 12 )}

--- demerphq
my friends call me, usually because I'm late....

Replies are listed 'Best First'.
Re: Re: Re: HTML and CGI coding
by davis (Vicar) on Dec 09, 2002 at 12:56 UTC

    This was my first assumption, however, command-line testing contradicted this: (Warning, I'm on unix, looks like you're on Win32 - adjust quotes accordingly)

    sh$ perl -MCGI -e '$q = new CGI ; print $q->Tr({-font-family => "not-v +alid"})'
    Gives:
    <tr 0="not-valid" />
    Which appears to contradict my assumption, excusing brainfarts.

    davis
    Is this going out live?
    No, Homer, very few cartoons are broadcast live - it's a terrible strain on the animator's wrist

    Update: Thanks for the explanation, LTjake
    Update 2: Thanks also to demerphq.
      CGI.pm want the args to have a leading dash, then convert all dashes in the name to underscores. So, to fix your example (pardon my win32 :):
      perl -MCGI -e "$q = new CGI ; print $q->Tr({-font_family => 'not-valid +'})"
      Gives
      <tr font-family="not-valid" />
      and to fix up the inital params:
      use CGI; $q = new CGI; print $q->Tr({ -align => "CENTER", -valign => "TOP", -bgcolor => "blue", -font_color => "yellow", -font_family => "verdana, arial, helvetica", -font_size => "12" });
      gives
      <tr valign="TOP" font-family="verdana, arial, helvetica" font-color="y +ellow" align="CENTER" font-size="12" bgcolor="blue" />


      --
      "I don't intend for this to take on a political tone. I'm just here for the drugs." --Nancy Reagan
      The problem in your example is not the leading '-' but the inline hyphen. Since -font-family has the latter its gunna fail. And if you had used strict should have failed with an error. I say should because when I tested it it didnt (I am preparing a bug report right now), however with warnings enabled you do get a good idea of what is going on. Also B::Deparse gets this stuff wrong FWICT. (another bug report on the way)
      D:\perl\psmail-1.0>perl -MData::Dumper -w -e "use strict; print Dumper +({-font-family => 'not-valid'})" Argument "family" isn't numeric in subtraction (-) at -e line 1. Argument "-font" isn't numeric in subtraction (-) at -e line 1. $VAR1 = { '0' => 'not-valid' }; D:\perl\psmail-1.0>perl -MData::Dumper -w -e "use strict; print Dumper +({-fontfamily => 'not-valid'})" $VAR1 = { '-fontfamily' => 'not-valid' }; # Deparse gets this one _wrong_ D:\perl\psmail-1.0>perl -MO=Deparse -MCGI -e "use strict; my $q = new +CGI ; print $q->Tr({-fontfamily => 'not-valid'})" my $q = 'CGI'->new; print $q->Tr({-'fontfamily', 'not-valid'}); -e syntax OK # Hard to say for sure, but apparently Deparse gets this right. But wh +y doesnt it die? D:\perl\psmail-1.0>perl -MO=Deparse -MCGI -e "use strict; my $q = new +CGI ; print $q->Tr({-font-family => 'not-valid'})" my $q = 'CGI'->new; print $q->Tr({-'font' - 'family', 'not-valid'}); -e syntax OK

      --- demerphq
      my friends call me, usually because I'm late....