S
scadav
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";
}
#####################################################
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";
}
#####################################################