pingme8705 has asked for the wisdom of the Perl Monks concerning the following question:

hi This is partial output of the excel file
Command | output show run | in encryption| service password-encryption ---------------------------------------------------------- | fsddfsfsdfsdfsd sdfs sd ---------------------------------------------------------- show ntp status | clock synchronised. 34.45.54.54 ---------------------------------------------------------- + | ----------------------------------------------------------
here i want to check for the a word say "encryption" in the first column and check for the same or other pattern in second column until next command appears in first column. can anyone comment on this ?
pingme8705 The world belong to the people who beleive in the beauty of their drea +ms

Replies are listed 'Best First'.
Re: data formatting in excel
by jmcnamara (Monsignor) on Sep 30, 2005 at 10:32 UTC

    You've twisted my arm a little into answering this. So could you clarify some points:

    Are you trying to match data in a flat file or in a data structure that you extracted from Excel or as you iterate through an Excel file?

    If you are iterating through a file can you show a short example of the code you are using, for context?

    Also, if you created the Excel file couldn't you just run your search against the input data instead?

    --
    John.

      hi Thanks for the reply. This output is directly the output of the excel file. its the output of the switch/routers. i have written a perl program to extract the output of the commands.
      pingme8705 The world belong to the people who beleive in the beauty of their drea +ms
Re: data formatting in excel
by dragonchild (Archbishop) on Sep 30, 2005 at 13:44 UTC
    A few questions:
    1. Is there a good reason you're not doing this in VB inside Excel vs. trying to do it in Perl?
    2. How are you extracting the data from the Excel file? Is this the problem step?
    3. If you have the data extacted, maybe with Spreadsheet::ParseExcel, then the problem can be reduced to "I have this data structrure and I need to iterate through it, grabbing various bits identified by (insert rules here)."
    Figure out where the problem is and solve that, then go to the next step. It sounds to me that you haven't fully analyzed what the steps are to solving your problem.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      hai here's the answers. 1) i cannot use VB as this is going to happen in a remote pc that is nix based and need to go for higher authorities permission for software installation 2)The problem i have shown is diagramatic representation in excel. We are getting similar output when we extract data from out perl program. 3) since the commands may vary the output may range from 1 line to 50 rows.And as shown in the diagram , the first column will have the commands and the 2nd column will have the output of the commands. did i answered you ?
      pingme8705 The world belong to the people who beleive in the beauty of their drea +ms
        The first step you need to accomplish is to find some data structure that will enable your intended use(s) of the data. Once you have designed your target data structure, the method of converting your input data into your data structure is basic computer science. Once you have the conversion of your data into your data structure, do whatever it is you need to do with it.

        Your questions have been telling me that you don't know what data structure you should be using. Data structures are the heart of every program. If you don't know how you need to represent your data, then you can't work with it.


        My criteria for good software:
        1. Does it work?
        2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: data formatting in excel
by jmcnamara (Monsignor) on Oct 03, 2005 at 11:35 UTC

    I'm going to guess that what you want to do is to "match data in column 2 of a file if the current or previous non-blank entry in column 1 matches another condition". I'd also guess that Excel doesn't have anything to do with the problem.

    I'm guessing this because, despite being given the opportunity to do so, you haven't explained clearly what you want to do.

    Here is an example program based on the above assumptions:

    #!/usr/bin/perl -w use strict; my $pattern1 = qr/encryption/; my $pattern2 = qr/encryption/; my $in_match = 0; while (<DATA>) { next unless /\S/; # Skip blank lines chomp; my ($command, $output) = split /\|/; if ($command =~ /\S/) { $in_match = $command =~ $pattern1; } if ($in_match and $output =~ $pattern2) { print $_, "\n"; } } __DATA__ Command | output show run in encryption | service password-encryption | fsddfsfsdfsdfsd sdfs sd | encryption | foo show ntp status | clock synchronised. 34.45.54.54 | some other text encryption1 | encryption2

    If this program isn't something like what you are looking for then you are really going to have to show a clear example in code or pseudo-code of what you are trying to do, with clear input and expected output.

    --
    John.

      hi
      open excel sheet store first column i- command in a array store the results in the 2nd array For the first command in the first column - check for the output in th +e second column + the pattern to be observed if the pattern matched then open another excel sheet and fill in the f +irst col by command name and second column by pattern we found check for the second command and so on… once end of first sheet open second sheet and so on…
      i think this may help you to understand the problem
      pingme8705 The world belong to the people who beleive in the beauty of their drea +ms