Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Little annoying mistakes ... of others

by Jenda (Abbot)
on Dec 07, 2008 at 11:40 UTC ( #728689=note: print w/replies, xml ) Need Help??


in reply to Re: Little annoying mistakes ... of others
in thread Little annoying mistakes ... of others

This is worse:

for (my $i = 0; $i < $#names; $i++) { print $names[$i]; }

Replies are listed 'Best First'.
Re^3: Little annoying mistakes ... of others
by sasdrtx (Friar) on Dec 08, 2008 at 02:54 UTC

    Worse? That's the One True Way. However, for one-liners, horizontal alignment is preferable, i.e.:

    for (my $i = 0; $ <= @names; $i++) { print $names[$i] }

    Given the C code. Hey, sometimes Perl is useful as a C prototyper.

    sas
Re^3: Little annoying mistakes ... of others
by dragonchild (Archbishop) on Dec 11, 2008 at 20:48 UTC
    The funniest part is that all three for-loops (parent, this, and child) are wrong (which only is a great defense of the whole point). The correct versions are
    for (my $i = 0; $i <= $#names; $i++) { ... } # or for (my $i = 0; $i < @names; $i++) { ... }
    You guys had $i < $#names and $i <= @names. :-)

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://728689]
help
Chatterbox?
[karlgoethebier]: Cojones! We need cojones!
[karlgoethebier]: Ouch! Permissions! We need permissions!
[BarApp]: I can not use modules. I gain temporary access and still can not use modules.
[Cosmic37]: ta erix - this szabo geezer is pretty cool methinks and he writes about undef but I cannot see instructions for redefining the record separator after having undefined it
[Corion]: $/ = "wahtever";
[Corion]: (it's a magic variable)
[karlgoethebier]: BarApp: whoami
[Cosmic37]: ok fankyou - I was wondering about that but thought there might be a redefine command or something; peachy
[Lotus1]: Cosmic37 if you undef $/ in a local context to a block it won't affect the global version after the block finishes

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-06-29 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (672 votes). Check out past polls.