in reply to Trying to use Spreadsheet::WriteExcel. What could be the problem?

If you analyze your input file better, you may be able to come up with a far elegant solution.

Example, ask yourself, is an Interface information always in a block that has a form that always starts with the /^Interface\s(\w+)$/ ? If so, then read in the file, pushing each (chomped) line into an array. When you get to the next Interface block, process the array you have built up in a function (to make the code look cleaner). In this function you can iterate over each element of the array looking for the data you want to extract (vrid, state, etc) and print it out (or pass that info on to another function that does the printing).

This way you keep your code looking clean and polished, thus easier for you and others to read and understand. It will also be easier for you to debug. You can then easily figure out why your code mixes up the interfaces and the addresses.

-imran

  • Comment on Re: Trying to use Spreadsheet::WriteExcel. What could be the problem?

Replies are listed 'Best First'.
Re^2: Trying to use Spreadsheet::WriteExcel. What could be the problem?
by sunny (Initiate) on Feb 15, 2006 at 07:25 UTC
    Hi

    yes

    My interface always have a form that Interface name1,Interface name2.....Interface name10

    can you figure out where i did mistake ?
Re^2: Trying to use Spreadsheet::WriteExcel. What could be the problem?
by Anonymous Monk on Feb 15, 2006 at 07:23 UTC
    Hi yes. Interface is always have form Interface name1, Interface name2 ....Interface name10 cann you figure it out where i did mistake ?
      Here is a sample of what a cleaner (in my opinion) version of your code should look like:
      #... my @lines = (); open my $inFile, '<', 'svrrp.txt' or die "Couldn't open svrrp.txt: $!" +; my $currIface = ""; while (<$inFile>) { chomp; if (my $iface = ($_ =~ /^Interface\s(\w+)$/) { processlines($currIface, @lines); $currIface = $iface; @lines = (); } push @lines, $_; } processlines($currIface, $lines); # to process last interface block #... sub processlines() { my $iface = shift; return unless $iface; # declare any vars foreach (@_) { # do your pattern matching here } # print your findings }
      You can expand on this to make it suit you.

      -imran