arrays - How can I avoid this error produced while using 'strict'? -


i have couple of lines of code work if use strict; commented out. however, don't want have disabled entire script because of 1 small section.

i need either recode it, or somehow disable use strict; temporarily , re-enable it. first option more realistic, don't know how change code work in strict mode.

my ($ctc_rec_ref) = get_expected_contacts($ctc,$fy);  @expected_ctc_rec = @$ctc_rec_ref;  print $expected_ctc_rec[0][0]."\n"; print $expected_ctc_rec[0][1]."\n"; print $expected_ctc_rec[0][2]."\n";  sub get_expected_contacts {     (@ctc_rec,$i) = ((),0);     $stmt = "select distinct field1, field2, field3 table field4 = ? , field5 = ? , field6 = 'e'";     $sth = $db1->prepare($stmt); $sth->execute(@_);      while(@results = $sth->fetchrow_array())     {         push @{ $ctc_rec[$i] }, $results[0];         push @{ $ctc_rec[$i] }, $results[1];         push @{ $ctc_rec[$i] }, $results[2];          $i++;     }        return (\@ctc_rec); } 


use strict; enabled:

can't use string ("0") array ref while "strict refs" in use @ ./return5.pl line 49.

(line 49: push @{ $ctc_rec[$i] }, $results[0];)


use strict; disabled:

1468778  04/01/2011  30557 

how can rewrite code works if strict mode disabled? if not possible, can use strict; temporarily disabled , re-enabled short piece of code within script?

the problem that

my (@ctc_rec,$i) = ((),0); 

doesn't think does. means same as

my @ctc_rec = (0); $i; 

strict doing it's meant , catching mistake. try writing:

my @ctc_rec; $i = 0; 

instead. should rid of error.

in case, there's way rid of error, , simplify code considerably @ same time: use selectall_arrayref.

sub get_expected_contacts {    return $db1->selectall_arrayref(      "select distinct field1, field2, field3 table field4 = ? , field5 = ? , field6 = 'e'",      undef, @_    ); } 

if intentionally doing prohibited strict (but knew doing), can disable strict locally:

use strict;  # code strict {    no strict;   # code not strict here } # strict in effect 

but should never until understand strict complaining about, , why it's ok in instance. it's better disable part of strict have to. instance, can no strict 'refs'; allow symbolic references without disabling other things strict does. (note: same technique works warnings pragma, should using.)


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -