Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Cisco to Juniper - parser help

by jwkrahn (Abbot)
on May 25, 2021 at 06:33 UTC ( [id://11133003]=note: print w/replies, xml ) Need Help??


in reply to Cisco to Juniper - parser help

A major problem with your code are these lines:

if ($neighbor eq undef){} elsif ($vcid eq undef) {} else {

undef can NOT be used in a comparison, you have to use the defined function to determine if a variable is defined or not.

You also don't need the if/elsif/else structure:

if ( !defined $neighbor && !defined $vcid ) {

Another problem is a lot of "uninitialized value" messages which can be fixed by initializing all your variables.

my $vcid; my $tag; my @splittag; my $pop; my $xcon; my $cos; my @splitcos; # change those to: my $vcid = ''; my $tag = ''; my @splittag; my $pop = ''; my $xcon = ''; my $cos = ''; my @splitcos;
$unit = $splitunit[2]; # change to: $unit = $splitunit[2] || '';
$vlanida = $splitvlan[2]; $vlanidb = $splitvlan[4]; # change to: $vlanida = $splitvlan[2] || ''; $vlanidb = $splitvlan[4] || '';
$cos = $splitcos[2]; # change to: $cos = $splitcos[2];
$neighbor = $splitxc[1]; $vcid = $splitxc[2]; # change to: $neighbor = $splitxc[1] || ''; $vcid = $splitxc[2] || '';
$pop = $splittag[4]; # change to: $pop = $splittag[4] || '';
if ($neighbor eq undef){} elsif ($vcid eq undef) {} else { # change to: if ( length $neighbor && length $vcid ) {

Try running your code with those changes and post again with your feedback.

Replies are listed 'Best First'.
Re^2: Cisco to Juniper - parser help
by GrandFather (Saint) on May 25, 2021 at 07:05 UTC

    A large block of global vars set to some arbitrary initial value is a code smell, nay, a code stink. With a cursory glance at the code it seems likely that the warnings are really and truly saying something important about the logic of the code. I would remove all the global variables then put them back in the smallest scope that makes sense, ideally initializing the variables where they are declared with an appropriate value rather than just any old value to shut up the warnings.

    If the code logic dictates that the variables are populated piecemeal during multiple passes through the loop I'd either add code to handle unexpectedly unpopulated values or fix the logic errors as appropriate. In either case just shutting up the warnings is stinky coding.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133003]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-29 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found