Guenther Sohler said:
I'd like to code a little bit more complicated construct, but I dont get
it done
Suppose i have following
my %database;
$database{"fruits"}=("Apple","Pear");
That doesn't do what you think it's doing - a scalar variable
($database{fruits}) cannot hold an array, but it can hold a
reference to an array:
$database{fruits] = [ 'Apple', 'Pear' ];
In your version of the code $database{fruits} ends up with the single
value "Pear".
You have no variable called $database - you have %database.
add_fruits(\%database);
If you had used the warnings and strict pragmas, perl would have told
you this.
sub add_fruits(my $databaseptr)
This is not how you pass parameters to Perl subroutines. Why did you
think it was?
sub add_fruits {
my ($databaseptr) = @_;
{
push databaseptr .. fruits "Banana";
That isn't even vaguely Perl - I don't know why you thought that line
might work.
}
I dont get the proper characters. Perl always complains.
When perl "complains", did you not think the content of the complaint
would provide us with useful information?
String found where operator expected at /tmp/y line 8, near "fruits
"Banana""
(Do you need to predeclare fruits?)
syntax error at /tmp/y line 8, near "fruits "Banana""
Execution of /tmp/y aborted due to compilation errors.
And that is beacuse line 8, as I said above, isn't even vaguely Perl.
Can anybody point me out ?
You never stated what it is you are trying to achieve, but I'm
guessing you want to do something like this:
#!/usr/bin/perl
use strict;
use warnings;
my %database;
$database{fruits} = [ 'Apple', 'Pear' ];
add_fruits(\%database);
use Data:

umper;
print Dumper \%database;
sub add_fruits {
my ($db_ref) = @_;
push @{ $db_ref->{fruits} }, 'Banana';
}