RE: hash of hash of array slices

2004-01-26 Thread Charles K. Clarkson
Paul Kraus [EMAIL PROTECTED] wrote:
: 
: This works 
: 
: Foreach ( @{$hash{$key1}{$key2}} )
: 
: This does note
: 
: Foreach ( @{($hash{$key1}{$key2})[9..1]} )
: 
: This gives me this error 
: Can't use undefined value as an array reference.
: 


 foreach ( reverse @{ $hash{$key1}{$key2} }[ 1 .. 9 ] ) {


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: hash of hash of array slices

2004-01-26 Thread Paul Kraus
 Paul Kraus [EMAIL PROTECTED] wrote:
 :
 : This works
 :
 : Foreach ( @{$hash{$key1}{$key2}} )
 :
 : This does note
 :
 : Foreach ( @{($hash{$key1}{$key2})[9..1]} )
 :
 : This gives me this error 
 : Can't use undefined value as an array reference.
 :
 
 
  foreach ( reverse @{ $hash{$key1}{$key2} }[ 1 .. 9 ] ) {
That was a typo should have read [ 1..10]

And the code doesn't work.
H


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash of hash of array slices

2004-01-26 Thread Jeff 'japhy' Pinyan
On Jan 26, Paul Kraus said:

foreach ( @{($hash{$key1}{$key2})[9..1]} )

It should be:

  foreach ( @{ $hash{$key1}{$key2} }[1 .. 10] ) { ... }

based on your other email.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: hash of hash of array slices

2004-01-26 Thread Paul Kraus
 -Original Message-
 From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]
 Sent: Monday, January 26, 2004 12:10 PM
 To: Paul Kraus
 Cc: 'Perl Beginners'
 Subject: Re: hash of hash of array slices
 
 On Jan 26, Paul Kraus said:
 
 foreach ( @{($hash{$key1}{$key2})[9..1]} )
 
 It should be:
 
   foreach ( @{ $hash{$key1}{$key2} }[1 .. 10] ) { ... }
 
 based on your other email.


This worked fine. However I was under the impression that any time you
worked with a slice that you had to surround the array in parenthesis.

When else does this not apply?



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: hash of hash of array slices

2004-01-26 Thread Charles K. Clarkson
: -Original Message-
: From: Paul Kraus [mailto:[EMAIL PROTECTED] 
: Sent: Monday, January 26, 2004 10:52 AM
: To: 'Charles K. Clarkson'; 'Perl Beginners'
: Subject: RE: hash of hash of array slices
: 
: 
:  Paul Kraus [EMAIL PROTECTED] wrote:
:  :
:  : This works
:  :
:  : Foreach ( @{$hash{$key1}{$key2}} )
:  :
:  : This does note
:  :
:  : Foreach ( @{($hash{$key1}{$key2})[9..1]} )
:  :
:  : This gives me this error 
:  : Can't use undefined value as an array reference.
:  :
:  
:  
:   foreach ( reverse @{ $hash{$key1}{$key2} }[ 1 .. 9 ] ) {
: That was a typo should have read [ 1..10]
: 
: And the code doesn't work.

Worked for me:

my( $key1, $key2 ) = qw| foo bar |;

my %hash;
$hash{$key1}{$key2} = [ 0 .. 20 ];

foreach ( reverse @{ $hash{$key1}{$key2} }[ 1 .. 9 ] ) {
print $_\n;
}

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: hash of hash of array slices

2004-01-26 Thread Tim Johnson

I think that only applies to a list slice, i.e. (split /\s+,$_)[3..9],
but an array slice doesn't need it, i.e. @array[2]

-Original Message-
From: Paul Kraus [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 26, 2004 9:38 AM
To: [EMAIL PROTECTED]
Cc: 'Perl Beginners'
Subject: RE: hash of hash of array slices


This worked fine. However I was under the impression that any time you
worked with a slice that you had to surround the array in parenthesis.

When else does this not apply?



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Hash of hash of array

2002-01-09 Thread Jon Molin

Ahmed Moustafa wrote:
 
 Hi All,
 
 My data structure is a hash of a hash of an array. I build it from an
 input file by the following code. Could you help me write it back to an
 output file, please?
 
 # Code Begins
 %data = ( );
 open (IN, in.txt) || die;
 while (IN) {
   chop;
   ($user_name, $file_name, $modified_by, $last_modified) = split (  ,
 $_ );
   $data{$user_name}{$file_name} = [$modified_by, $last_modified];
 }
 close (IN);
 # Code Ends
 

the hash hasn't got arrays but arrayrefs in it, here are some ways to
reach the values:

my $scalar = $data{user}{file1}-[0]; # get value 0 in the file1 array
my @array = @{$data{user}{file1}}; # dereferens the array and put it in
@array
my $array_ptr = $data{user}{file1}; # get the arrayref and reach the
values by $array_ptr-[nbr]

/Jon


 Thanks a lot for your attention. Your help will be appreciated so much.
 
 Ahmed
 
 --
 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: Hash of hash of array

2002-01-09 Thread Ahmed Moustafa

Jon,thanks a lot for your help :)

Jon Molin wrote:

 Ahmed Moustafa wrote:
 
Hi All,

My data structure is a hash of a hash of an array. I build it from an
input file by the following code. Could you help me write it back to an
output file, please?

# Code Begins
%data = ( );
open (IN, in.txt) || die;
while (IN) {
  chop;
  ($user_name, $file_name, $modified_by, $last_modified) = split (  ,
$_ );
  $data{$user_name}{$file_name} = [$modified_by, $last_modified];
}
close (IN);
# Code Ends


 
 the hash hasn't got arrays but arrayrefs in it, here are some ways to
 reach the values:
 
 my $scalar = $data{user}{file1}-[0]; # get value 0 in the file1 array
 my @array = @{$data{user}{file1}}; # dereferens the array and put it in
 @array
 my $array_ptr = $data{user}{file1}; # get the arrayref and reach the
 values by $array_ptr-[nbr]
 
 /Jon
 
 
 
Thanks a lot for your attention. Your help will be appreciated so much.

Ahmed

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