that's called a reference in perl

$foo = 'hummmm';

if I want to pass that as a reference to a subroutine (much better way to do things than by value) I would do this:

speak(\$foo);

sub speak {
        my ($foo) = @_;
        # this is by reference "$$"
        print $$foo . "\n";
        # also, if I want to set $foo, I can do so without having to
        # return the value of $foo (because we're refering to the
        # location of the data that's contained in $foo
        $$foo = $$foo . " we've spoken\n";

        # references are the best way to pass data!
}

Now, with hash references, you can do it two ways. $foo{whatever} is the same as $foo->{whatever}

my $foo = {}; # hash reference as opposed to 'my %foo;'

$foo->{words} = 'whatevah';

speak($foo);

sub speak {
        my ($foo) = @_;
        print $foo->{words} . "\n";
        #same thing
        print $$foo{words} . "\n";
}

my %foo;

$foo{words} = 'ok ok whatevah';

# by reference, and the data is accessed the
# same way as we accessed the hashref $foo
speak(\%foo);


Hope this helps...


Richard Schilling wrote:
Just a quick question, and perhaps it's a Perl language question. I forget, but why do you have to reference a hash with a double "$$" when you use fetchrow_hashref?

    [-
    use DBI;

    # code to open connection, run query, etc . . .
    -]

    [$ if $hashed_row = $query->fetchrow_hashref $]
    fieldname: [+ $$hashed_row{'fieldname'} +]<br>
    [$ endif $]

Don't know why but for some reason I'm drawing a blank . . .

Thanks.

--Richard

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
----------------------
Patrick Galbraith
Senior Software Developer
[EMAIL PROTECTED] [EMAIL PROTECTED]
[EMAIL PROTECTED]
206.719.2461


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to