Bryan R Harris wrote:
>>> I'm having trouble with this, and I'm sure someone out there has a
>>> really clever solution-- 
>>> 
>>> I have a hash, %data, with, say, 32 elements.
>>> 
>>> From that, I need an array going from 01 to 32, i.e. 01, 02, 03,
>>> 04, etc. 
>>> 
>> The real question is what are you attempting to do? With the hash,
>> you can have totals and any other info, pulse you have the key as
>> part of what is going.
> 
> 
> I'm building a script that will split a file into a bunch of little
> pieces, based on very specific and custom criteria.  The hash holds
> the data, e.g. $data{"32.52,53.21"} would hold all the data
> pertaining to that key ("10 20 30\n40 50 60\n"), and I want to write
> these little files out.  I want to number the output files based on
> the number of hash elements, but I want them to be zero-padded so
> they line up in file lists.  The rest of it works, I'm just having
> trouble coming up with the zero-padded numbers! 
> 
> - B

        Then use sprintf and what you believe to be the largest number you 
would process in a day.  If less than a thousand, then a sprintf "%03d" would 
zero pad and allow up to 999 entries per day. If over a 1000, then change to 
%04d to get almost 10,000 elements in a day.  You could use the hash and the 
array element to hold what you want to do:

                $data{key}[0] = file number
                $data{key}[1] = data for file.

        Now you can sort the key or not and then do something like:

        my $MyFileOut = sprintf "%03d", $data{key}[0];
        # now $MyFileOut is say 001 and you can open and write the data using 
[1] for the data.

Just a thought.

Wags ;)

Wags ;)


*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to