in reply to Re: Uninitialized value from hostname()
in thread Uninitialized value from hostname()

I also find your usage of 'our' to be quite strange.
I'm new to Perl, so I'm sure some of it is going to look "strange" :)

Thank you for the rewrite. I'm still having difficulty understanding our, my, and local. If I change it from 'our' to 'my', how do I properly "access" $localip from within nested IF/ELSE and WHILE? That in a nutshell is my biggest challenge with Perl currently, is watching the warnings and errors complain about my syntax for using variables.

Verifying whether this has worked or not will take some time. This script is running out in the field, and I would need to wait for another network event to see what happens. Under normal conditions I have no warnings or errors returned from running the script. It also runs on many other systems and returns no errors or warnings at all. Since it's all logged I can verify what occurs on the other systems and that the script is working.

  • Comment on Re^2: Uninitialized value from hostname()

Replies are listed 'Best First'.
Re^3: Uninitialized value from hostname()
by Monk::Thomas (Friar) on Oct 14, 2016 at 08:19 UTC
    long answer: Variable Scoping in Perl: the basics

    short answer:
    • forget about 'our' and 'local' (for now)
    • identify the relevant blocks (= something enclosed in '{ }')
    • if you need the variable outside of the block, define it outside

    minimalistic example to set a value inside a conditional / loop / block:
    (I intentionally used the variable '$value' inside the block to demonstrate 'my'. It is not mandatory, you can also assign directly.)
    my $variable; if (1 == 1) { my $value = 'a'; $variable = $value; } else { my $value = 'b'; $variable = $value; } # => '$variable' now contains 'a'