Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by leriksen (Curate)
on Aug 07, 2003 at 03:52 UTC ( #281738=note: print w/ replies, xml ) Need Help??


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

I am getting slightly different behaviours depending on whether I use

screwed $_;
or
screwed "$_";
I use AS 5.6.1
In the first, screwed()::@_ gets clobbered, in the second screwed()::@_ is OK, but @instances is still clobbered.

And if I could just add, to the original poster, that
map {function($_)} @array;
is generally frowned upon - map returns a list, and by not having map on the RHS of an assignment
@result_set = map {function($_)} @array
, that list is considered being used in a void context. This means, in this case, all the hard work of creating a list of results via the map is wasted, the list is thrown away. Because screwed() doesn't explicitly return a value, it defaults to using the return value of the close() statement at the end of the sub. If you really dont care about the return values of applying a function using the elements of an array as parameters, it is 'better'(tm) to use this idiom
foreach (@array) {sub_without_meaningful_return($_)}
This makes it clear that the function has side-effects - that is, the function uses and possibly changes some variable outside its scope- in screwed()'s case, STDOUT is used.
merlyn has lectured me once on this - so I now pass this on.


Comment on Re: opening a file destroys nulling entries in a list?!?!
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-12-21 18:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls