in reply to Re: Passing Indirect as Reference
in thread Passing Indirect as Reference

But couldn't you do just
my $parse_it = HTML::TokeParser->new( \ ${$self->{'HTML'} } );
As far as my limited understanding of references goes, you force the $self part to be interpreted as a scalar (string), and pass a reference to that string.

If I'm wrong here (correct me if not ;-), you also could do

my $parse_it = HTML::TokeParser->new( \ "$self->{HTML}" );
as the quotes are not necessary, and the \ should give a reference to the resulting string.

Hope this helps,

Jeroen
I was dreaming of guitarnotes that would irritate an executive kind of guy (FZ)

Replies are listed 'Best First'.
Re: Re: Re: Passing Indirect as Reference
by chipmunk (Parson) on Jan 10, 2001 at 19:32 UTC
         Quote:     my $parse_it = HTML::TokeParser->new( \ ${$self->{'HTML'} } ); That code dereferences $self->{'HTML'} as a scalar reference; if $self->{'HTML'} were already a scalar reference, this whole exercise would be unnecessary. So that won't work.

         Quote:     my $parse_it = HTML::TokeParser->new( \ "$self->{HTML}" ); That works, passing a reference to a copy of $self->{HTML}, instead of to $self->{HTML} itself. That has the (probably not significant) disadvantage of allocating memory for a duplicate of $self->{HTML}, but the advantage of not having to worry about HTML::TokeParser changing the value of $self->{HTML} via the reference. That's a good suggestion.

Re: Re: Re: Passing Indirect as Reference
by ichimunki (Priest) on Jan 10, 2001 at 18:10 UTC
    thanks to both of you. FYI, looking at jeroenes' last example I tried
    my $parse_it = HTML::TokeParser->new( \ $self->{HTML} );
    which worked just fine without the double quotes around the construct.

    (I use the quoted hash keys by habit and early example, I suppose I can drop that habit soon. It doesn't affect hash keys with spaces in them?)
      I tried it, but perl appears to interpret the words as a method/package pair. So, you'll have to quote if you use spaces in keys.

      Jeroen
      I was dreaming of guitarnotes that would irritate an executive kind of guy (FZ)

        I knew there was a reason I was keeping this habit around. I had read somewhere that such a thing would happen, but when I tried to verify this morning via the Camel3 and perldoc I could not. Thanks.