Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you pull out a hash array using struct? 1

Status
Not open for further replies.

cdlvj

MIS
Nov 18, 2003
676
0
0
US
list is a hash array. Debug shows

Code:
$list = {
          "seconds" => "12,2",
          "hour" => "8,2",
          "minute" => "10,2",
          "month" => "4,2",
          "day" => "6,2",
          "year" => "0,4"
        };


Code:
use Class::Struct;
struct ftpdata => {
	mask           => '$',
	maskDate       => '$',
	list           => '%',
	fileInput      => '$'
};
	
sub Load 
{
	my $f = ftpdata->new();
	$f->list("year","0,4");
	$f->list("month","4,2");
	$f->list("day","6,2");
	$f->list("hour","8,2");
	$f->list("minute","10,2");
	$f->list("seconds","12,2");
}



#####################################################
# Purpose: Method to translate input according to mask 
#####################################################
#   
sub translate 
{
   my $list = $f->list;
   my $key;
   my $value;
[b] bombs here what is the each(???) to get at list[/b]
   while (($key,$value) = each($list))
   {
	   print $key . "-" . $value;
   }
}
 
Hi,

(($key,$value) = each($list))

"each" is returning a scalar which you're trying to interprest as an array with "($key,$value)"

you really only need to get back the value of $key, have a look at the 'keys' function - useful for just that.

Mike

When working on any project the value of other people is exactly that - they are other people, with views that don't necessarily match yours. This mismatch, between their views and the view you've been contentedly assuming is right, is where that value lies.
 
$list looks like a reference to a hash, so you have to dereference it to use the each() function:

Code:
while (($key,$value) = each([b]%{$list}[/b]))

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top