Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

wie bekommt man ein hash und ein array an ein sub uebergeben?

23 views
Skip to first unread message

Astrid

unread,
Jan 25, 2017, 12:31:25 AM1/25/17
to
Hallo!

Ein Skalar und ein Hash an ein Unterprogramm
zu uebergeben habe ich hingekommen.

Aber wie kann ich ein Hash und ein Array an
ein Unterprogramm in Perl uebergeben?

Das Array ist dabei der Input fuer das
Unterprogramm, der Hash der Output des
Unterprogrammes.

Gruss, Astrid

Megalodon

unread,
Jan 25, 2017, 6:57:11 AM1/25/17
to
Hallo, Astrid!

Ich nehme an du meinst mit Unterprogram eine Funktion. Am besten du übergibst Pointer. Das sind scalare die nur die Addresse auf einen Speicherbereich beinhalten (grob gesagt).
Wie das aussehen kann soll folgendes Program zeigen:

use strict;
use warnings;

use feature qw/say/;

my $hash = {};

my $array = [
'maeh',
'naja',
'top',
];

$hash = do_what($hash, $array);

for my $hash_key (keys %{$hash}) {
say "Key: $hash_key Value: " . $hash->{$hash_key};
}

sub do_what {
my ($hash, $array) = @_;

for my $item (@$array) {
$hash->{$item} = 1;
}

return $hash;
}

Grüße
Wolfgang
0 new messages