Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: create filename from IP#

by jdporter (Paladin)
on Nov 26, 2003 at 19:18 UTC ( [id://310354]=note: print w/replies, xml ) Need Help??


in reply to create filename from IP#

my $IP = '127.0.0.1'; # or whatever my $abs_IP = join '', map { sprintf "%03d", $_ } split /\./, $IP;

jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.

Replies are listed 'Best First'.
Re: Re: create filename from IP#
by holo (Monk) on Nov 26, 2003 at 20:59 UTC
    my $IP = '127.0.0.1'; my $abs_IP = sprintf "%03d"x4, split /\./, $IP;

    Avoid map for simple stuff. The "%03d"x4 above is computed during compilation. Also, avoid loops at runtime.

    You should also consider using the resutling string as a prefix of the resulting filename for security reasons. There is File::Temp for that.

    UPDATE: Ignoring the fact that this might not be as useful as one might think, you should really use a database for this type of job. It's a lot safer, faster and scalable.

    It depends on what you store in each file. If you store small records of just a few bytes, you could be using 2k or 4k (or more) of disk space for each file according to your fs blocksize. Take a look to DB_File for more info.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://310354]
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: (5)
As of 2024-04-18 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found