craigmarksmith has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have an instance of HTML::TokenParser::Simple, I need to copy it, go to the next token in my copied version, then go back to my original (none incremented version). The problem is when I go to the next token in my copied version it does the same to my original verison. Any ideas?
#!/usr/bin/perl -w use HTML::TokeParser::Simple; my $p = HTML::TokeParser::Simple->new("clean.htm"); my $token = $p->get_token; #$token = $p->get_token; #$token = $p->get_token; print "1 " . $token->as_is . "\n"; my $p_blah = $p; print "2 " . getNextToken($p_blah) . "\n"; $token = $p->get_token; print "3 " . $token->as_is . "\n"; sub getNextToken { if(my $token_blah = $_[0]->get_token){ return $token_blah->as_is; } else { return "end"; } }
returns
1 <p class=label> 2 Business insurance 3 </p>
when I expected
1 <p class=label> 2 Business insurance 3 Business insurance

Replies are listed 'Best First'.
Re: HTML::TokeParser::Simple copying?
by fglock (Vicar) on Nov 23, 2004 at 11:19 UTC

    Untested - I wonder if this works:

    require Clone::PP; push @HTML::TokeParser::Simple::ISA, 'Clone::PP'; # deep copy my $p_blah = $p->clone();

    Clone::Any looks interesting too.

      Monster!!! You da man! Cheers!
Re: HTML::TokeParser::Simple copying?
by Xenograg (Scribe) on Nov 23, 2004 at 17:57 UTC

    Is this an issue of correctly "deep copying?" If so, can this object be properly replicated without using a separate module?

    ---
    The harder I work, the luckier I get.