in reply to Re: Re: accessing Apache::DBI 'cached connections'
in thread accessing Apache::DBI 'cached connections'

In your example, $DBH is just an empty lexical variable that you declared right before dumping it. The DBI->connect code will never even run because "my $DBH" will always return true. (It returns the result of the my() call, not the value of the variable.)

UPDATE: Advice about the return value of my() is not correct. See below.

  • Comment on Re: Re: Re: accessing Apache::DBI 'cached connections'

Replies are listed 'Best First'.
Re: Re: Re: Re: accessing Apache::DBI 'cached connections'
by bobn (Chaplain) on Jul 21, 2003 at 21:38 UTC

    Your post sounded so good, I  ++'d it, but it's wrong.

    #!/usr/bin/perl -w my $DBH ||= retval('1'); print "$DBH\n"; sub retval { return $_[0] }

    This prints '1'.

    Update: Oddly enough, Camel 3 calls 'my' a named unary operator and lists named unary operators at higher precedence than any of assignment, assignment operators or logical operators, so you should be right, but the code doesn't work that way for me, at least not on 5.8.0 or 5.005_03.

    Newer Update: 'my' probably does have higher precedence thatn ||=, but it doesn't matter because it returns false.

    my $orr || print "or\n"; my $andd && print "and\n";

    prints 'or'.

    --Bob Niederman, http://bob-n.com
      You're right, the DBI->connect part will get executed. However, since he has || and not ||=, it will just get thrown away.

        That's for sure, was pointed out previously. BTW, see my update above - interesting, no?

        --Bob Niederman, http://bob-n.com