Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • bail out on error (Score:3, Interesting)

    by jmm (276) <johnNO@SPAMperlwolf.com> on 2003.09.17 11:03 (#24270) Journal
    A lot of the extra code space is the constant testing whether you need to skip the next step because you've already hit an error. Just bail out when the error happens. I also changed it to either return 0, $msg (when an error happened) or else to return 1,@list (when everything worked).
    #------------------------#
    sub GetValues
    #------------------------#
    {
        my $dbh = get_connection('databasename')
          or return( 0, "Failed to get connection to databasename in GetValues" );
        my $sth = $dbh->prepare('Select * from table_name')
          or return( 0, "Call to prepare failed in GetValues" );
        my @a = $sth->execute()
          or return( 0, "Call to excecute failed in GetValues" );
        my $r;
        my @a;
        push @a, $r
            while $r = $sth->fetchrow_hashref;
        return (1, \@a);
    }
    #------------------------#