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

bianca
 2021-05-25 11:23
#193284 #193284
User since
2009-09-13
6823 articles
BenutzerIn

user image
Morgen!

Folgender Code:
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
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;

my $test1 = ['Birne','Apfel'];
my @test2 = ('Fred','Anna');
my %test3 = (foo => 'bar',abc => 'def');
my $test4 = 'string';
my $ref = [
    0,
    1,
    2,
    [$test1,\@test2,\%test3,\$test4],
];

if (defined $ref->[3]) {

    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 $keyref (@{$ref->[3]}) {
        say Data::Dumper::Dumper($keyref);
    }
}


Kommt raus:
Quote
$VAR1 = [
"Birne",
"Apfel"
];

$VAR1 = [
"Fred",
"Anna"
];

$VAR1 = {
"abc" => "def",
"foo" => "bar"
};

$VAR1 = \"string";


Was muss ich machen, um ohne ein zusätzliches Modul die Variablennahmen anzuzeigen?

Das soll rauskommen:
Quote
@$test1 = [
"Birne",
"Apfel"
];

@test2 = [
"Fred",
"Anna"
];

%$test3 = {
"abc" => "def",
"foo" => "bar"
};

$test4 = \"string";

Vielen Dank
10 print "Hallo"
20 goto 10

View full thread Variablennamen anzeigen