question about MAP function, please help. 
Author Message
 question about MAP function, please help.

Hi, all

there are too many perl functions and a lot i need to learn how and when to
use them. now after reading the doc for map function , i am still
confused. here i have two codes which i don't quiet sure what's going on

#1


saved into $_ , then the block function evalutes each of them i.e the "-s

#2:


print "$c \n";

i got the output as uncertain alphebet combination in length 6. again, my



my another question arises.... under what situation should i use map ?
which way is better ? does it make really difference between map code with
this while one regardless of the length of the code ,  is the
time-consuming ?  

thanks

.QiaNg



Thu, 25 Mar 2004 09:16:21 GMT  
 question about MAP function, please help.
[Posted and mailed]



Quote:
> #1



> saved into $_ , then the block function evalutes each of them i.e the "-s



Quote:
> #2:




> print "$c \n";

> i got the output as uncertain alphebet combination in length 6. again, my



map is used to iterate over one list, returning another list.  Essentially
doing a transformation of the first into the second.  The second list can
be larger, smaller, related to or have nothing to do with the first list
at all.

In this case the mistake comes in $c.  Rmember: map is normally used to
return a list.  You're using it in a /scalar/ context and map's scalar
context return value is the number of elements returned.  (Always 6.)

Try this variation:


This properly takes the list coming out of map, joins them together
into a scalar, which is what I presume you intended.

Quote:
> my another question arises.... under what situation should i use map ?

Whenever appropriate.  :)

Quote:
> which way is better ?

When it fits better.

Quote:
> does it make really difference between map code with
> this while one regardless of the length of the code ,  is the
> time-consuming ?  

Do whatever works best for you.  In terms of efficiency, your time spent
programming is probably more important than how long the program takes to
run.  Get the big picture right, and don't sweat the small stuff too
much.

--
    Clinton A. Pierce            Teach Yourself Perl in 24 Hours  *and*

"If you rush a Miracle Man,     for details, see http://geeksalad.org    
        you get rotten Miracles." --Miracle Max, The Princess Bride



Thu, 25 Mar 2004 14:54:28 GMT  
 question about MAP function, please help.

Quote:
>map is used to iterate over one list, returning another list.  Essentially
>doing a transformation of the first into the second.  The second list can
>be larger, smaller, related to or have nothing to do with the first list
>at all.

One thing to bear  in mind is that $_ is an alias for the elements of
the source list. If you modify $_, you also modify your input. Doing
this is usually considered a boo-boo.

If you want to have only some elements from the input list in your
output, you should probably use grep.

Just my $0.02,
--

split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while



Fri, 26 Mar 2004 16:59:11 GMT  
 question about MAP function, please help.

Quote:


> >map is used to iterate over one list, returning another list.  Essentially
> >doing a transformation of the first into the second.  The second list can
> >be larger, smaller, related to or have nothing to do with the first list
> >at all.

> One thing to bear  in mind is that $_ is an alias for the elements of
> the source list. If you modify $_, you also modify your input. Doing
> this is usually considered a boo-boo.

I often use map to *intentionally* modify all the elements in an array:


Quote:

> If you want to have only some elements from the input list in your
> output, you should probably use grep.

> Just my $0.02,
> --

> split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
> '"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while




Sun, 28 Mar 2004 20:54:07 GMT  
 question about MAP function, please help.

Quote:


> > >map is used to iterate over one list, returning another list.  Essentially
> > >doing a transformation of the first into the second.  The second list can
> > >be larger, smaller, related to or have nothing to do with the first list
> > >at all.

> > One thing to bear  in mind is that $_ is an alias for the elements of
> > the source list. If you modify $_, you also modify your input. Doing
> > this is usually considered a boo-boo.

> I often use map to *intentionally* modify all the elements in an array:




Anno



Mon, 29 Mar 2004 11:52:07 GMT  
 question about MAP function, please help.

September MCMXCIII in <URL::">

Quote:


}} > >

}} > > >map is used to iterate over one list, returning another list.  Essentially
}} > > >doing a transformation of the first into the second.  The second list can
}} > > >be larger, smaller, related to or have nothing to do with the first list
}} > > >at all.
}} > >
}} > > One thing to bear  in mind is that $_ is an alias for the elements of
}} > > the source list. If you modify $_, you also modify your input. Doing
}} > > this is usually considered a boo-boo.
}} >
}} > I often use map to *intentionally* modify all the elements in an array:
}} >

}}


      CARPARK:
   {  my $fookie = 0; BUBBLE:

      $arr [$fookie ++] =~ s/asdf/lkj/;
      goto BUBBLE
   }

Abigail
--
perl -wle 'print prototype sub "Just another Perl Hacker" {};'
#    A flying eagle. A
#    beetle flies above a lake.
#    A bear. A Bishop.



Tue, 30 Mar 2004 23:01:39 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. grep & map, help please

2. Site map for web site - Perl scripts - help please

3. Basic PERL Question - PLEASE PLEASE HELP

4. HELP Please - DLL Function

5. PLEASE HELP!!!!! - Calling System Functions

6. Simple Query Function Help Please!

7. Common Module Functions...help please!

8. File handling and manipulation from function, help please?

9. stat function, strange behaviour, please help

10. HELP Please - DLL Function

11. sin tan cos function help please!

12. Problem calling perl functions in CGI- please help.

 

 
Powered by phpBB® Forum Software