Brian wrote:
Hi all.

Hello,

I think this should be relatively simple but i just can't figure it
out. I have a list of files and directories. The files will all end in
.html. All the remaining elements in the list are assumed to be
directories. I'm looking for a regex to add a trailing slash to the
directories if one doesn't exist. I can do this but using a series of
if statements, but I am trying to make my code more concise by using
the map function. Here is an example:

my @pages = (
        "lc1",
        "lc2/",
        "lc3/index.html",
        "lc4/",
        "lc5",
);

map {s/(some regex here)/$1\//} @pages;

$ perl -le'
my @pages = (
"lc1",
"lc2/",
"lc3/index.html",
"lc4/",
"lc5",
);
print "@pages";
s|(?<!/)\z|/| for @pages;
print "@pages";
'
lc1 lc2/ lc3/index.html lc4/ lc5
lc1/ lc2/ lc3/index.html/ lc4/ lc5/





John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to