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

What is the correct name for the \agent thing
my $stream =HTML::TokeParser->new( \agent->{content} );
how is it related to the
print Dumper \@link;
I believe it lets you pass a reference to a function or an object as an argument. Is this right?

Replies are listed 'Best First'.
Re: what is \ in perl
by davido (Cardinal) on Jun 21, 2006 at 21:46 UTC

    It's called the backslash operator (see perlref). It is used to take a reference to a variable, subroutine, or value. It doesn't create a new variable, simply a reference to an existing variable, sub, or value.

    perlreftut is a good starting point for references.


    Dave

Re: what is \ in perl
by EvanK (Chaplain) on Jun 21, 2006 at 21:52 UTC
    as with everything in perl, the backslash '\' has several different uses.

    you're correct that when you precede an unquoted variable with a backslash, you get a reference to it.

    # this will print a memory address like SCALAR(0x1e8feac) print \$test;

    __________
    Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
    - Terry Pratchett

Re: what is \ in perl
by HuckinFappy (Pilgrim) on Jun 22, 2006 at 03:38 UTC
    And it does things which you may not expect. Well, I didn't expect them, but when I think about it, things make sense:
    DB<15> $bar = \do { my $n = @INC ; "$n entries in \@INC" } DB<16> print $$bar 6 entries in @INC
Re: what is \ in perl
by hawtin (Prior) on Jun 22, 2006 at 08:01 UTC

    I am not sure what the meaning of the question is, but the answer is probably here