in reply to Serving many tarballs as part of your web space

I had the hardest time trying to understand the goings-on in this part of the script:
for my $step (1..$#path) { @names = map /\A\/?\Q$path[$step]\E(?:\/(.*))?\z/s, @names; die "no such name" unless @names; if (grep !defined $_, @names) {
I'm quite impressed.

Thanks for carving something useful out of my block of marble.

Replies are listed 'Best First'.
Re: Re: Serving many tarballs as part of your web space
by jryan (Vicar) on Jan 11, 2002 at 14:12 UTC

    I'd imagine the map is the only part that is really confusing; here it is in a nutshell:

    @names = map ( # start map / # start matching regex # this will place what is matched in the grouping # into $_, or undef if there are no matches \A # match start, kinda like ^, # except will ONLY match begining \/ ? # 0 or 1 literal backslashes \Q # start regex quotemeta $path[$step] # interpolated, and then quotemeta'd \E # end regex quotemeta (?: # non grouping parenthesis \/ # literal backslash (.*) # here is what actually is grouped; # matches the rest of the line )? # end non-grouping parens, 0 or 1 of those \z # match end, kinda like $, # except will ONLY match very end of string /sx # s lets . match newlines; i added the x , @names); # i added parenthesis
Re: Re: Serving many tarballs as part of your web space
by merlyn (Sage) on Jan 11, 2002 at 12:36 UTC
    The code I write for columns has far too few comments, because the comments are provided in the accompanying text. I think you'll see that it makes sense once you see the narrative I wrote for that particularly odd piece of code. I think I was trying to hard to be line-wise efficient.

    -- Randal L. Schwartz, Perl hacker

      Figured so.

      After sleeping over it, I'm wondering if there's any particular reason you didn't something along the following lines?

      my ($prefix, $filepath) = split '/', $path, 2; # ... @names = grep m!\A/?\Q$filepath\E(?:/.*)?\z!s, @names; if(@names == 1) { require Archive::Tar; # ... exit 0 } { my %choices = (); # ...

      The sole really significant difference I can see is that it doesn't catch the "trailing stuff after name" case. Am I missing something?

      Or should I just be patient and wait for the column? :-)