data structures

2003-03-04 Thread David Gilden
I am trying to build a data structure, and am tripping up here.  
any suggestions?
Thx!
Dave

!/usr/bin/perl -w
 snip...
@bags = param('handbag');   get all of the bags styles
@bag_quantity = param('quantity');   get all of the bags quantity 

foreach my $bag (@bags){
($bag_name,$imgName)  =  split (/,/,$bag);
push %bags_ordered,$bag_name;
push %bags_ordered{$bag_name}{image_name} = $imgName;
}

foreach my $q (@bag_quantity){
push %bags_ordered{$bag_name}{$bag_quantity} =$q; 
}


Data structure: 



%bags_ordered = (
"bag-style1" =>   { price => 10,
image_name => 'FIO-142b-small',
 quantity=> 5
   },

"bag-style2" =>   { price => 12,
image_name => 'GUC-208-small',
   quantity=> 5,
   },

);

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



newbie: data structures

2002-07-24 Thread Anthony E.

How would I store (and access) a table of
information...assuming there is a unique key
'email'...ie -

These are the column names:
email firstName lastName phone address1

"[EMAIL PROTECTED]" "Joe Blow" "415-555-" "123
Mayberry"

"[EMAIL PROTECTED]"  "John Doe" "619-555-5551" "456 Happy
Ln."

etc...etc...
(also some of the fields will be null from time to
time).



__
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

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




RE: data structures

2003-03-04 Thread Hanson, Rob
> any suggestions?

I'll try.

> @bags = param('handbag');  get all of the bags styles

Missing comment...

@bags = param('handbag'); # get all of the bags styles

> push %bags_ordered,$bag_name;

You can't push onto a hash, only an array.  So either %bags_ordered need to
be an array, or you mean something else.

Maybe this is what you mean...

use strict; # a big bonus for debugging
use Data::Dumper; # for testing

my %bags_ordered;
my @bags = param('handbag'); # get all of the bags styles
my @bag_quantity = param('quantity'); # get all of the bags quantity 

for (my $i = 0; $i < @bags; $i++) {
  # split the bag item
  my ($bag_name, $imgName) = split (/,/, $bags[$i]);

  # create an empty hash if this is a new bag
  $bags_ordered{$bag_name} = {} unless exists $bags_ordered{$bag_name};

  # set the image name
  $bags_ordered{$bag_name}->{image_name} = $imgName;

  # set the quantity. should it be additive with +=?
  $bags_ordered{$bag_name}->{quantity} = $bag_quantity[$i];
}

# print the structure for testing using Data::Dumper
print Dumper \%bags_ordered;


Rob


-Original Message-
From: David Gilden [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 04, 2003 4:57 PM
To: [EMAIL PROTECTED]
Subject: data structures 


I am trying to build a data structure, and am tripping up here.  
any suggestions?
Thx!
Dave

!/usr/bin/perl -w
 snip...
@bags = param('handbag');   get all of the bags styles
@bag_quantity = param('quantity');   get all of the bags quantity 

foreach my $bag (@bags){
($bag_name,$imgName)  =  split (/,/,$bag);
push %bags_ordered,$bag_name;
push %bags_ordered{$bag_name}{image_name} = $imgName;
}

foreach my $q (@bag_quantity){
push %bags_ordered{$bag_name}{$bag_quantity} =$q; 
}


Data structure: 



%bags_ordered = (
"bag-style1" =>   { price => 10,
image_name => 'FIO-142b-small',
 quantity=> 5
   },

"bag-style2" =>   { price => 12,
image_name => 'GUC-208-small',
   quantity=> 5,
   },

);

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



Re: newbie: data structures

2002-07-24 Thread Wiggins d'Anconia

This is a very broad question, so giving a specific answer is difficult 
to say the least, but since no one else has responded I will provide at 
least this much

You are going to want to be looking at using a "hash of hashes" 
essentially you create a hash where each key is the email address (which 
you will be looking up on) and the value associated with that key is 
itself a hash.

Here is one place to start:
http://www.wdvl.com/Authoring/Languages/Perl/PerlfortheWeb/hash_of_hashes.html

Or there are examples of these types of structures in the Camel, 
Advanced Perl Programming, and possibly the other perl related O'Reilly 
books.

Good luck.

http://danconia.org



Anthony E. wrote:
> How would I store (and access) a table of
> information...assuming there is a unique key
> 'email'...ie -
> 
> These are the column names:
> email firstName lastName phone address1
> 
> "[EMAIL PROTECTED]" "Joe Blow" "415-555-" "123
> Mayberry"
> 
> "[EMAIL PROTECTED]"  "John Doe" "619-555-5551" "456 Happy
> Ln."
> 
> etc...etc...
> (also some of the fields will be null from time to
> time).
> 
> 
> 
> __
> Do You Yahoo!?
> Yahoo! Health - Feel better, live better
> http://health.yahoo.com
> 



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




Re: newbie: data structures

2002-07-24 Thread Vikrama Dhiman

ur mail title says data structure but ur problem doe not seem to 
be of the nature.
please be a little more clear.
store and retreive, there are as many options as u want.
what do u exactly r lookign for???
regards
vicki

On Wed, 24 Jul 2002 Anthony E. wrote :
>How would I store (and access) a table of
>information...assuming there is a unique key
>'email'...ie -
>
>These are the column names:
>email firstName lastName phone address1
>
>"[EMAIL PROTECTED]" "Joe Blow" "415-555-" "123
>Mayberry"
>
>"[EMAIL PROTECTED]"  "John Doe" "619-555-5551" "456 Happy
>Ln."
>
>etc...etc...
>(also some of the fields will be null from time to
>time).
>
>
>
>__
>Do You Yahoo!?
>Yahoo! Health - Feel better, live better
>http://health.yahoo.com
>
>--
>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]




