On 10-05-12 04:15 PM, Brian wrote:
Hi all. 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;
Thanks,
Brian
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
# Set maximum depth for Data::Dumper, zero means unlimited
local $Data::Dumper::Maxdepth = 0;
my @pages = (
"lc1",
"lc2/",
"lc3/index.html",
"lc4/",
"lc5",
);
for my $page ( @pages ){
if( $page =~ m{ html \z }msx || $page =~ m{ \/ \z }msx ){
}else{
$page .= '/';
}
}
print '@pages: ', Dumper \...@pages;
__END__
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
I like Perl; it's the only language where you can bless your
thingy.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/