in reply to Re: Parsing email and returning the key/values in two hashes
in thread Parsing email, inserting into database and creating an aggregation report.

Hi,
I indeed used 'split' operator, but didn't know how to pack each column value.
  • Comment on Re^2: Parsing email and returning the key/values in two hashes

Replies are listed 'Best First'.
Re^3: Parsing email and returning the key/values in two hashes
by Random_Walk (Prior) on Dec 22, 2004 at 19:42 UTC

    Hi 'gator,

    If you have a line that is fixed width columns you can unpack it based on the widths quite easily. This gets around all the probs of split and fields that can contain a variable amount of whitespace (I suspect your category field easily could)

    # it goes a little like this while (<DATA>) { my ($Name, $Host, $Port, $Rest)=unpack('A15A10A10A*', $_); # now do what you will with them }

    the A tells it to unpack ASCII, the numbers are the number of characters in each column, the A* just grabs the rest 'cos I was too lazy to count all your column widths

    Festive Cheers,
    R.