in reply to passing information into a hash

I think you want something like:
$unsubscribe{$address} = [@dbase_array];
Also, you really out to check out Data::Dumper for quick and dirty printing out of datastructures:
use Data::Dumper; use CGI qw(:standard); my %unsubscribe; foreach my $address (@dbs) { open (DAT,'<',"$memberinfo/$address") or die "can't open $address: +$!\n"; my @dbase_array = <DAT>; print pre("dbase_array = ", Dumper \@dbase_array); print "address = $address", br(); close(DAT); $unsubscribe{$address} = [@dbase_array]; print pre("hash = ", Dumper \%unsubscribe); }
And don't forget to use strict and warnings as well.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: Re: passing information into a hash
by hmerrill (Friar) on Sep 29, 2003 at 14:50 UTC
    I have a question about this line
    $unsubscribe{$address} = [@dbase_array];
    I guess I'm wondering if that is the same as this:
    $unsubscribe{$address} = \@dbase_array;
    technically?? Both create a reference to the array, but do they both accomplish the same exact thing? Or are they somehow different?
      Good question. :) For this particular case, i probably should have used your second snippet (take a reference to the array instead of copying it into a new anonymous one). Consider these:
      use Data::Dumper; my @array = qw(foo bar baz); my %hash; for (1..5) { my @array = qw(foo bar baz); $hash{$_} = \@array; undef @array; } print Dumper \%hash; for (1..5) { my @array = qw(foo bar baz); $hash{$_} = [@array]; undef @array; } print Dumper \%hash;
      I usually stick with an explicit copy since it tends to keep me out of trouble, but there are times when you do want to take a reference, and you just have to be careful when you do.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
        I want to be clear about this - I don't quite understand yet. Does @array copy the array and then create an anonymous reference to the new array? Or does it just create a new reference to the existing @array? TIA.
Re: Re: passing information into a hash
by Anonymous Monk on Sep 29, 2003 at 14:40 UTC
    That worked perfectly, and I thank you for it.