Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Can you make it nicer?

by hdb (Prior)
on Nov 19, 2013 at 07:46 UTC ( #1063291=note: print w/ replies, xml ) Need Help??


in reply to Can you make it nicer?

Or this?

sub id2path_new { my $id = shift or return q(); return sprintf "%03d/$2/$3", $1 if $id =~ /(.+)(...)(...)/; return join "/", "00000$id" =~ /(..)(..)(..)$/; }

Update: Changed the last line, was return sprintf "%02d/%02d/%02d", "00000$id" =~ /(..)(..)(..)$/;.

Update: Another variation:

sub id2path_new { my $id = shift or return q(); $id =~ /(.+)(...)(...)/ or "00000$id" =~ /(..)(..)(..)$/; return sprintf "%0".length($3)."d/$2/$3", $1; }

Update: ...and close to obfuscation...

sub id2path_new { my $id = shift or return q(); sprintf "%0".($id=~/(.+)(...)(...)/?3:("00000$id"=~/(..)(..)(..)$/ +,2))."d/$2/$3",$1; }

I am getting carried away, so here is yet another one:

sub id2path_new { $_[0]?join"/",grep{$_}"00000$_[0]"=~/0*(..)(..)(..)$|0*(.{3,})(... +)(...)$/:q(); }


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://1063291]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-12-26 17:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (172 votes), past polls