[Nh-pm] The Perly Way

Paul L Lussier pll at lanminds.com
Wed May 14 14:28:12 CDT 2003


In a message dated: Wed, 14 May 2003 14:48:55 EDT
Ray Cote said:

>At my stage of Perl development, it takes too long to wrap my mind 
>around the anonymous code block inside the map. That }@$rowref; line 
>simply looks wrong to my poor little C++/Pascal-addled brain. :}

Oops, forgot to address this :)


What's the difference between:

    map { $_ = 'NULL' if !defined($_) } @$rowref;
    print join( "\t", @$rowref) . "\n";

and

    map { $_ = 'NULL' if !defined($_);
          print "$_\t";               
        } @$rowref;
    print "\n";                         

Syntactlically, they're basically the same.  In the second though, 
I'm moving the print inside the map.  think of the map() as nothing 
more than a 'foreach'.  These two snippets are functionally equivalent:

    foreach (@$rowref) {             | map {
        $_ = 'NULL' if !defined($_); |       $_ = 'NULL' if !defined($_);
        print "$_\t";                |        print "$_\t";
    }				     |     } @$rowref;
    print "\n";			     | print "\n";

All I did was take:

    map { $_ = 'NULL' if !defined($_) } @$rowref;

and add one statement, which created this:

    map { $_ = 'NULL' if !defined($_); print "$_\t"; } @$rowref;

Then, I just added a couple new lines to get:


    map { $_ = 'NULL' if !defined($_);

          print "$_\t";

        } @$rowref;
    print "\n";

to make it more readable.

However, YOU created:

    map { $_ = 'NULL' if !defined($_) } @$rowref;

to begin with, all I did was add a print statement :)

So, a print statement should be too tough to wrap your
"C++/Pascal addled brain around" ;)
-- 

Seeya,
Paul
--
Key fingerprint = 1660 FECC 5D21 D286 F853  E808 BB07 9239 53F1 28EE

	It may look like I'm just sitting here doing nothing,
   but I'm really actively waiting for all my problems to go away.

	 If you're not having fun, you're not doing it right!





More information about the Nh-pm mailing list