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.