1
2
3
4
open (TMPFILE, ">$TempFile")|| die "Fehler $!";
print TMPFILE Dumper(\%ResultHash);
close TMPFILE;
1
2
3
4
5
6
7
8
9
open (my $fh,'<','AllVMinfos.txt') or die $!;
my $config_neu;
{
$/ = undef;
my $s= <$fh>;
$s=~s|\$VAR1|\$config_neu|;
eval "$s";
}
print Dumper($config_neu);
$VAR1 = {
1
2
3
4
5
6
7
8
9
10
11
$VAR1 = {
\'esx.xxx.org\' => bless( {
\'mo_ref\' => bless( {
\'type\' => \'HostSystem\',
\'value\' => \'host-429\'
}, \'ManagedObjectReference\' ),
\'vm\' => [
bless( {
\'type\' => \'VirtualMachine\',
\'value\' => \'vm-688\'
}, \'ManagedObjectReference\' ),.....
perldoc Data::Dumper
1
2
3
4
5
6
7
8
9
10
11
%main = (
'esx.xxx.org' => bless( {
'summary.config' => bless( {
'name' => 'esx.xxx.org',
'vmotionEnabled' => '1',
'faultToleranceEnabled' => '0',
'port' => '443',
'product' => bless( {
'version' => '5.5.0',
'apiType' => 'HostAgent',
'licenseProductName' => 'VMware ESX Server'.....
index.pl: Global symbol "%main" requires explicit package name at (eval 97) line 1, <$fh> chunk 1.
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
#! /usr/bin/env perl use strict; use warnings; use Data::Dumper; my %data = ( what => [ 1,2,3 ], ever => [ qw( a b c ) ], ); my $file = "/tmp/filename.txt"; ### save %data to file as %name open my $wh, '>', $file or die "open($file,w) failed: $!"; print $wh Data::Dumper->Dump( [ \%data ], [ "*name" ] ); close $wh or die "close($file) failed: $!"; ### read to a lexical variable ### retrieve %name from file (you need to know %name before) open my $rh, '<', $file or die "open($file,r) failed: $!"; my %name; eval do { local $/; <$rh> }; close $rh; print Data::Dumper->Dump( [ \%name ], [ '*name_it' ] );
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
#! /usr/bin/env perl use strict; use warnings; use Data::Dumper; my %data = ( what => [ 1,2,3 ], ever => [ qw( a b c ) ], ); my $file = "/tmp/filename.txt"; # save %data to file as %name open my $wh, '>', $file or die "open($file,w) failed: $!"; print $wh Data::Dumper->Dump( [ \%data ], [ "*name" ] ); print $wh <<MESSAGE; print "Hier schreibt ein Boeser Bube boese Sachen in die Datendatei....\n"; print "Diese prints aus der Datendatei werden ausgefuehrt...\n"; MESSAGE close $wh or die "close($file) failed: $!"; ### B : read to a package variable ### retrieve %name from file (you need to know %name before) our %name; do $file; print Data::Dumper->Dump( [ \%name ], [ '*name_it' ] );
index.pl: Global symbol "%name" requires explicit package name at (eval 97) line 1, <$fh> chunk 1.
1
2
3
4
5
6
7
8
9
10
11
12
my %ResultHash = (
what => [
1,2,3
],
ever => [
qw( a b c )
],
);
# resultview return
open (TMPFILE, ">$TempFile")|| die "Fehler $!";
print TMPFILE Data::Dumper->Dump([\%ResultHash], ['*name']);
close TMPFILE;
1
2
3
4
5
6
open my $rh, '<', $filename or die "open($filename,r) failed: $!";
my %name;
eval do { local $/; <$rh> };
close $rh;
print Data::Dumper->Dump( [ \%name ], [ '*name_it' ] );
%name-it = (
1
2
3
4
5
6
7
8
9
10
11
12
13
14
%name_it = (
'esx.xxx.org' => bless( {
'config' => bless( {
'activeDiagnosticPartition' => bless( {
'diagnosticType' => 'singleHost',
'id' => bless( {
'diskName' => 'mpx.vmhba32:C0:T0:L0',
'partition' => '7'
}, 'HostScsiDiskPartition' ),
'slots' => '1',
'storageType' => 'directAttached'
}, 'HostDiagnosticPartition' ),
.....
QuoteThe return value can be evaled to get back an identical copy of the original reference structure.