Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: What would you do?

by bjelli (Pilgrim)
on Mar 16, 2001 at 18:56 UTC ( [id://64934]=note: print w/replies, xml ) Need Help??


in reply to What would you do?

doubling a number seems simpler than doing the modulo, thus:

# change even-numberd list entries to 'hi' foreach $i (0..@list/2) { $double = $i * 2; $list[$double] = 'hi'; }

of course you could do away with the extra variable "$double". loose the variable, insert another line of comment to explain what happens. same difference.

--
Brigitte    'I never met a chocolate I didnt like'    Jellinek
http://www.horus.com/~bjelli/         http://perlwelt.horus.at

Replies are listed 'Best First'.
Re: Re: What would you do?
by indigo (Scribe) on Mar 18, 2001 at 00:20 UTC
    Just a little tighter, without getting too obfuscated:

    $list[$_ * 2] = 'hi' for 0 .. @list / 2;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://64934]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-23 23:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found