Thread Umfangreiche Hash Referenz mit Regex und Code kopieren (20 answers)
Opened by bianca at 2016-02-26 09:38

FIFO
 2016-02-26 18:57
#183996 #183996
User since
2005-06-01
469 Artikel
BenutzerIn

user image
Naja, wie schon gesagt: use Clone:

ohne (Referenzkopie):
Code (perl): (dl )
1
2
3
4
5
6
7
8
my $alt = {
    code => sub{ printf "alt %s\n", shift }
};

my $neu = $alt;
$alt->{code} = sub { printf "neu %s\n", shift };

$neu->{code}->('Hallo Welt'); # "neu Hallo Welt"


mit (deep copy):
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
use Clone "clone";

my $alt = {
    code => sub{ printf "alt %s\n", shift }
};

# my $neu = $alt;
my $neu = clone $alt;
$alt->{code} = sub { printf "neu %s\n", shift };

$neu->{code}->('Hallo Welt'); # "alt Hallo Welt"
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? -- Brian Kernighan: "The Elements of Programming Style"

View full thread Umfangreiche Hash Referenz mit Regex und Code kopieren