in reply to Re^6: Data::Dumper is returning empty
in thread Data::Dumper is returning empty

what does fixed in grandparent mean?

Replies are listed 'Best First'.
Re^8: Data::Dumper is returning empty
by ikegami (Patriarch) on Jan 19, 2010 at 20:21 UTC

      ikegami You have been wonderful. This code is so much closer to being finished with your help and the help of the cb. So far, I am making your suggested changes and everytime I do I fall back to a previous issue which is my fault for missing something. Often I fall back into a scoping issue.

      At the moment I am having the following error:

      cccadm@ccasec1::perl: ./sec-test.pl Global symbol "%nic" requires explicit package name at ./sec-test.pl line 147. Execution of ./sec-test.pl aborted due to compilation errors (#1) (F) You've said "use strict vars", which indicates that all variables must either be lexically scoped (using "my"), declared beforehand using "our", or explicitly qualified to say which package the global variable is in (using "::"). Uncaught exception from user code: Global symbol "%nic" requires explicit package name at ./sec-test.pl line 147. Execution of ./sec-test.pl aborted due to compilation errors. at ./sec-test.pl line 195

      I am not sure if you saw my up post but I have updated my my scratchpad with the full script so you can see all the progress so far.

        Already covered

        for my $nic (networkInfo()) { print "Device: $nic->{device} has IP Address $nic->{ip}\n" . "\tMask: $nic->{mask}\n" . "\tBroadcast: $nic->{bcast}\n"; print "Device: $nic->{device} also IPv6 address $nic->{ip6}\n" if defined($nic->{device}); }
        I've been playing with this. It still needs work, but it works:
        #!/usr/bin/perl use strict; use warnings; use File::Find qw(find); use IO::Interface::Simple; use POSIX qw(uname); use Data::Dumper; deleteBak(); my $opsys = getOperatingSystem(); my $platform = getPlatform($opsys); my $hostname = getHostname(); my $input; my ($uname_s, $uname_r) = (POSIX::uname())[0,2]; print ">>> $uname_s\n", ">>> $uname_r\n", ">>> Hostname: $hostname\n", ">>> Perl $]\n", ">>> $0\n"; my @interfaces = IO::Interface::Simple->interfaces; for my $if (@interfaces) { print Dumper "interface = $if\n"; print Dumper "addr = ",$if->address,"\n", "broadcast = ",$if->broadcast,"\n", "netmask = ",$if->netmask,"\n"; print Dumper "is running\n" if $if->is_running; print Dumper "is broadcast\n" if $if->is_broadcast; print Dumper "is p-to-p\n", if $if->is_pt2pt; print Dumper "is loopback\n" if $if->is_loopback; print Dumper "is promiscuous\n" if $if->is_promiscuous,; print Dumper "is multicast\n" if $if->is_multicast; print Dumper "is notrailers\n" if $if->is_notrailers; print Dumper "is noarp\n" if $if->is_noarp; } ###################################################################### # SUBROUTINES # ###################################################################### sub getOperatingSystem { my ($os) = $^O; return $os; } sub getPlatform { my $opsys_in = $^O; my $pform; if ($opsys_in =~ /linux/) { my $infilename = '/etc/issue'; { my($file, $var1, $var2); die "Could not open $infilename for reading: $!\n" unless open my $ifh, '<', $infilename; local $/; #undef the input rec sepe +rator (newline), slurp file into a scalar $file = <$ifh>; close $ifh; if( $file =~ /^(Red)(Hat)/) { next unless ($var1, $var2) = ($1, $2); $pform = "$var1$var2"; print "$var1$var2\n"; last; } elsif ($file =~ /\bWelcome to ([\w.]+)/) { next unless ($var1) = $1; $pform = "$var1"; print "$var1\n"; last; } else { print "No Matches\n"; } } } elsif ($opsys_in =~ /solaris/) { die "[`uname -a`] in getPlatform Failed: $!"; my @input = split (/\s/, $input) unless my($input) = `uname -a`; @input = split(/\s/, $input, 0); $pform = $input[0]; print "$pform\n"; } return $pform; } sub getHostname { die "[uname -a| in gethostname Failed: $!" unless my $host = `uname -a`; my(@host) = split(/\s/, $host, 0); return $host[1]; } sub deleteBak { my $searchdir = '/emc/cccadm/scripts/perl/etc-test'; print "Are you sure you would like to delete all *.bak files that + exist in: $searchdir [yes/no] "; chomp(my $answer = lc(<STDIN>)); if ($answer ne 'y' & $answer ne 'yes') { print "You did not enter [y] or [yes]. Exiting program.\n"; exit; } my(@bak) = find_bak_files($searchdir); if (not @bak) { warn "No files were found\n"; } foreach $_ (@bak) { warn "Can't delete $_: $!\n" unless unlink $_; print "Deleting $_\n"; } } sub find_bak_files { my ($dir) = @_; my @bak; find(sub { push @bak, $File::Find::name if /\.bak\z/ and -f $_;}, $dir); return @bak; } sub networkInfo { my @nics; my %nic; my $platform = $^O; $platform = getPlatform(); if ([$platform =~ /Red Hat/]) { die("Can't get info from Linux ifconfig: $!\n") unless my $ifconfig = `/sbin/ifconfig`; for(split(/(?<=\n)(?=\w)/, $ifconfig, 0)) { my %nic; next unless ($nic{'device'}) = /^(eth\d)\s/; if (/\binet addr:([\d.]+)\s.+?:([\d.]+)\s.+?:([\d.]+)/) { $nic{'ip'} = $1; $nic{'bcast'} = $2; $nic{'mask'} = $3; print "Device: $nic{device} has the IP Address of $nic +{'ip'}\n\tMask: $nic{'mask'}\n\tBroadcast: $nic{'bcast'}\n"; } if (/^\s+ inet6 addr:\s*(\S+)/m) { $nic{'ip6'} = $1; print "Device: $nic{'device'} also has IPv6 address of + $nic{'ip6'}\n"; } push @nics, \%nic; } } elsif ($platform =~ /SunOS/) { die "Can't get info from Solaris ifconfig: $!\n" unless my $ifconfig = `/sbin/ifconfig -a`; foreach $platform (split(/(?<=\n)(?=\w)/, $ifconfig, 0)) { my %nic; next unless ($nic{device}) = $_ =~ /^(fjgi\d)\s/; if (/\binet addr:([\d.]+)\s.+?:([\d.]+)\s.+?:([\d.]+)/) { $nic{'ip'} = $1; $nic{'bcast'} = $2; $nic{'mask'} = $3; print "Device: $nic{'device'} has the IP Address of $n +ic{'ip'}\n\tMask: $nic{'mask'}\n\tBroadcast: $nic{bcast}\n"; } if (/^\s+ inet6 addr:\s*(\S+)/m) { $nic{'ip6'} = $1; print "Device: $nic{'device'} also has IPv6 address of + $nic{'ip6'}\n"; } push @nics, \%nic; } } return @nics, \%nic; }
        Update: I've looking for a clean way to find the name of the platform. I tried ProjectBuilder. Specifically, see the bin folder for pbdistrocheck. To download it, do cpan ProjectBuilder::Conf.