RE: data structures / CGI.pm

2003-03-04 Thread David Gilden
Good afternon,

I am not seeing consistent results from my script below. 

It seems that sometimes it works and other times I get '0's in 
the quantity field.

As I don't write PERL often enough this is probably poorly written code!
Thanks for any help.

Dave  


HTML at:


#!/usr/bin/perl -w

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use strict;
my (@bags,@bag_quantity);
my ($bag_name,$imgName);
my (%bags_ordered,%prices);
my $n=0;
my $bags_ordered;
use Data::Dumper; 

# Build data structure 

@bags = param('handbag');  # get all of the bags styles
@bag_quantity = param('quantity');  # get all of the bags quantity 

foreach my $bag (@bags){
($bag_name,$imgName)  =  split (/,/,$bag);
$bags_ordered{$bag_name} = {} unless exists $bags_ordered{$bag_name}; # thanks rob!
$bags_ordered{$bag_name}->{image_name} =$imgName;
$bags_ordered{$bag_name}->{quantity} = $bag_quantity[$n]; 
$n++;
}

## I don't think '->' really needed

# will the order be correct, don think so!

 Prices amounts with out '$' #

%prices = (
'bag-style-dots' => 12,
'bag-style-dogs' =>5,
'bag-style-cats' =>44,
'bag-style-leather' =>15,
'bag-style-fur' =>23,
'bag-style-stripes' =>12,
'bag-style1' =>14,
'bag-style2' =>6,
'bag-style3' =>51,
);


#
#%bags_ordered = (
#"bag-style1" =>   { price => 10,
#   image_name => 'FIO-142b-small',
#quantity=> 5
#  },
#
#"bag-style2" =>   { price => 12,
#   image_name => 'GUC-208-small',
#  quantity=> 5,
#  },
#
#);



print header;
# print HTML
print 


Catalog








 

Complete your order
more text on how complete your order..
START_HTML

[EMAIL PROTECTED] = param();
#foreach my $name (@test){
#my $val = param($name);
#   print qq|\$name $name \$val $val\n|;
# }

print Dumper \%bags_ordered;

print "\n";
 
  
print qq|\n\n|; 
print qq|DescriptionQuantityPrice\n|; 
print  "\n"; 


foreach my $bag (keys %bags_ordered){
print  "\n";
print qq|\n|;
print  "$bag";
print  "$bags_ordered{$bag}{quantity}\$$prices{$bag}\n";
print "\n";
}

print " subtotal\n";
print "  fill in  \n";

print "\n";


#print < 'post' , -action =>"finnish-not done.pl");


exit;

==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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



RE: data structures one more try

2003-03-05 Thread David Gilden
Rob,

Good call!

>  You can print out the data in @bags and @bag_quantity  
>  using Data::Dumper..
>  print Dumper [EMAIL PROTECTED];




Check this out,   'order' second and third bag in the first row.
and hit the CGI and see the results, bizarre!

Thanks for your help,

Regards

Dave
( kora musician / audiophile / web master @ cora connection /  DFW, TX, USA)

and web designer for Afropop Worldwide



==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==
==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

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



RE: data structures one more try

2003-03-05 Thread David Gilden
Rob and all the rest reading this,

Here's what fixed the problem.
The check boxes are only sent to CGI.pm if  checked,
while all the input fields are sent regardless. So @bag_quantity
was filled with '0's  ...
 get rid of 'o's
@bag_quantity = grep(/[^0]/, @bag_quantity);

 ...this now seems to work 


Thanks, 

Dave
( kora musician / audiophile / web master @ cora connection /  DFW, TX, USA)

and web designer for Afropop Worldwide



==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==
 

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