Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: opening a file destroys nulling entries in a list?!?!

by l2kashe (Deacon)
on Aug 07, 2003 at 03:39 UTC ( #281730=note: print w/ replies, xml ) Need Help??


in reply to opening a file destroys nulling entries in a list?!?!

and now for something entirely different..

just as an aside, using map in a void context (i.e. not returning anything), is generally considered a BadThing(TM). If you are simply looking for a way to do simple single line loops, you can always use for().. ala

print "before: $_\n" for @instances; screwed "$_" for @instances; print "after: $_\n" for @instances;

You might already know this, you might not, but I figured I would toss it out there. The reason it't not so good, is Perl can go through a lot of trouble to build a list of things to return from the map block, and if you don't use them its simply a waste of processor time and memory that could be better spent doing other things.

use perl;


Comment on Re: opening a file destroys nulling entries in a list?!?!
Download Code
Re: Re: opening a file destroys nulling entries in a list?!?!
by matpalm (Initiate) on Aug 07, 2003 at 03:47 UTC
    my first attempt was with
    foreach(@instances) { screwed "$_"; };
    and then when it didn't work i showed it to someone here at work and he introduced me to maps so i used
    map { screwed "$_"; } @instances;
    but...
    screwed "$_" for @instances;
    ..is even less typing again!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2015-07-03 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (55 votes), past polls