Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: A Better Guten Split

by ikegami (Patriarch)
on Dec 01, 2009 at 00:35 UTC ( [id://810292]=note: print w/replies, xml ) Need Help??


in reply to A Better Guten Split

I guess we can start by getting rid of the useless variable and shorten the silly pattern.

my $split = join '/', split //, $id; substr($split, -2, 2, ''); my $url = "$base_url/$split/$id/$id-h/$id-h.htm";

Two lines to calculate and one line to assemble. I don't think length is really a problem here. We're dealing with readability issues if we try to shorten it any more. These are just too complicated:

substr( ( my $split = join '/', split //, $id ), -2, 2, ''); my $url = "$base_url/$split/$id/$id-h/$id-h.htm";
( my $url = join '/', split //, $id ) =~ s{(.*)/}{$base_url/$1/$id/$id-h/$id-h.htm}s;

I'm partial to this *longer* version:

my $url = join('/', $base_url, $id =~ /(.)(?=.)/sg, $id, "$id-h", "$id-h.htm" );

The flow is very simple, so it's easy to understand.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://810292]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-04-25 15:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found