"Satya Devarakonda" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi,
>

Hi Satya

> I have a set of strings in array @search_key and a log file loaded into an
> array @modem_log.
>
> I want to extract lines that contain the keys and load them into four
> arrays - @env_start, @env_end, @env_files, @env_bytes, @env_errors.
>
> Can somebody tell me if what I am doing below is right?
>
> Thanks for your help...
> Satya::Novice_City
>
> --------------------------------------------------------------------------
--------------------------------------
> my @search_key = qw (FILETYPE.ZIP RBZ RBZ Bytes Errors);

I'm not sure what you mean here, but it's probably not what you've coded.
This does:

    my @search_key = ('FILETYPE.ZIP', 'RBZ', 'RBZ', 'Bytes', 'Errors');

as qw() takes the string between the () delimiters and splits it on
whitespace.

> my @search_out =  qw( \@env_start  \@env_end  \@env_files  \@env_bytes
\@env_errors);

For the same reason, this means:

    my @search_out = ('\@env_start', '\@env_end', '\@env_files',
'\@env_bytes', '\@env_errors');

where what you really want is:

    my @search_out = (\@env_start, \@env_end, \@env_files, \@env_bytes,
\@env_errors);

which is a very unusual way of implementing a two-dimensional array. Each of
the rows are separate named arrays such that $env_start[0] is the same thing
as $search_out[0]->[0]. If you're using 'strict' then these arrays need also
predeclaring with 'my'. If not, then you don't need 'my' anywhere.

>
>     for ($i = 0, $j = 0; $i < @search_key; $i++)
>     {
>         ${search_out[$i]} = grep (/$search_key[$i]/,@modem_log);
>         for ($j = 0; $j < ${search_out[0]}; $j++)
>         {
>            ${search_out[$i]} = substr
($search_out[$i][$j],$str_start[$j].$str_length[$j]);
>         }
>     }

Here I get a bit lost. We're iterating through the array of search keys. All
elements of @modem_log that contain $search_key[0] get copied into array
@env_start, all those that contain $search_key[1] into array @env_end,
...etc.

First of all, you want:

    for ($i = 0; $i < @search_key; $i++)
    {
        @$search_out[$i] = grep ((index $_, $search_key) >= 0, @modem_log);

        :
    }

which is roughly what you had, except that I've used index() instead of a
regex, as all metacharacters in the search key would have their special
meaning (for instance the period character would match any single character
in the log record).

In the for ($j) loop I'm completely lost. Firstly you seem to be overwriting
the array references in @search_out with the result of substr(). Secondly,
arrays @str_start and @str_length have appeared from nowhere, and you're
concatenating them into a single string for the second parameter of
substr().

I shan't try to guess at what you intend to do here, but have a go at
implementing what I've written here and see if you can also explain what
result
you need.

I hope this helps at least a little :)

Cheers

Rob






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to