On Tue, 12 Jun 2001, Shawn wrote:

> Anyone know why the attatched script produces this error for every time
> it prints a line?

Two comments (and a fix):

In general, you never want to use 'map' unless you care about the return
value. You don't in this case, so you can use a for loop instead.

Why is it a hash? It takes a bit of a close look to figure it out:

'+{...}' looks like a code block, but it's actually the identity of an
anonymous hash. '+' is the identity operator in perl (see the perlop
manpage). And '{...}' returns a reference to a hash unless used in a code
block context (i.e after 'do', 'eval', 'map', 'sub', and several other
keywords). Because it followed the '+' operator, it was interpreted as a
hash constructor. Each hash contained only the return value of 'print',
which is 1. And only 1 entry.

Later,
Neil

--- listdir.pl  Tue Jun 12 08:54:22 2001
+++ listdir.new Tue Jun 12 08:55:48 2001
@@ -4,7 +4,7 @@

 use Inline C;

-map +{ print "$_\n" } , list_dir("/var");
+print "$_\n" for list_dir("/var");

 __END__
 __C__


Reply via email to