Making progress. Needed to understand hash references, and how to
de-reference them.
Tim Bowden
On Mon, 2008-02-25 at 14:54 +0900, Tim Bowden wrote:
> Hi all,
>
> I'm using HTML::Parser to process files containing snippets of html
> looking like:
> <option value="1">First option</option><option value="2">Another
> choice</option><option value="4">pick me</option>
>
> I'm wanting to create a hash of option value, name pairs. Ie, 1 =>
> "First option",2=>"Another choice" and so on. Problem is, I don't know
> how to handle the hash returned in $attr in the start sub:
>
> #!/usr/bin/perl -wT
> use strict;
> use HTML::Parser;
>
> my %choices;
> my $file = 'test_snippet';
> my $parser = HTML::Parser-> new(api_version => 3,
> start_h => [\&start, "tagname, attr"],
> );
>
> sub start {
> my ($tag, $attr) = @_;
> print "$tag\t$attr\n";
> # do something here to read the hash returned in $attr
> # and add the key value pair to %choices but what?
> }
> $parser->parse_file($file) or die "couldn't parse file";
>
>
> I realise it should be obvious and simple, but I feel like I've been hit
> with the stupid stick for now. Any suggestions?
>
> Thanks,
> Tim Bowden
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/