note
Prior Nacre V
<p>
I'm assuming this is related to a markup language such as HTML or XML.
</p>
<p>
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 [http://search.cpan.org/modlist/World_Wide_Web/HTML|HTML::] or [http://search.cpan.org/modlist/String_Language_Text_Processing/XML|XML::] modules on [http://search.cpan.org/|CPAN]. There may be others with which I'm unfamiliar; [http://search.cpan.org/~phish/XML-LibXML-1.58/LibXML.pod|XML::LibXML] is the only one that I have a reasonable working knowledge of.
</p>
<p>
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).
</p>
<code>
<html lang="en">
<head>
</head>
<body>
<h1>Heading1</h1>
<p id="para1" class="first-para">This is <em>emphasied</em>. And this is not.</p>
</body>
</html>
</code>
<p>
<strong>Note:</strong> This code is for illustrative purposes only - I am not suggesting you include it in an application.
</p>
<readmore>
<code>
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]{content}[0]{value};
print "EM text = $em_text\n";
</code>
</readmore>
<p>
This has probably raised further questions. Ask away.
</p>
<div class="pmsig"><div class="pmsig-334485">
<p>Regards,</p>
<p>PN5</p>
</div></div>
405724
405724