Can't use string ("3862926") as a HASH ref while "strict refs"

I guess I'm not understanding what I'm doing (or have been reading in my
web searches)... Can someone explain the difference between these two
code snippets...

SUN83-PRODWEB>more foo
#! /usr/local/bin/perl
        use strict;
        my %t;
        my ($a, $c);
        my ($aa, $cc);
        $a=3D$aa=3D1;
        $c=3D$cc=3Dq{Additional Electrical Circuit};
        $t{$a}{$c}{AMT}=3D1000;
        $c=3Dq{Additional};
        $t{$a}{$c}{AMT}=3D2;
        print $t{$aa}{$cc}{AMT}, "\n";
        &Ix($t{$aa}{$cc}{AMT});
sub Ix {
        my ($v) =3D @_;
        print "v=3D$v\n";
        }
SUN83-PRODWEB>./foo
1000
v=3D1000
SUN83-PRODWEB>


And=20
     1  #! /usr/local/bin/perl -d
     2  use strict;
   106  my ($prev_fund, $prev_service, $prev_acct);
   107  my %totals=3D();
   108  while ($sth->fetch) {
   109      if ($fund ne $prev_fund) {
   110
&PrintAcctTotal($totals{$prev_fund}{$prev_service}{$prev_acct}{AMT},
   111
$totals{$prev_fund}{$prev_service}{$prev_acct}{QTY});
   112
&PrintServiceTotal($totals{$prev_fund}{$prev_service}{AMT},
   113              $totals{$prev_fund}{$prev_service}{QTY});
   114          &PrintFundTotal($totals{$prev_fund});
   115          }
   116      elsif ($service ne $prev_service) {
   117          print
"(prev_fund,prev_service)=3D<$prev_fund,$prev_service>\n";
   118          print "value
=3D<$totals{$prev_fund}{$prev_service}{AMT}>\n";
   119
&PrintServiceTotal($totals{$prev_fund}{$prev_service}{AMT},
   120              $totals{$prev_fund}{$prev_service}{QTY});
....
   150      $totals{$fund}{$service}{$acct}{AMT} +=3D $amt;
   151      $totals{$fund}{$service}{$acct}{QTY} +=3D $n_qty;
   152      $totals{$fund}{$service}{AMT} +=3D $amt;
   153      $totals{$fund}{$service}{QTY} +=3D $n_qty;
   154      $totals{$fund} +=3D $amt;
   155      $prev_fund =3D $fund;
   156      $prev_service =3D $service;
   157      $prev_acct =3D $acct;
   158      }

SUN83-PRODWEB>./journal_items.pl

Loading DB routines from perl5db.pl version 1.27
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(./journal_items.pl:17):  my %param =3D (
main::(./journal_items.pl:18):          PERIOD=3D>'',);
  DB<1> c
(prev_fund,prev_service)=3D<Y,Additional Electrical Circuit>
Can't use string ("3862926") as a HASH ref while "strict refs" in use at
../journal_items.pl line 118.
 at ./journal_items.pl line 118
Debugged program terminated.  Use q to quit or R to restart,
  use O inhibit_exit to avoid stopping after program termination,
  h q, h R or h O to get additional info.
  DB<1> q
SUN83-PRODWEB>

Thank you in advance...=20
John W Moon

0
John
6/23/2006 5:36:55 PM
perl.beginners 29388 articles. 4 followers. Follow

5 Replies
1086 Views

Similar Articles

[PageSpeed] 31

On Fri, 2006-23-06 at 13:36 -0400, Moon, John wrote:
>      1  #! /usr/local/bin/perl -d
>      2  use strict;
>    106  my ($prev_fund, $prev_service, $prev_acct);
>    107  my %totals=();
>    108  while ($sth->fetch) {
>    109      if ($fund ne $prev_fund) {
>    110
> &PrintAcctTotal($totals{$prev_fund}{$prev_service}{$prev_acct}{AMT},
>    111
> $totals{$prev_fund}{$prev_service}{$prev_acct}{QTY});
>    112
> &PrintServiceTotal($totals{$prev_fund}{$prev_service}{AMT},
>    113              $totals{$prev_fund}{$prev_service}{QTY});
>    114          &PrintFundTotal($totals{$prev_fund});
>    115          }
>    116      elsif ($service ne $prev_service) {

Examine %totals here. (You can also add the following to get %totals
displayed on STDOUT:
  use Data::Dumper;
  print Dumper \%totals; # %totals will be called $VAR1
)

>    117          print
> "(prev_fund,prev_service)=<$prev_fund,$prev_service>\n";
>    118          print "value
> =<$totals{$prev_fund}{$prev_service}{AMT}>\n";

This is generating an error because you are going (at least) one level
too deep. In other words, %totals doesn't have the structure you think
it has.


-- 
__END__

Just my 0.00000002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/


0
shawnhcorey
6/23/2006 6:04:09 PM
On 6/23/06, Moon, John <John.Moon@dms.myflorida.com> wrote:

>    118          print "value
> =<$totals{$prev_fund}{$prev_service}{AMT}>\n";

> Can't use string ("3862926") as a HASH ref while "strict refs" in use at
> ./journal_items.pl line 118.

From the looks of that message, I'm guessing that $totals{$prev_fund}
holds 3862926 instead of a hash reference.

>  154      $totals{$fund} += $amt;

Here you're using $totals{$fund} as if it's an integer, instead of a
hash reference. If it is a reference before line 154, it will be
(silently) converted to an integer, since you're using it as one.
Since the integer is a memory address, it's almost certain not to be
what you want.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
0
tom
6/23/2006 6:15:17 PM
Moon, John wrote:
> [...]
>    150      $totals{$fund}{$service}{$acct}{AMT} += $amt;
>    151      $totals{$fund}{$service}{$acct}{QTY} += $n_qty;
>    152      $totals{$fund}{$service}{AMT} += $amt;
>    153      $totals{$fund}{$service}{QTY} += $n_qty;
>    154      $totals{$fund} += $amt;
 > [...]

I think this is the problem. There is a conflict between making 
$totals{$fund} a hash reference (lines 150-153) and making it a number 
(line 154).

The same conflict exists between lines 150-151 and lines 152-153. I 
don't know much about your data, but I might do it like this:

$totals{$fund}{$service}{$acct}{AMT} += $amt;
$totals{$fund}{$service}{$acct}{QTY} += $n_qty;
$totals{$fund}{$service}{total}{AMT} += $amt;
$totals{$fund}{$service}{total}{QTY} += $n_qty;
$totals{$fund}{total}{total}{total} += $amt;

IOW, you (probably) need to keep the depths the same.

HTH


0
mumia
6/23/2006 8:10:41 PM
On Fri, 2006-23-06 at 15:10 -0500, Muma W. wrote:
> IOW, you (probably) need to keep the depths the same.

What he needs to do is to check the structure (with the debugger or
Data::Dumper) every time before he uses the structure. And that means
_every_ time. (Don't worry, like my karate instructor use to say, "The
first hundred are easy.")


-- 
__END__

Just my 0.00000002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/


0
shawnhcorey
6/23/2006 9:01:54 PM
From: Muma W. [mailto:mumia.w.18.spam+nospam@earthlink.net]=20
Sent: Friday, June 23, 2006 4:11 PM
To: Beginners List
Subject: Re: Can't use string ("3862926") as a HASH ref while "strict
refs"

Moon, John wrote:
> [...]
>    150      $totals{$fund}{$service}{$acct}{AMT} +=3D $amt;
>    151      $totals{$fund}{$service}{$acct}{QTY} +=3D $n_qty;
>    152      $totals{$fund}{$service}{AMT} +=3D $amt;
>    153      $totals{$fund}{$service}{QTY} +=3D $n_qty;
>    154      $totals{$fund} +=3D $amt;
 > [...]

I think this is the problem. There is a conflict between making=20
$totals{$fund} a hash reference (lines 150-153) and making it a number=20
(line 154).

The same conflict exists between lines 150-151 and lines 152-153. I=20
don't know much about your data, but I might do it like this:

$totals{$fund}{$service}{$acct}{AMT} +=3D $amt;
$totals{$fund}{$service}{$acct}{QTY} +=3D $n_qty;
$totals{$fund}{$service}{total}{AMT} +=3D $amt;
$totals{$fund}{$service}{total}{QTY} +=3D $n_qty;
$totals{$fund}{total}{total}{total} +=3D $amt;

IOW, you (probably) need to keep the depths the same.

HTH

Thank you...=20

jwm


--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>


0
John
6/25/2006 2:05:28 PM
Reply:

Similar Artilces:

Can't use string ("1") as a HASH ref while "strict refs"
--00151747694010009a04ad544f1b Content-Type: text/plain; charset=UTF-8 Hi, I was getting this error message for one of my script. The reason came out out to be, I had not place a semi-colon at the end of try-catch block. try { something } catch some_exception { do something } After I placed the semi-colon, I am no longer getting this error (Can't use string ("1") as a HASH ref while "strict refs") try { something } catch some_exception { do something }; My questions is I have quite a few scripts that are using the SAME try-catch...

Can't use string ("1") as a HASH ref while "strict refs" in use at ./policy.sanitizer line 255.
Hi there, I am trying to figure out why the following lines are giving me an error: --- snip --- $found{filter}{$filter}{family}{$family} = 1; print keys %{ $found{filter}{$filter}{family} }; --- snip ---- here's the error Can't use string ("1") as a HASH ref while "strict refs" in use at ../policy.sanitizer line 255. I am trying to the display all the keys for $found{filter}{$filter}{family} please Cheers, Noah On 10/9/09 Fri Oct 9, 2009 2:12 PM, "Noah" <noah-list@enabled.com> sc...

bugzilla: undef error
I'm encountering the problem described here: https://bugzilla.mozilla.org/show_bug.cgi?id=300448 I'm running bugzilla 2.18.3 on fedora. The problem seems to be that a line was added to this file: template/en/default/bug/create/created.html.tmpl So I commented out this line: mailrecipients = item.mailrecipients and restarted everything, but I'm still getting the same error. I'm not sure that I understand the solution very well. Any ideas? Thanks, Bryan ...

DBD::Proxy::db table_info failed: Server returned error: Failed to execute method CallMethod: Can't use string ("1") as an ARRAY ref while "strict refs" in use
------_=_NextPart_001_01C2BB46.4379CEA8 Content-Type: multipart/related; type="multipart/alternative"; boundary="----_=_NextPart_002_01C2BB46.4379CEA8" ------_=_NextPart_002_01C2BB46.4379CEA8 Content-Type: multipart/alternative; boundary="----_=_NextPart_003_01C2BB46.4379CEA8" ------_=_NextPart_003_01C2BB46.4379CEA8 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I'm having a problem using the table_info() via ProxyServer... I'm = getting the following error messages: I am us...

Can't use string as a subroutine ref while "strict refs"
------=_NextPart_000_0004_01C70428.644E8960 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable use strict; use warnings; use CGI; my $q =3D new CGI; my $do =3D $q->param('do') || 'main''; if ($do) { &$do; } sub main { blah blah } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Trying to call the subroutine main from variable $do but I am gettin' = error: Can't use string ("main") as a subroutin...

Can't use string as a subroutine ref while "strict refs"
Hello, I am trying to do the following, do I need to remove the strict option for this to work or is there a better way ? --snip-- sub admin { my $term = shift; my $host = shift; my @actions = ( "ssh_login", "su_login", "su_logout", "ssh_logout", "cmds" ); foreach my $a (@actions) { &show_log("Calling $a"); my $check= &{$a}; return(1) unless $check==0; } } --snip-- -- Michael Gale Red Hat Certified Engineer Network Administrator Pason Systems Corp. You could...

lwp-rget error message ("can't use string ("URI::URL") as ARRAY ref)
I've been using lwp-rget, for instance: cyc$ lwp-rget --depth=2 --limit=100 "http://www.somesite.com/~whoever with no problems. tonight I got this msg: Can't use string ("URI::URL") as an ARRAY ref while "strict refs" in use at /usr/local/path_to_module/URI/WithBase.pm line 41. version info: This is perl, version 5.005_03 built for i386-freebsd and: This is lwp-rget version 1.19 (libwww-perl-5.52) Any advice would be really appreciated. CYC. Hi! I have a simple program which opens each URL in a file and saves ...

Can't use string ("") as an Array ref
I'm getting the following when trying running the following code with use strict; without it, it works fine.=20 =23=21/usr/bin/perl -w=20 use strict;=20 use warnings;=20 use Data::Dumper;=20 my (=40data,=40contents);=20 =40data =3D <STDIN>; push(=40contents,map =7B =5B split/:/,=24_ =5D if/=5E=5Cw+/ =7D (sort = =40data) );=20 for(1..=24=23contents) =7B=20 print =24contents=5B=24_->=5B0=5D . =22=5Cn=22 if = defined(=24contents=5B=24_=5D->=5B0=5D);=20 =7D - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - = - - - - - - - Th...

Can't use string ("bug/create/create-guided.html.tm") as a HASH ref
- I could use some help with my Bugzilla install - I have installed the stable release of Bugzilla (2.16.5) and have customized some of the templates (which is a cool new way to do things). I am following the instructions to modify create.html.tmpl and comment.txt.tmpl to create some fields for bug entry. However, I get the following perl error message and I can't figure out why: Can't use string ("bug/create/create-guided.html.tm") as a HASH ref while "strict refs" in use at /usr/lib/perl5/site_perl/5.8.0/Template/Provider.pm line 663. I am new to...

Using "+" or "||"
Using SQLAnywhere 5.5.04, I've gotten into the habit of using "||" in ISQL to indicate a string concatenation. I needed to paste my SQL statement into the PowerBuilder script painter for some embedded SQL, and PB didn't like the "||" very much at all. I changed it to "+" and it seems to be ok. Do these two operators indicate ~exactly~ the same thing? moin, afaik these two's are not the same! if you're using "||" and any term is NULL then in the resultstring the term will be ignored if you use "+" then the resu...

"Using" or "With"
Hi all Please can someone enlighten to me as regards the difference with the "Using" and "With" statement when accessing data - which is better, what are the limitations and/or any pointers. Many thanks. Regards DaveDavid WinchesterPlease mark as answer if this is the solution.  using gives you the ability to use the connection and it closes the connection directlly after you finish using it. and there is no need to try- cach - finaly. there is no limitation on using USING keywordMuhanad YOUNISMCSD.NETMy Blog || My Photos || LinkedIn I have a dataobject the re...

(setxkbmap) can't use "ALT_GR"/"left ALT" button after using it
hello folks i use LXDE as i'm known and my only solution to switch keyboard is to use setxkbmap now after i define keyboards layouts to switch and chose ALT+Shift to switch it goes "bugged" using the right ALT will switch the layouts and i'm not able to write the "other" letters help please P.S : this is the command i use �setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll fr,ar� -- SAFAD ------------------------------------------------------------------------ bump up rotfl! -- SAFAD -------------------------------...

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Web resources about - Can't use string ("3862926") as a HASH ref while "strict refs" - perl.beginners

Resources last updated: 12/5/2015 7:08:56 AM