Data Structures in Perl

2003-07-06 Thread Trevor Morrison
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]



RE: Data Structures in Perl

2003-07-06 Thread Gupta, Sharad
>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]



Re: Data Structures in Perl

2003-07-06 Thread Robin Norwood
"Gupta, Sharad" <[EMAIL PROTECTED]> writes:

> >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();
   ^ 'order', or 'orders'?
> }

The Perlish way to do the above is:

foreach my $order (@orders) {
  print $order->order_number();
}

This iterates over each element in the array @orders, and places them
in turn in a variable called '$order'.  Do it this way, and you don't
have to worry about the index of the array at all.

-RN

-- 
Robin Norwood
Red Hat, Inc.

"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Data Structures in Perl

2003-07-08 Thread Trevor Morrison
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=>'$'   ,

how to create/use data structures in perl ?

2003-07-08 Thread Madhu Reddy
Hi,
   How to create data structures in perl ?
I have following data structure in C...and i have to
create similar data structure in perl and use...

how to create data strutures in perl and how to use ?



typedef struct  {   charPrefix[8];
charPrint;
charName[80];
charModTime[32];
int Len;
}   fileinfo_;

Thanks
-Madhu


__
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: how to create/use data structures in perl ?

2003-07-08 Thread Sudarshan Raghavan
Madhu Reddy wrote:

Hi,
  How to create data structures in perl ?
I have following data structure in C...and i have to
create similar data structure in perl and use...
how to create data strutures in perl and how to use ?

perldoc -f pack
perldoc -f unpack


typedef struct  {   charPrefix[8];
charPrint;
charName[80];
charModTime[32];
int Len;
}   fileinfo_;
Eg.
#!/usr/bin/perl
use strict;
use warnings;
my $format = 'Z8 c Z80 Z32 i';
my $fileinfo_instance = pack ($format, 'project_', 1, 'SomeName', 
'ModTime', 40);
my ($prefix, $print, $name, $modtime, $length) = unpack ($format, 
$fileinfo_instance);

print "Prefix  = $prefix\n";
print "Print   = $print\n";
print "Name= $name\n";
print "Modtime = $modtime\n";
print "Length  = $length\n";
Thanks
-Madhu
__
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Can anyone guide me for : Data Structures in Perl

2005-07-17 Thread atul ashpalia
Hi,

can anybody help me with a link or a tutorial for
understanding the Datastructures in perl.

Example, Array of Array, Hash of Array, Hash of Hash,
Array of Hash.

Along with few scripts to understand their
application.

thanks in advance,
Atul Ashpalia

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Can anyone guide me for : Data Structures in Perl

2005-07-17 Thread Wijaya Edward
You can find everything you need in:

perldoc perldsc

--
Regards,
Edward WIJAYA
SINGAPORE


> 
> can anybody help me with a link or a tutorial for
> understanding the Datastructures in perl.
> 
> Example, Array of Array, Hash of Array, Hash of Hash,
> Array of Hash.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Can anyone guide me for : Data Structures in Perl

2005-07-17 Thread Wiggins d'Anconia
Wijaya Edward wrote:
>
> 
>>can anybody help me with a link or a tutorial for
>>understanding the Datastructures in perl.
>>
>>Example, Array of Array, Hash of Array, Hash of Hash,
>>Array of Hash.
> 
> 
> 
> 
> You can find everything you need in:
>
> perldoc perldsc
>
> --
> Regards,
> Edward WIJAYA
> SINGAPORE
>

There are also:

perldoc perllol
perldoc perlreftut
perldoc perlref

And Learning Perl Objects, References, and Modules from O'Reilly.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]