Thread Korrekter Code? (7 answers)
Opened by bianca at 2011-04-09 20:28

rosti
 2011-04-09 21:31
#147520 #147520
User since
2011-03-19
3211 Artikel
BenutzerIn
[Homepage]
user image
Warts ab, wenn Du später komplexere Strukturen mit hashes und Arrays und Scalaren innendrinne hast, wirst Du auch ohne Fehlermeldung Dein Blaues Wunder erleben, guck mal:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use warnings;
use strict;
use Data::Dump qw(dump);


my %h = (
        1 => {
                1 => 'foo',
                2 => 'bar',
        },
        2 => [],
        3 => 'foo',
);

clear(\%h);

sub clear{
        my $ref = shift;
        %$ref->{1} = ();   # { 1 => undef, 2 => [], 3 => "foo" }
        %{$ref->{1}} = (); # { 1 => {}, 2 => [], 3 => "foo" }
}

print dump \%h; 


.. und nicht mal ne Warnung! Also immer schön cast'en, was gemeint ist.

Rolf
Last edited: 2011-04-09 21:34:27 +0200 (CEST)

View full thread Korrekter Code?