リファレンス

                             <p>ソースコード</p>
 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
29
30
31
32
33
34
35
#!/usr/bin/perl

#BEGIN{
#   print "Content-type: text/plainnn";
#   open(STDERR, ">&amp;STDOUT");
#   $|=1;
#}

%h = (
    'num1'    => 1,
    'num2'    => 2,
);

@a = (1,2);

$hash = %h;
$array = @a;

print <<EOM;
Content-type: text/plain

$h{num1} = $h{num1}

$$hash{num1} = $$hash{num1}
%$hash{num1} = %$hash{num1}
$hash->{num1} = $hash->{num1}

$a[0] = $a[0]
@a[0] = @a[0]

$$array[0] = $$array[0]
@$array[0]  = @$array[0]
$array->[0] = $array->[0]

EOM
 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl

BEGIN{
    print "Content-type: text/plainnn";
    open(STDERR, ">&amp;STDOUT");
    $|=1;
}

use Benchmark;

$count  = 1000;
$cnt    = 100;
$dat1   = "reftest1.txt";
$dat2   = "reftest2.txt";

srand;
for(0 .. $cnt){
    @nums[$_] = rand;
}

open(OUT, "> $dat1");
close(OUT);
open(OUT, "> $dat2");
close(OUT);

sleep 1;

@t = timethese($count, {
    'Refuse'  =>   '&amp;use_ref;',
    'RefNouse'    =>   '&amp;nouse_ref;',
});

exit(0);

sub use_ref{
    my $r_nums;
    $r_nums = @nums;
    open(OUT, ">> $dat1");
    foreach(@$r_nums){
        print OUT "$_n";
    }
    close(OUT);
}

sub nouse_ref{
    my @n_nums;
    @n_nums = @nums;
    open(OUT, ">> $dat2");
    foreach(@n_nums){
        print OUT "$_n";
    }
    close(OUT);
}
                          </div>

Comments

comments powered by Disqus