Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Can you make it nicer?

by hexcoder (Hermit)
on Nov 19, 2013 at 14:46 UTC ( #1063342=note: print w/ replies, xml ) Need Help??


in reply to Can you make it nicer?

I tried to seperate the necessary steps. The code satisfies the tests. $id is treated only as a string.

sub id2path_new { my $id = shift; return q() unless $id; # group of digits my $bits = length $id > 6 ? 3 : 2; # prepend with 0 digits if necessary my $id = ('0' x (3 * $bits - length $id)) . $id; my @parts = ( # leftmost part (substr $id, 0, -2 * $bits), # subparts (substr $id, -2 * $bits) =~ m{(\d{$bits})}xmsg ); return join q{/}, @parts; }


Comment on Re: Can you make it nicer?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-09-02 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (31 votes), past polls