in reply to Getting data from Cisco Call Manager with Perl

Hi! There are a great many things you can improve in the Perl code here.

  1. Please always use strict and warnings. These are there to help you find your errors.
  2. Always declare variables with 'my'. There are a few here that you forgot to declare
  3. When parsing CSV files, use the module for this: Text::CSV. It is much better at parsing CSV files than the naive split approach.
  4. Calling functions with & is bad practice for the vast majority of cases. That's mostly a hold-over from Perl 4 days. While there are cases where it's proper, it's not proper anywhere you've done it. Call functions simply with parens: some_function()
  5. When passing variables to a function, there's no need to surround those variables with quotes. call_func("string", $string)
  6. Do not use BAREWORD file handles.

Since I don't have your module SNMP_util and I can't really test things, I won't try to rewrite your entire script, but here's a good starting point:

#!/usr/bin/env perl use strict; use warnings; use NetAddr::IP; use SNMP_util; use Text::CSV (); my $csv = Text::CSV->new({binary => 1}) or die "Can't use Text::CSV: ".Text::CSV->error_diag(); open my $fh, "<:encoding(utf8)", "formerlyBridges2Input.csv" or die "Can't open CSV: $!"; while (my $row = $csv->getline($fh)) { # $row is now an array reference containing the # CSV's fields. # If the line is "a,b,c" then we will have: # $row->[0] "a" # $row->[1] "b" # $row->[2] "c" }

Please take a look at that and try to work in your code using the CSV parser and show us what you get. If you have a specific problem, we'll be more than happy to help a bit more.

Replies are listed 'Best First'.
Re^2: Getting data from Cisco Call Manager with Perl
by adamZ88 (Beadle) on Mar 02, 2017 at 22:00 UTC

    Hello Genio,

    I have finally applied all of your suggestions to my script. They were very helpful! The only suggestion that I did not adopt was to use "Text::CSV" as my file is not really a csv file. It is a regular file that includes one switch per line. I feel that for this purpose I will not need it, but in the future I might. Thanks!