Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 imbibing at the Monastery: (9)
As of 2015-07-06 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls