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

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.

Replies are listed 'Best First'.
Re: Re: Re: Re: HTML and CGI coding
by LTjake (Prior) on Dec 09, 2002 at 13:09 UTC
    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
Re: Re: Re: Re: HTML and CGI coding
by demerphq (Chancellor) on Dec 09, 2002 at 13:12 UTC
    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....