Thread Variablennamen anzeigen (18 answers)
Opened by bianca at 2021-05-25 11:23

bianca
 2021-05-26 09:52
#193293 #193293
User since
2009-09-13
6823 articles
BenutzerIn

user image
Vielen Dank!

Aber bitte hilf mir nochmal kurz, es in mein Script einzusetzen, ich scheitere am
Quote
Can't use string ("$test1") as a HASH ref while "strict refs" in use at sub_meldung_machen.pl line 63.


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
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
system 'cls';

my $test1 = ['Birne','Apfel'];
my @test2 = ('Fred','Anna');
my %test3 = (foo => 'bar',abc => 'def');
my $test4 = 'string';
my %uebergabe = (
    liste       => [
        [
            0,
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            'Testtext',
#           [$test1,\@test2,\%test3,\$test4],
            [
                '$test1'    => $test1
            ]
        ]
    ]
);

my $env;

meldung_machen($env,\%uebergabe);

###############################################################################
###############################################################################

sub meldung_machen{
    my ($env,$transp) = @_;


    foreach my $ref (@{$transp->{liste}}) {

        # Text setzen
        my $text = $ref->[9];

        # Dump/-s im Text ergänzen
        if (defined $ref->[10] && ref($ref->[10]) eq 'ARRAY') {

            require Data::Dumper;
            local $Data::Dumper::Useqq;
            $Data::Dumper::Useqq = 1;
            local $Data::Dumper::Sortkeys;
            $Data::Dumper::Sortkeys = sub {
                my ($hash) = @_;
                return [(sort {$a =~ /^\d+$/ && $b =~ /^\d+$/ ? $a <=> $b : lc($a) cmp lc($b)} keys %$hash)];
            };

            foreach my $args (@{$ref->[10]}) {
#say $args;
say "Zeile ".__LINE__.': '.Data::Dumper::Dumper($args);
                my @names = keys %$args;
                my @refs  = values %$args;
                my $dump = Data::Dumper::Dump(\@refs,\@names);
                $dump =~ s/&/&amp;/g;
                $dump =~ s/</&lt;/g;
                $dump =~ s/>/&gt;/g;
                $dump =~ s/\n/<br>/g;
                $text .= "<br><br>Dump von xxx:\n<pre>$dump</pre>";
            }
        }

say $text;

    }

}
10 print "Hallo"
20 goto 10

View full thread Variablennamen anzeigen