I just know there's a better way to do this than what I am doing. Basically, I get the content of a webpage using HTTP::Tiny; the content looks 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>
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:
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; + } }
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.

In reply to Looking for a better way to build a hash from regex matches. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.