forgot to reply to all for the following *laugh*


---------- Forwarded message ----------
From: Willy West <[EMAIL PROTECTED]>
Date: Tue, 8 Mar 2005 19:20:24 -0500
Subject: Re: Counting Multiple lines of data with a unique column of information
To: "Wilson, Josh --- Systems Analyst --- GO" <[EMAIL PROTECTED]>


>
> The problem is that one shipment might have more than one palette and I
> don't know how to strip multiple lines of data (with a unique shipment
> number) for processing.  I'm using Active Perl 5.8 in a Windows
> environment.
>
> For Example here are a few lines of dummy data
> (header provided for information only):
>
> ShipmentNumber  Weight  Date  Time  LocationID
>
> 01000 254 03082005 11:25:21 500
> 01000 210 03082005 11:27:36 500
> 01401 112 03082005 11:35:21 500
> 01401 678 03082005 11:37:36 500
> 01002 450 03082005 17:54:00 001
> 01785 105 03082005 03:05:67 250

here is one way to do it:

use strict;
use warnings;

my @data =
        (
        "01000 254 03082005 11:25:21 500",
        "01000 210 03082005 11:27:36 500",
        "01401 112 03082005 11:35:21 500",
        "01401 678 03082005 11:37:36 500",
        "01002 450 03082005 17:54:00 001",
        "01785 105 03082005 03:05:67 250"
        );

my $storage;

#replace the for loop with a
# while(<FILEHANDLE>) to get the results from an open file :)
#you may want to add chomp(); to the mix as
#well.

for (@data){
        print "one line is $_\n";

        /(\d{5})(.*)/; #assumes a 5 digit part #

        push (@{$storage->{$1}},$2);

#this last bit puts the data into a hash that
#uses the part numbers as its keys..

}

for (keys(%{$storage})){
        print "Item $_ has " . @{$storage->{$_}} . "  entries\n";
        }

----------------------------------------

and here is the sample data's output::

one line is 01000 254 03082005 11:25:21 500
one line is 01000 210 03082005 11:27:36 500
one line is 01401 112 03082005 11:35:21 500
one line is 01401 678 03082005 11:37:36 500
one line is 01002 450 03082005 17:54:00 001
one line is 01785 105 03082005 03:05:67 250
Item 01000 has 2 entries
Item 01401 has 2 entries
Item 01785 has 1 entries
Item 01002 has 1 entries

----------------------------------

look up "regular expressions" with perl and "hash references" in order
to make these
kinds of tasks easier.

good luck :)

Willy
http://www.hackswell.com/corenth

-- 
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