> >>>Anders Stegmann 02/06/06 1:02 pm >>>
>
> Thaks for replying!
>
> The hash has only one key, so it sould be okay.
> I get the output:
>
> Can't use string (ARRAY(0x648290)) as an ARRAY ref while strict refs in
> use at testhash6.pl line 8.
>
> When I run the script.
>
> It seems like I am somehow dealing with a reference to an array!? Or
> what?


Hi Anders

It's not easy to find a line 8 with a try to derefence an array in your 
script :-)

Yes, the error tells you that something that has been an arrayref once is used 
as a string and tried to be derefenced.

You use an arrayref (on the right side) in the line

>$hash{$key1} = [$en, $to, $tre];

You can have a look at this data structure (and any other you like) with 
Data::Dumper, by putting code like below into your script:

use Data::Dumper;
warn Dumper \%hash;

The error occurs because of your line

>print $dbm_hash{$key}[2];

It seems that nested structures are not supported in the *dbm implementation, 
since at the beginning of your code it's possible to

print $hash{$key1}[2];

resulting in 'nul'.

I did not go further into the docs, and won't, and have never used dbmopen. 

It's deprecated. I think as a beginner you should not use deprecated things. 
Please read

perldoc -f dbmopen

and follow the advice there :-)

hth, joe



[top post history:]
> >>>John Doe <[EMAIL PROTECTED]> 02/06/06 12:55 pm >>>
>
> Anders Stegmann am Montag, 6. Februar 2006 12.30:
> >Hi!
>
> Hi Anders
>
> >Can anyone tell me why this script doesn't work?
> >
> >
> >use strict;
> >use warnings;
> >
> >my %hash = ();
> >
> >my $key1 = 'nul';
> >my $en = 'en';
> >my $to = 'to';
> >my $tre = 'tre';
> >
> >
> >$hash{$key1} = [$en, $to, $tre];
> >
> >dbmopen(my %dbm_result_hash, 'hash_database', 0666) or die cannot save
> >database_name to dbm\n;
>
> No quotes around the string after die. This is a syntax error.
>
> >%dbm_result_hash = %hash;
> >
> >dbmclose(%dbm_result_hash);
> >
> >dbmopen(my %dbm_hash, 'hash_database', 0666);
> >
> >my ($key) = keys %dbm_hash;
>
> Not shure if this is intended. $key contains the first key of the list
> of
> keys from %dbm_hash, which itself has not a specific order.
>
> >print $dbm_hash{$key}[2],\n;
> >
> >dbmclose(%dbm_hash);
> >
> >exit;
>
> No need for an exit at the end of a script.
>
> btw, from
>
> perldoc -f dbmopen:
>
> dbmopen HASH,DBNAME,MASK
>               [This function has been largely superseded by the tie
> function.]
>
>
> hth,
> joe
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>

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


Reply via email to