Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I'm assuming this is related to a markup language such as HTML or XML.

I'm unsure whether you are using the data to create a document or if you are extracing the data from a document. If one of these, I would suggest you use one of the HTML:: or XML:: modules on CPAN. There may be others with which I'm unfamiliar; XML::LibXML is the only one that I have a reasonable working knowledge of.

In terms of how you might use anonymous arrays and hashes, behind the <readmore> is a script which creates a data structure to represent the following HTML fragment (and prints the content of the <em> element).

<html lang="en"> <head> </head> <body> <h1>Heading1</h1> <p id="para1" class="first-para">This is <em>emphasied</em>. A +nd this is not.</p> </body> </html>

Note: This code is for illustrative purposes only - I am not suggesting you include it in an application.

use strict; use warnings; my $ra_web_page = [ { type => 'tag', element => 'html', attributes => { lang => 'en', }, content => [ { type => 'tag', element => 'head', attributes => { }, content => [ ], }, { type => 'tag', element => 'body', attributes => { }, content => [ { type => 'tag', element => 'h1', attributes => { }, content => [ { type => 'string', value => 'Heading 1', }, ], }, { type => 'tag', element => 'p', attributes => { id => 'para1', class => 'first-para', }, content => [ { type => 'string', value => 'This is ', }, { type => 'tag', element => 'em', attributes => { }, content => [ { type => 'string', value => 'emphasised', }, ], }, { type => 'string', value => '. And this is not.', }, ], }, ], }, ], }, ]; my $em_text = $ra_web_page->[0]{content}[1]{content}[1]{content}[1]{co +ntent}[0]{value}; print "EM text = $em_text\n";

This has probably raised further questions. Ask away.



In reply to Re: Introduction to anonymous arrays and hashes by Prior Nacre V
in thread Introduction to anonymous arrays and hashes by sulfericacid

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2023-06-07 06:36 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (29 votes). Check out past polls.