in reply to Cut n' paste monkey on my back

Wouldn't this be a great use for a hash? Just search for any keyword on the line and if you find one, increment the appropriate hash entry. Then read from $output{VLAN}, etc to find these. You should only have 1 match string. Maybe you could do something like this:
my %flag = (); while (<IN>) { s/\.\d+\s*=\s*/_/; # Format the string to match nicer $flag{$1}++ if /(VLAN|if(?:Oper|Admin)Status_(?:up|down))/; } # Now access $flag{VLAN}, $flag{ifOperStatus_up}, etc.

I'm not sure if the substitute makes you take more time, but at least you won't parse through the entire file 4 times. Sometimes it really does make more sense to parse the file one line at a time, instead of in a huge block. This particularly makes sense because the lines have such regularity.

-Ted

Replies are listed 'Best First'.
RE: Re: Cut n' paste monkey on my back
by turnstep (Parson) on Nov 02, 2000 at 07:03 UTC

    That was the first thing I though of also, although I would write it like this:

    $found{$1}++ while /($foo|$bar|$baz)/go;

    The only problem in general is that $foo and company cannot contain any "special" regular expression character...it will work, but they will return the match, not the original search, i.e. $foo = "ba.t" would create keys of "bart", "bast", and "bait". Still, if you know your input file well enough to avoid them, a simple hash increment is definitely a smooth way to do it.

RE: (2) Cut n' paste monkey on my back (increment hash entries)
by ybiC (Prior) on Nov 02, 2000 at 09:31 UTC
    Thanks tedv - exactly what I was hoping for.   8^)

    Since the SNMP collection code is in the same script, would it make sense to put the collection data into an array instead of the intermediate file, and read array elements into your code?   Would save having to open+close+unlink file, but are there drawbacks ?
        cheers,
        Don
        striving for Perl Adept

    Update: and thanks to mdillon for esplaining turnstep's /o syntax above.   More food for thought.   But my brain is full.   {g}