in reply to Stuck with RegEx (Parsing whois output)


A quick script that came to my mind.
However, I always believe that TIMTOWTDI
use strict; my $flag = "n"; open FH, '<', 'filename'; foreach (<FH>) { $flag = "n" if /\{section\d+\}/; $flag = "y" if /\{section2\}/; if ($flag =~ /[yY]/) { print $1 if /key2: (.*)$/; } } close FH;
Update: $flag reset. Thanks to si_lence

Replies are listed 'Best First'.
Re^2: Stuck with RegEx
by si_lence (Deacon) on Sep 28, 2004 at 09:18 UTC
    Does this not print all the values for key2 even if they are in a different section that comes after {section2}?
    So you need to reset the $flag variable as soon as you come to the next section.
    si_lence
Re^2: Stuck with RegEx (Parsing whois output)
by marsch (Initiate) on Sep 28, 2004 at 09:13 UTC

    Hi,

    thanks for your help. Definitely, this would be fine. But my aim is to tune the Net::XWhois module, especially the DENIC parser. The engine parses the input with one regex:

    @matches = $self->{ Response } =~ /${$self->{Parser}}{$key}/sg;

    This is why I feel bound to that =~ m/.../sg structure. Otherwise I had to rewrite the complete code in order to capture the distinct whois responses...