Thread Eine Referenz auf einen String anlegen, den ich: aber dann verändern kann (25 answers)
Opened by steffenw at 2004-06-16 17:15

havi
 2004-06-17 11:19
#83400 #83400
User since
2003-08-04
2036 Artikel
BenutzerIn
[Homepage]
user image
[quote=steffenw,16.06.2004, 15:15]das geht nicht, weil '' eine Konstante ist:
Code: (dl )
1
2
my $result = \'';
$$result .= 'text';

so funktioniert es:
Code: (dl )
1
2
3
4
5
my $result;
{ my $value = '';
 $result = \$value;
}
$$result .= 'text';
 
das funktioniert nicht:
Code: (dl )
1
2
3
my $result = '';
$result = \$result;
$$result .= 'text';

Nun, wie schreibe ich so etwas? Variante 2 ist mir zu lang.[/quote]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl

use warnings;
use strict;

my $scalar = 'EINS';
my @array = qw(eins zwei drei);
my %hash = ('eins' => '1', 'zwei' => '2');

test_sub(\$scalar,\@array,\%hash);

sub test_sub {

my $scalarref = shift;
my $arrayref = shift;
my $hashref = shift;

print 'SCALARREF....', $$scalarref.'HALLO', "\n";
print 'ARRAYREF.....', @$arrayref, "\n";
print 'ARRAYREF_1...', $$arrayref[0], "\n";
print 'ARRAYREF_1...', ${$arrayref}[0], "\n";
print 'ARRAYREF_1...', $arrayref->[0], "\n";
print 'HASHREF......', keys %$hashref, "\n";
print 'HASHREF_1....', $$hashref{'zwei'}, "\n";
print 'HASHREF_1....', ${$hashref}{'zwei'}, "\n";
print 'HASHREF_1....', $hashref->{'zwei'}, "\n";

} # test_sub


Gruss

View full thread Eine Referenz auf einen String anlegen, den ich: aber dann verändern kann