HI,
I must be missing something, after following Gupta's advice the particular
object printed fine using this code:
$obj->order_number ($order_num);
print "obj:" . $obj->order_number($order_num) . "\n";
push @order, $obj;
for each of the 15 orders which I have shown below. Now, at the end of my
program I run a for loop:
for (my $w=0;$w<=$#order;$w++) {
print "Order Number:" . $order[$w]->order_number() . "\n";
}
to print out all of the 15 differnet order numbers and all I get is the last
order number printed 15 times. What am I missing besides sleep. TIA.
Trevor
C:\maverick>perl miva_struc_class.pl
# of Rows in Order: 25 rows in the 1 order
Order Number is 3225
w is 1
obj:3225
# of Rows in Order: 27 rows in the 2 order
Order Number is 3218
w is 2
obj:3218
# of Rows in Order: 25 rows in the 3 order
Order Number is 3223
w is 3
obj:3223
# of Rows in Order: 26 rows in the 4 order
Order Number is 5010
w is 4
obj:5010
# of Rows in Order: 29 rows in the 5 order
Order Number is 5006
w is 5
obj:5006
# of Rows in Order: 26 rows in the 6 order
Order Number is 5010
w is 6
obj:5010
# of Rows in Order: 26 rows in the 7 order
Order Number is 5003
w is 7
obj:5003
# of Rows in Order: 27 rows in the 8 order
Order Number is 4971
w is 8
obj:4971
# of Rows in Order: 26 rows in the 9 order
Order Number is 4931
w is 9
obj:4931
# of Rows in Order: 27 rows in the 10 order
Order Number is 4925
w is 10
obj:4925
# of Rows in Order: 25 rows in the 11 order
Order Number is 4893
w is 11
obj:4893
# of Rows in Order: 26 rows in the 12 order
Order Number is 4864
w is 12
obj:4864
# of Rows in Order: 25 rows in the 13 order
Order Number is 4870
w is 13
obj:4870
# of Rows in Order: 29 rows in the 14 order
Order Number is 4873
w is 14
obj:4873
# of Rows in Order: 25 rows in the 15 order
Order Number is 3280
w is 15
obj:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
Order Number:3280
C:\maverick>
-----Original Message-----
From: Gupta, Sharad [mailto:[EMAIL PROTECTED]
Sent: Sunday, July 06, 2003 4:55 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Data Structures in Perl
>From ur example i assume that:
my @order is an array collecting all of the objects with each order.
So, instead of
my @order = new miva_order;
we mean to say:
my @orders;
my $obj = new miva_order;
$obj->order_number(get_order_num_via_regex());
push @orders,$obj;
for (my $w=0;$w<=$#orders;$w++) {
print $order[$w]->order_number();
}
Note that in the for loop above i am starting $w with 0 and not 1. If u
start with 1 and ur @order have only 1 element, it won't print anything
because the index start with '0'
-Sharad
-----Original Message-----
From: Trevor Morrison [mailto:[EMAIL PROTECTED]
Sent: Sunday, July 06, 2003 10:37 AM
To: [EMAIL PROTECTED]
Subject: Data Structures in Perl
Hi,
I am new to using data structures in Perl, but have played with them in C (a
long time ago). I have downloaded the Class::Struct::Fields module on my
W2K system and all works well. I am finding the documentation a little
terse though.
I am trying to read into my Perl program orders that was placed through an
on-line shopping cart that are sent to an Outlook mailbox. I export the
email to a file that I read into my Perl program. Since each order is
basically the same as far as content is concerned there are some variation.
I would like to use a data structure to store each orders information in.
Now, I have read through the "Programming Perl" manual (Chapter 9) on Data
structures several times and searched the web for the information that I
need, but cannot find it.
If I claim my data structure like so:
use Class::Struct::FIELDS;
struct (miva_order => {
order_number =>'$' ,
date =>'$' ,
bill_name =>'$' ,
ship_name =>'$' ,
ship_email_address =>'$' ,
ship_phone_number =>'$' ,
ship_business_name =>'$' ,
ship_to_street =>'$' ,
ship_to_city =>'$' ,
ship_to_state =>'$' ,
ship_to_zip =>'$' ,
bill_to_street =>'$' ,
bill_to_city =>'$' ,
bill_to_state =>'$' ,
bill_to_zip =>'$' ,
quantity =>'$' ,
code =>'$' ,
shipping_method =>'$' ,
shipping_amount =>'$' ,
sales_tax =>'$' ,
notes =>'$'
}
);
my @order = new miva_order;
I want to fill the fields saying $order->order_number($order_numb) where the
$orders numb is pulled from the email using regular expressions.
Now, what I want to be able to do is say :
for (my $w=1; $w<=$number_of_orders; w++) {
print $order[$w]->order_number ;
}
and have all the order numbers that are associated with the each of the
orders print out; and it does not work this way. This is where my problem
is, I am coding wrong and I cannot see it. Any help is appreciated.
Trevor
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]