in reply to Passing Indirect as Reference

How about: my $parse_it = HTML::TokeParser->new( \( $self->{'HTML'} ) ); \(LIST) maps \ onto each element of LIST, and returns a list of references.

Replies are listed 'Best First'.
Re: Re: Passing Indirect as Reference
by jeroenes (Priest) on Jan 10, 2001 at 13:05 UTC
    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)

           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.

      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)