in reply to Predefining complex data structures?
Secondly, you want to do something along the lines of:
Obviously, I'm assuming that $tag is some object with three methods - name(), value(), and attributes(). These will have to return the appropriate values from the data source. Also, I'm assuming that attributes() will return everything within the tag definition other than the tag's name. If all you get is the text, you could do something like:# Caveat Lector - this is untested! foreach $tag (@tags) { push @{$tagstack{$tag->name}}, { text => $tag->value, attributes => { split /[\s=]+/, $tag->attributes }, }; }
The regex could be tightened, but this is off-the-cuff.foreach my $tag (@tags) { my ($name, $attributes, $value) = $tag =~ m#^<(\w+)\s+(\w+)?\s*>(.*?)</\1>$#; # Use $name, $attributes, and $value as per above }
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|