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_names;
R
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: 03 October 2002 06:31
To: Beginners Perl Mailing List
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.
--
Eric P.
Sunnyvale, CA
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]