Read this from perldoc
C:\WINNT>perldoc -q void
Found in C:\Perl\lib\pod\perlfaq6.pod
What's wrong with using grep or map in a void context?
Both grep and map build a return list, regardless of their
context. This means you're making Perl go to the trouble of
building up a return list that you then just ignore. That's no
way to treat a programming language, you insensitive scoundrel!
Found in C:\Perl\lib\pod\perlfaq8.pod
What's wrong with using backticks in a void context?
Strictly speaking, nothing. Stylistically speaking, it's not a
good way to write maintainable code because backticks have a
(potentially humongous) return value, and you're ignoring it.
It's may also not be very efficient, because you have to read in
all the lines of output, allocate memory for them, and then
throw it away. Too often people are lulled to writing:
`cp file file.bak`;
And now they think "Hey, I'll just always use backticks to run
programs." Bad idea: backticks are for capturing a program's
output; the system() function is for running programs.
Consider this line:
`cat /etc/termcap`;
You haven't assigned the output anywhere, so it just wastes
memory (for a little while). You forgot to check "$?" to see
whether the program even ran correctly, too. Even if you wrote
print `cat /etc/termcap`;
this code could and probably should be written as
system("cat /etc/termcap") == 0
or die "cat program failed!";
which will get the output quickly (as it is generated, instead
of only at the end) and also check the return value.
system() also provides direct control over whether shell
wildcard processing may take place, whereas backticks do not.
How do I avoid zombies on a Unix system?
Use the reaper code from the section on "Signals" in the perlipc
manpage to call wait() when a SIGCHLD is received, or else use
the double-fork technique described in the fork entry in the
perlfunc manpage.
Jos�.
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Thursday, March 13, 2003 5:43 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: How to map hash keys only, not values?
>
>
>
>
> >First, please don't use map in a void context for its side effects.
>
> Uh oh... What side effects? I use map like this all the
> time! What dread is looming in my future?
>
>
> >Just loop it:
> >
> > sub subname {
> > my %values;
> > while (@_ >= 2) {
> > my ($key, $value) = splice @_, 0, 2;
> > $values{uc $key} = $value;
> > }
> > ...
> > }
>
> Thanks! As is often the case, it looks obvious now that I see it.
>
>
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
**** DISCLAIMER ****
"This e-mail and any attachment thereto may contain information which is confidential
and/or protected by intellectual property rights and are intended for the sole use of
the recipient(s) named above.
Any use of the information contained herein (including, but not limited to, total or
partial reproduction, communication or distribution in any form) by other persons than
the designated recipient(s) is prohibited.
If you have received this e-mail in error, please notify the sender either by
telephone or by e-mail and delete the material from any computer".
Thank you for your cooperation.
For further information about Proximus mobile phone services please see our website at
http://www.proximus.be or refer to any Proximus agent.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]