Re: Problems passing a reference to a hash between functions



niall.macpherson@xxxxxxxxxxxx wrote:
> I have a sub which calls the fetchall_hashref method from the DBI
> module. I like to have all my subs return either 0 (success) or -1
> (failure) and if the sub need to return some data to the caller I
> always pass a variable by reference and populate that variable . I tend
> to try to think of refs the same way as I did with pointers in 'C'
> which I am more familiar with. What I am trying to do here is pass a
> reference to a reference to a hash to the sub.

As others have said, you should not program C in Perl. Program Perl in
Perl.

>
> my %attr = ( RaiseError => 1, AutoCommit => 0);
> $$r_conn = DBI->connect("dbi:ODBC:" . $dsn , undef, undef,
> \%attr);

You said you want your subroutines to return -1 on failure. However,
because you have RaiseError => 1, they are generally not going to return
anything on failure. Instead, DBI will raise errors, i.e. call die. You
could intercept that with eval{}, but in the code you show doesn't do that.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.



Relevant Pages