Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > MAP Question

Reply
Thread Tools

MAP Question

 
 
George
Guest
Posts: n/a
 
      01-17-2005
Hi
I needed to run regular exression(RE) for all the elements of an array
so I thought of using MAP(one liner) insted foreach.
Following line
@Rfolder=map {/#(.*?)(?=/,$_} @getlistF;
gave me all the existing elements plus what is extracted by RE

but
following line
@Rfolder=map {/#(.*?)(?=/} @getlistF;
gave me just what RE returned,

Definetly it means that I do not understand MAP correctly,
can somebody please explain what is the difference between two
statement , cause what I understood that $_ needs to be set before ,
for RE to work.
 
Reply With Quote
 
 
 
 
Matija Papec
Guest
Posts: n/a
 
      01-17-2005
X-Ftn-To: George

"George" <(E-Mail Removed)> wrote:
>Hi
>I needed to run regular exression(RE) for all the elements of an array
>so I thought of using MAP(one liner) insted foreach.
>Following line
>@Rfolder=map {/#(.*?)(?=/,$_} @getlistF;
>gave me all the existing elements plus what is extracted by RE
>
>but
>following line
>@Rfolder=map {/#(.*?)(?=/} @getlistF;
>gave me just what RE returned,
>
>Definetly it means that I do not understand MAP correctly,
>can somebody please explain what is the difference between two
>statement , cause what I understood that $_ needs to be set before ,
>for RE to work.


You didn't say what do you want to accomplish, and I'm not sure what are
you're expectations regarding map?


--
Matija
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      01-17-2005
George <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Hi
> I needed to run regular exression(RE) for all the elements of an array
> so I thought of using MAP(one liner) insted foreach.
> Following line
> @Rfolder=map {/#(.*?)(?=/,$_} @getlistF;
> gave me all the existing elements plus what is extracted by RE
>
> but
> following line
> @Rfolder=map {/#(.*?)(?=/} @getlistF;
> gave me just what RE returned,
>
> Definetly it means that I do not understand MAP correctly,
> can somebody please explain what is the difference between two
> statement , cause what I understood that $_ needs to be set before ,
> for RE to work.


Have you read the map documentation (not "MAP", case matters)?

As it explains, the block you give to map is evaluated in list context,
with $_ set to the list elements in turn.

In the first case, the block returns whatever the regex extracts, followed
by $_. In the second case, there is no $_ in the block, so it returns
just what the regex extracts. What else is to explain?

Anno
 
Reply With Quote
 
Peroli
Guest
Posts: n/a
 
      01-18-2005
hi george,
If Map bugs you, why dont you try grep. It works.
Peroli Sivaprakasam

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-18-2005
"Peroli" <(E-Mail Removed)> wrote in news:1106011879.674678.237640
@z14g2000cwz.googlegroups.com:

> hi george,
> If Map bugs you, why dont you try grep. It works.


map (not Map) works too. map and grep do different things. See

perldoc -f map
perldoc -f grep

Sinan.
 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      01-18-2005
On Mon, 17 Jan 2005 17:19:26 GMT, "George" <(E-Mail Removed)>
wrote:

>I needed to run regular exression(RE) for all the elements of an array


Yes...

>so I thought of using MAP(one liner) insted foreach.


Not such a thing as MAP...

>Following line
>@Rfolder=map {/#(.*?)(?=/,$_} @getlistF;


....as your correct use of map() shows.

>gave me all the existing elements plus what is extracted by RE


is this what you want? Is this _not_ what you want? What do you want?

>but
>following line
>@Rfolder=map {/#(.*?)(?=/} @getlistF;
>gave me just what RE returned,


Yes...

>Definetly it means that I do not understand MAP correctly,


Perhaps... are you missing a list context here?

Definitely you do _not_ understand that there's not such a thing as
MAP. And I can't really understand why you spell it so.

>can somebody please explain what is the difference between two
>statement , cause what I understood that $_ needs to be set before ,
>for RE to work.


What does make you suppose it's not set?

However I can't explain you the difference, but hopefully

perldoc -f map

can.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
Reply With Quote
 
George
Guest
Posts: n/a
 
      01-18-2005
Michele Dondi wrote:

> On Mon, 17 Jan 2005 17:19:26 GMT, "George" <(E-Mail Removed)>
> wrote:
>
> > I needed to run regular exression(RE) for all the elements of an
> > array

>
> Yes...
>
> > so I thought of using MAP(one liner) insted foreach.

>
> Not such a thing as MAP...
>
> > Following line
> > @Rfolder=map {/#(.*?)(?=/,$_} @getlistF;

>
> ...as your correct use of map() shows.
>
> > gave me all the existing elements plus what is extracted by RE

>
> is this what you want? Is this not what you want? What do you want?
>
> > but
> > following line
> > @Rfolder=map {/#(.*?)(?=/} @getlistF;
> > gave me just what RE returned,

>
> Yes...
>
> > Definetly it means that I do not understand MAP correctly,

>
> Perhaps... are you missing a list context here?
>
> Definitely you do not understand that there's not such a thing as
> MAP. And I can't really understand why you spell it so.
>
> > can somebody please explain what is the difference between two
> > statement , cause what I understood that $_ needs to be set before ,
> > for RE to work.

>
> What does make you suppose it's not set?
>
> However I can't explain you the difference, but hopefully
>
> perldoc -f map
>
> can.
>
>
> Michele


writing map as MAP was just for eye catcher, like in BOLD, I never
thought you guys would even comment on that,
any way
 
Reply With Quote
 
George
Guest
Posts: n/a
 
      01-18-2005
Anno Siegel wrote:

> George <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> > Hi
> > I needed to run regular exression(RE) for all the elements of an
> > array so I thought of using MAP(one liner) insted foreach.
> > Following line
> > @Rfolder=map {/#(.*?)(?=/,$_} @getlistF;
> > gave me all the existing elements plus what is extracted by RE
> >
> > but
> > following line
> > @Rfolder=map {/#(.*?)(?=/} @getlistF;
> > gave me just what RE returned,
> >
> > Definetly it means that I do not understand MAP correctly,
> > can somebody please explain what is the difference between two
> > statement , cause what I understood that $_ needs to be set before ,
> > for RE to work.

>
> Have you read the map documentation (not "MAP", case matters)?
>
> As it explains, the block you give to map is evaluated in list
> context, with $_ set to the list elements in turn.
>
> In the first case, the block returns whatever the regex extracts,
> followed by $_. In the second case, there is no $_ in the block, so
> it returns just what the regex extracts. What else is to explain?
>
> Anno


my mistake in understanding that RE was taking $_ as input ,
 
Reply With Quote
 
Tintin
Guest
Posts: n/a
 
      01-18-2005

"George" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Michele Dondi wrote:
>> > so I thought of using MAP(one liner) insted foreach.

>>
>> Not such a thing as MAP...

>
> writing map as MAP was just for eye catcher, like in BOLD, I never
> thought you guys would even comment on that,
> any way


The reason it was commented on, is that a number of Perl newbies don't
realise that Perl is a case sensitive language and they often make silly
mistakes like:

use cgi;

instead of:

use CGI;

If someone talks about using the xyz module (instead of XYZ), or the ABC
function (instead of abc), it put doubt into peoples mind as to whether the
poster really knows the correct case.


 
Reply With Quote
 
George
Guest
Posts: n/a
 
      01-18-2005
Tintin wrote:

>
> "George" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
> > Michele Dondi wrote:
> >> > so I thought of using MAP(one liner) insted foreach.
> > >
> >> Not such a thing as MAP...

> >
> > writing map as MAP was just for eye catcher, like in BOLD, I never
> > thought you guys would even comment on that,
> > any way

>
> The reason it was commented on, is that a number of Perl newbies
> don't realise that Perl is a case sensitive language and they often
> make silly mistakes like:
>
> use cgi;
>
> instead of:
>
> use CGI;
>
> If someone talks about using the xyz module (instead of XYZ), or the
> ABC function (instead of abc), it put doubt into peoples mind as to
> whether the poster really knows the correct case.


Makes sense,
thanks for clarifying
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
std::map::find() throws exception when map is empty? Matthias Hildebrand C++ 5 03-20-2012 06:09 AM
I can map all files (.*) to asp.net worker.How do I map NO FILE to asp.net worker? alex ASP .Net 1 02-04-2005 03:18 AM
searching keys in std::map using map::upper_bound Erik Arner C++ 0 11-02-2004 11:14 PM
map.insert(key,val) vs. map[key]=val ? Patrick Guio C++ 6 10-20-2004 01:54 PM
map that maps to iterators in the same map ? Vlad C++ 0 12-15-2003 08:29 PM



Advertisments