RE: using 'map' with mixture of scalars and array refs...

2002-10-23 Thread Peter Scott
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Michael Hooten) writes: >Simpler and easier to read: >@combined = map { ref $_ eq 'ARRAY' ? @$_ : $_ } values %{$hash{family}}; > >Either dereference the array or return the scalar. Yes, I'm aware of the 'either' in the posting. However, the exa

RE: using 'map' with mixture of scalars and array refs...

2002-10-23 Thread Michael Hooten
D] Subject: Re: using 'map' with mixture of scalars and array refs... In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Michael Kavanagh) writes: >Hi there, > >I've got a hash that has keys which contain either >- array references >- scalar values > &

Re: using 'map' with mixture of scalars and array refs...

2002-10-22 Thread John W. Krahn
Michael Kavanagh wrote: > > Hi there, Hello, > I've got a hash that has keys which contain either > - array references > - scalar values > > for example: > @values = (12398712984, 19286192879); > $hashofarrays{'family'}{'arrayref'} = \@values; > $hashofarrays{'family'}{'scalar'} = 12938712938;

Re: using 'map' with mixture of scalars and array refs...

2002-10-22 Thread Peter Scott
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Michael Kavanagh) writes: >Hi there, > >I've got a hash that has keys which contain either >- array references >- scalar values > >for example: >@values = (12398712984, 19286192879); >$hashofarrays{'family'}{'arrayref'} = \@values; >$hashofarrays

Re: Using map

2002-10-03 Thread Jeff 'japhy' Pinyan
On Oct 3, [EMAIL PROTECTED] said: >I'm having a difficult time understanding the map function. You're having a hard time coping with the fact that $_ is an alias to the values in the list you're mapping over, not a copy. >@new_names = map { ($x = $_) =~ s/(jpg|gif)$/html/i; $x } @old_names; > >

Re: Using map

2002-10-03 Thread George Schlossnagle
Not necessarily prettier: @new = map {m/(.*)(?:jpg|gif)$/i?"$1html":$_ } @old; Karl Kaufman wrote: >I, too, am interested in this syntax. I had to do the same juggling in order to >"map" the values without affecting the original array -- and would prefer cleaner >syntax if it's possible.

Re: Using map

2002-10-03 Thread Karl Kaufman
I, too, am interested in this syntax. I had to do the same juggling in order to "map" the values without affecting the original array -- and would prefer cleaner syntax if it's possible. Thx! Karl > @new_names = map { ($x = $_) =~ s/(jpg|gif)$/html/i; $x } @old_names; > > Is there a more el

Re: Using map

2002-10-03 Thread Bob Showalter
- Original Message - From: <[EMAIL PROTECTED]> To: "Beginners Perl Mailing List" <[EMAIL PROTECTED]> Sent: Thursday, October 03, 2002 1:31 AM Subject: Using map > Hello, All: > > I'm having a difficult time understanding the map function. > > I've got an array of file names that all end

RE: Using map

2002-10-03 Thread Robin Cragg
Hi Eric, if you want a more pretty way, (if a touch slower) try: my @new_names = @old_names; foreach (@new_names) { s/\.(jpg|gif)/\.html;i ; } I personally don't like map as I came to PERL from C, but if you want to use it instead... my @new_names = @old_names; map s/\.(jpg|gif)/\.html/i, @new