Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Now, the page is dynamic. What I mean is that there could be no output like above, or there could be 10 outputs like above. I am trying to build a hash from the output, and doing it like so:<A TARGET="UI" HREF="/turnka/user_interaction?action=display_question +&UNIT_TO_BATCH=batch_UTFS-7-1369171801707%3A1%3A1&LOCATION=UTFS-7&QUE +STION_ID=CHECK_TIME">batch_UTFS-7-1369171801707:1:1</A></TD> <TD ALIGN="center"> UTFS-7</TD> <TD ALIGN="center"> CHECK_TIME</TD> <TD ALIGN="center"> Sys Check</TD> <TD ALIGN="center"> 70 h23 m</TD> <TD ALIGN="center"> Please Answer</TD> </TR>
I am doing this for multiple servers, so I am thinking that the hash should look something like: $hash{'server_name'}{'location'}{'url'} and so on... Is there an easy way to map the matches from a regex match to a hash? Looking at my code I know that the way I am going about this is really inefficient.my $server = $self-{server}; + + my $response = $http->get("http://$server:8080/turnka/view"); + my $content = $response->{content}; + if ( $content !~ /No UI/ ) { my @ui = ( $content =~ /(<A\s+TARGET="UI" HREF="(.*?)"> + (?<!\=)(batch.*?)<\/A><\/TD> + <TD ALIGN.*?>(.*?)<\/TD> + <TD ALIGN.*?>(.*?)<\/TD> + <TD ALIGN.*?>(.*?)<\/TD> + <TD ALIGN.*?>(.*?)<\/TD> + <TD ALIGN.*?>(.*?)<\/TD>/gs + ); + foreach my $ui (@ui) { + $ui_hash{$server}{$3}{'batch'} = $2; + $ui_hash{$server}{$3}{'url'} = $1; + $ui_hash{$server}{$3}{'interaction'} = $4; + $ui_hash{$server}{$3}{'title'} = $5; + $ui_hash{$server}{$3}{'time'} = $6; + $ui_hash{$server}{$3}{'status'} = $7; + } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looking for a better way to build a hash from regex matches.
by hdb (Monsignor) on May 22, 2013 at 07:14 UTC | |
|
Re: Looking for a better way to build a hash from regex matches.
by Anonymous Monk on May 22, 2013 at 03:13 UTC |