New to Perl. Need some guidance with what to do..

From: scadav (dkscaccia_at_yahoo.com)
Date: 07/18/04


Date: Sun, 18 Jul 2004 00:58:21 GMT

I am pretty new to perl so I am hoping someone can give me some direction
with the following problem.

I have a log file which tracks orders that are placed. If a customer
places an order, that order will be given a unique identifier. If the
customers decides to change the order, the replaced order will be given a
new identifier (replacing the old one). For example:

Item OrderID OldOrderID Quantity
xyz 1234 NONE 200
xyz 1235 1234 150
xyz 1427 1235 175
abc 4561 NONE 200
abc 8541 4561 450
xyz 1785 1427 250
xyz 1263 1785 800
jot 4715 NONE 12
nuy 7894 NONE 856
xyz 8978 NONE 741 **** (New different order for
XYZ)

Here is what the actual log file looks like:
xyz|1234|NONE|200
xyz|1235|1234|150
xyz|1427|1235|175
abc|4561|NONE|200
abc|8541|4561|450
xyz|1785|1427|250
xyz|1263|1785|800
jot|4715|NONE|12
nuy|7894|NONE|856
xyz|8978|NONE|741

In this example, the order for xyz changed 5 times and I would like to
create a list of all the id numbers that are associated with that one
order that was changed 5 times. Keep in mind that the log file will
contain other orders for xyz, but they are NEW orders and not CHANGED
orders. For example, this would be the output I am looking for:

1234
1235
1427
1785
1263

I figured the best way to go about this was to try to put the values into
an array. Well, I can get the first two ids into the array, but I am not
sure how to continue to search from the last item I put into the array
and keep comparing to the has I created. Not sure if that makes sense or
not. Anyhow below is the code that I created. Can anyone point me in
the correct direction?

Thanks

#######################################################
use strict;

my $logfile=();
my $rcd=();
my @row=();
my %cxlrepl=();
my $orderid=();

my $oldid=();
my $newid=();

my @idlist=();

my $ab=();

$orderid = 1234;
$logfile = "temp.txt";

open (DATA, $logfile) || die ("cannot open file");

while ($rcd = <DATA>){
        next unless (!($rcd =~ /NONE/));
        @row = split(/\|/,$rcd);
        $cxlrepl{$row[2]}=$row[1];
}

push (@idlist, $orderid);

while (($oldid, $newid) = each(%cxlrepl)){

                if ($orderid == $oldid){
                        push (@idlist, $newid);
                }
                
}

foreach (@idlist){
print "$_ \n";
}
#####################################################



Relevant Pages

  • Re: modifying putty to include the symmetric key in the logs
    ... 'keyspace' is an array of 'unsigned char' values, ... Of course such an attacker would become able to ... logged in cleartext _in_ the log file, so an attacker able to read ...
    (comp.security.ssh)
  • Re: regExp
    ... > It uses ReadAllto store the entire log file into an array then it uses ... ReadAll() is not suitable for "find" style log parsing because it's ... Of course if it's just a script for Juan to run himself, ...
    (microsoft.public.scripting.wsh)
  • Re: annoying dhclient error messages
    ... > connection. ... The problem is that I get the following annoying error ... > bytes at end of array ... into a new log file, and block them from the console. ...
    (freebsd-questions)
  • Re: Using sortrows on mixed-type cell arrays
    ... I read the log file into a Matlab cell array, everthing is string ... I now want to sort the rows of the array first by then ...
    (comp.soft-sys.matlab)
  • Re: date/time -vbscript
    ... You can also generate unique identifier using VbScript using ... Fabrice Canel ... >I am creating a log file and need to make sure the log files created is ...
    (microsoft.public.scripting.vbscript)