Not everyone uses a glass TTY or emulates it with a fixed-width font.

No, but many of us do. It's the least common denominator. If you want your code to be maintainable regardless of the environment preferred by the maintainer, you really should keep it in mind.

Even most of those who don't constrain themselves to a proper 80 character line use fixed-width fonts. Even most lame editors that come embedded in the plethora of available "integrated development environments" at least default to a fixed width font. How many nodes here are considered because code tags weren't used and the result is almost unreadable even when BR tags are inserted? What font do you use?

I strongly stand by my statement that the assignment operators should be lined up. It doesn't take much more work (even when you have to change a bunch of them) and it is worth it to give your code a polished look.

I think that the code

my $foo = 'bar'; my $bazqux = 42; my $quux = "$bazqux ${foo}s"; my $money = 'gold'; my $total_fortune = $quux . "of $money\n";
is simply more readable as
my $foo = 'bar'; my $bazqux = 42; my $quux = "$bazqux ${foo}s"; my $money = 'gold'; my $total_fortune = $quux . "of $money\n";
and if you actually disagree, well, you are welcome to your opinion on the matter (right up until the day you do any work for me, that is.)

As for the example, I'd rather use a slice rather than mentioning the params array on every line.

In the example, the multiple assignments were separate calls to the param() method of the CGI object called $q, not assignment to several elements at different keys in the same hash. If it was the latter, I probably wouldn't recommend assigning to scalars at all. If it really made sense though, I'd be inclined to agree that a hash slice would be the way to go.... maybe. Even that might be a lot less maintainable if there were many variables. Consider:

my ($foo, $bar,..., $baz,... $qux) = @hash{'abc', 'def',..., 'pqr',... + 'yz'};
versus
my $foo = $hash{abc}; my $bar = $hash{def}; . . . my $baz = $hash{pqr}; . . . my qux = $hash{yz};
The more verbose method neatly puts each variable on the same line as its hash element. If you had to change the assignment to $baz in the former of those two methods, you'd find yourself counting keys in your slice to find the one it matched with. That's a pretty ugly situation.

I don't know if the accessor function has something similar. That is, if passed multiple arguments will it return a list as well?

No. Calling it with multiple arguments, as in

$q->param('foo','bar','baz')
will result in the parameter 'foo' being assigned an array with the values 'bar' and 'baz' in it. It's the same as calling it as
$q->param(-name => 'foo', -values => ['bar', 'baz'])

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Re: Re: CGI and why? by sauoq
in thread CGI and why? by Sifmole

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.