Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Can't modify int in scalar assignment error

by rkrish (Acolyte)
on Dec 19, 2012 at 04:55 UTC ( #1009494=perlquestion: print w/ replies, xml ) Need Help??
rkrish has asked for the wisdom of the Perl Monks concerning the following question:

I have code snippet which while compiling giving 'Can't modify int in scalar assignment' error.Am i doing anything wrong here? I'm getting the error at line :'foreach (@accums)'

my code is :

my $getAccumsForAcct = qq{ select distinct usage_acum_seq_nbr fr +om svc_price }; my $getAccums = $lda->prepare($getAccumsForAcct); my $sbscrp_id='0032581923'; if(defined($getAccums)) { $getAccums->execute(); while (my @accums = $getAccums->fetchrow_array() ) { } foreach (@accums) { int returnCode = SUCCESS; my $xmlFile = "GetUsgSummary_" . $acct_nbr . $_.". +xml"; createXmlForUpd( $xmlFile, $acct_nbr,$sbscrp_id ); $returnCode = invokeServer( $acct_nbr , $xmlFi +le ); if ( $returnCode != SUCCESS ) { return $return +Code; } return $returnCode; } }

Comment on Can't modify int in scalar assignment error
Download Code
Re: Can't modify int in scalar assignment error
by NetWallah (Abbot) on Dec 19, 2012 at 05:25 UTC
    If you "use strict;" in your program, it would have told you:
    Global symbol "@accums" requires explicit package name at ..
    which identifies the problem immediately, in your "foreach(@accums)" line.

    Poor programming practices precurse pernicious predicament.

                 "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

      I have not used 'use strict' in my code. I just tried using it,it gave lot of such messages :( "Global symbol "@accums" requires explicit package name at " Please throw some light on how to fix this :(

        see strict

        If you tell me, I'll forget.
        If you show me, I'll remember.
        if you involve me, I'll understand.
        --- Author unknown to me
        Aside from logic problems, you have a "scope" problem with your "@accum" variable.

        You have declared it in the "while (my @accum=...)" statement, which makes it local to the while loop.

        You attempt to use it outside the while loop (where it does not exist), in the "foreach" statement.

        To correct the problem, the preferred method is to fix your logic.

        If you do not understand what your logic problem is, use globals, and suffer later.

        If you do not understand what I'm trying to say, please read up on variable scoping, and algorithms (these topics are fairly independent of the programming language you choose).

                     "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

        rkrish:

        If you add use diagnostics;, it will give more detailed error messages, and suggestions on what the problem is and/or potential fix(es) (IIRC).

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

Re: Can't modify int in scalar assignment error
by jwkrahn (Monsignor) on Dec 19, 2012 at 06:38 UTC
    int returnCode = SUCCESS;

    That looks like C code, not Perl code.    Perhaps you meant:

    my $returnCode = SUCCESS;


    if ( $returnCode != SUCCESS ) { return $return +Code; } return $returnCode;

    That makes little sense.    You are testing $returnCode but you return $returnCode whether it equals SUCCESS or not.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1009494]
Approved by tobyink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-10-25 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (145 votes), past polls