----- 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 in 'jpg' or 'gif'. I'd like
> to create a parallel array of file names that end in 'html'. I'm creating
> the array this way...
>
> @new_names = map { ($x = $_) =~ s/(jpg|gif)$/html/i; $x } @old_names;
>
> Is there a more elegant way to accomplish this? It just doesn't seem
> elegant assigning $_ to $x, performing the substitution on $x, and then
> returning $x.

@new_names = @old_names;
s/(jpg|gif)$/html/i for @new_names;

($_ is an alias for each entry in @new_names when used with the "for"
statement modifier)




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to