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
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
>
&
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;
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
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;
>
>
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.
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
- 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
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