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

I am getting an error when I try to run this code. It says

Search pattern not terminated at ./sec-test.pl line 166 (#1) (F) The lexer couldn't find the final delimiter of a // or m{} construct. Remember that bracketing delimiters count nesting level. Missing the leading $ from a variable $m may cause this error. Note that since Perl 5.9.0 a // can also be the defined-or construct, not just the empty search pattern. Therefore code written in Perl 5.9.0 or later that uses the // as the defined-or can be misparsed by pre-5.9.0 Perls as a non-terminated search pattern. Uncaught exception from user code: Search pattern not terminated at ./sec-test.pl line 166. at ./sec-test.pl line 166

line 166 is the map $_//'[undef]', line

Also how would I return to main so I could run the following code section, or code similar to what I have below?

my %nicdata = networkInfo($platform); for (@nicdata) { print "Device: $nic{device} has the IP Address of $nic{ip}\n\tMask +: $nic{mask}\n\tBroadcast: $nic{bcast}\n"; print "Device: $nic{device} also has IPv6 address of $nic{ip6}\n"; }

Replies are listed 'Best First'.
Re^4: Data::Dumper is returning empty
by ikegami (Patriarch) on Jan 19, 2010 at 19:30 UTC
    Sorry, I used a 5.10 construct. Change
    map $_ // '[undef]'
    to
    map defined($_) ? $_ : '[undef]'

    Update:

    Concerning the code you posted, you introduced numerous errors:

    • You're assigning a list of nicdata to a hash.
    • Your hash is named nicdata, but it does contains the data about multiple nics.
    • You use @nicdata without ever placing any information in it.
    • Your array is named nicdata, but it's suppose to contain the data about multiple nics.
    • You use %nic without ever placing any information in ti.
    • You pass $platform as an argument as though it can change.
    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}); }

      Using the following code gives a different error about scoping

      Global symbol "%nic" requires explicit package name

      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}); }
        Copy and paste error on my part. The hash is accessed via the ref in $nic, so $nic needs to be derefed. Fixed in grandparent.

      Much closer. I had to add a comma to end of that line. Now when it runs I get use of uninitialized value in pattern match (m//) lline 55 and 127 error.

      Are you sure you would like to delete all *.bak files that exist in: /emc/cccadm/scripts/perl/etc-test yes/no yes No files were found >>> Oper Sys: linux >>> Platform: RedHat >>> Hostname: ccasec1.centera.lab.emc.com Use of uninitialized value in pattern match (m//) at ./sec-test.pl line 55 (#1) (W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl tells you what operation you used the undefined value in. Note, however, that perl optimizes your program and the operation displayed in the warning may not necessarily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer to the concatenation (.) operator, even though there is no . in your program. Use of uninitialized value in pattern match (m//) at ./sec-test.pl line 127 (#1)

        The posted code doesn't have nearly that many lines.