Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Can't get rid of: Useless use of private variable in void context

by tobias_hofer (Friar)
on Feb 25, 2013 at 09:43 UTC ( #1020476=perlquestion: print w/ replies, xml ) Need Help??
tobias_hofer has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I need help on an perl warning. I am looking at the code for hours but I can't figure out the problem

Perl is complaining about the useless use of a private variable in void context on line 157 (#2) (W void)

Here the code:
Its a sub for parsing the content of a map-file.
Line number 157 is marked by a comment.

Any help is welcome!!!

sub ProcessMapFile { my $self = shift; my $MapFile = $_[0]; my $PlaceToPutInformation = $_[1]; #Each config profile defines its own way how to parse the map-file +. my $iterator = $ProfileInformation->{'StartLine'}; #Process map-file for ( $iterator ; $iterator < @$MapFile ; $iterator++ ) { if ( $MapFile->[$iterator] =~ m! ^ #Begin with.. (\S+) #matiching non space character: START Memory \s+ #space characters (\S+) #matiching non space character: END Memory \s+ #space characters (\S+) #matiching non space character: Size \s+ #space characters (\S+) #matiching non space character: Symbol (g = glob +al, l = static) \s+ #space characters (\S+) #matiching non space character: Name \s+ #space characters (\S+) #matiching non space character: Memory \s+ #space characters (\S+) #matiching non space character: Output Section \s+ #space characters (\S+) #matiching non space character: Input Section \s+ #space characters (\S+) #matiching non space character: Input Object !x ) { #Process Zero sized (uninitialized) memory $PlaceToPutInformation->{'Maps'}{'HIGHTEC'}{$5} = { 'Start' => $1, 'End' => $2, 'Size' => $3, 'Symbol' => $4, 'Memory' => $6, 'OutputSection' => $7, 'InputSection' => $8, 'InputObject' => $9, }; $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OverallSize'} = + 0 if ( not exists $PlaceToPutInformation->{'Memory'}{'HIGHTEC'} {'OverallSize'} ); $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OverallSize'} = $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OverallSize'} + + $3; $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'Memory'}{$6} = +0 if ( not exists $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'Memo +ry'} {$6} ); $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'Memory'}{$6} = $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'Memory'}{$6} ++ $3; $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OutputSection'} +{$7} = 0 if ( not exists $PlaceToPutInformation->{'Memory'}{'HIGHTEC'} {'OutputSection'}{$7} ); $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OutputSection'} +{$7} = $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OutputSection +'} {$7} + $3; } else { last; } } # This is line 157 #Create Array of Names for quick check! my @a = keys( %{ $PlaceToPutInformation->{'Maps'}{'HIGHTEC'} } ); $PlaceToPutInformation->{'SymbolCollection'}{'HIGHTEC'} = \@a if ( +@a); }

Comment on Can't get rid of: Useless use of private variable in void context
Download Code
Re: Can't get rid of: Useless use of private variable in void context
by tmharish (Friar) on Feb 25, 2013 at 09:54 UTC

    Update:

    This is about my stupidest post - the long assignments got me totally confused with where each statement begins and ends.

    Anon below has hit the nail on the head - I probably need someone to hit me on the head as well!

    Please ignore rest of this post.

    Original post - Please ignore

    Some of your ifs are ; terminated and some assignments might be missing a ; - not sure if you actually want that:

    My comments start with '##'

    $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OverallSize'} = 0 if ( not exists $PlaceToPutInformation->{'Memory'}{ +'HIGHTEC'} {'OverallSize'} ); ## If closed here - useless use of ... $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OverallSize'} = $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OverallSize'} + + $3; $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'Memory'}{$6} = +0 ## Possible ; missing if ( not exists $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'Memo +ry'} {$6} ); ## If closed here - useless use of ... $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'Memory'}{$6} = $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'Memory'}{$6} + +$3; $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OutputSection'} +{$7} = 0 ## Possible ; missing if ( not exists $PlaceToPutInformation->{'Memory'}{'HIGHTEC'} {'OutputSection'}{$7} ); ## If closed here - useless use o +f ... $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OutputSection'} +{$7} = $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}{'OutputSection'} +{$7} + $3;

    Cant do better unless there is test input

Re: Can't get rid of: Useless use of private variable in void context (look up, look above, look before)
by Anonymous Monk on Feb 25, 2013 at 09:58 UTC

      Thanks a lot!
      yes, it has been the iterator variable.
      I have put the definition into the for(.. , and its working fine.

      Many Thanks and best regards!
      Tobias

Re: Can't get rid of: Useless use of private variable in void context
by Anonymous Monk on Feb 25, 2013 at 10:08 UTC
    #Process Zero sized (uninitialized) memory $PlaceToPutInformation->{'Maps'}{'HIGHTEC'}{$5} = { 'Start' => $1, 'End' => $2, 'Size' => $3, 'Symbol' => $4, 'Memory' => $6, 'OutputSection' => $7, 'InputSection' => $8, 'InputObject' => $9, }; local *HTEC = $PlaceToPutInformation->{'Memory'}{'HIGHTEC'}; $HTEC{'OverallSize'} ||= 0; $HTEC{'OverallSize'} = $HTEC{'OverallSize'} + $3; $HTEC{'Memory'}{$6} ||= 0; $HTEC{'Memory'}{$6} = $HTEC{'Memory'}{$6} + $3; $HTEC{'OutputSection'}{$7} ||= 0; $HTEC{'OutputSection'}{$7} = $HTEC{'OutputSection'}{$7} + $3;
      Bah, start short too :)
      $HTEC{$5} = { 'Start' => $1, 'End' => $2, 'Size' => $3, 'Symbol' => $4, 'Memory' => $6, 'OutputSection' => $7, 'InputSection' => $8, 'InputObject' => $9, };
        and while you're at it, drop the single quotes for barewords :)

        $HTEC{perl}{is}{Perl}

      Yes, much more beautiful!
      sadly I still got to use perl 5.10 so local *HTEC... is not working

      However, the  ||= 0 version makes the code much more better and makes me get rid of all the if statements!
      I will use it that way!
      Thanks a lot!

      Cheers!

      Tobias

        sadly I still got to use perl 5.10 so local *HTEC... is not working

        Sure it is, it worked since the very first perl5, at least

        perl -MData::Dump -e" dd $f={2,{4,{6,8}}}; local *H=$$f{2}{4}; dd\%H" { 2 => { 4 => { 6 => 8 } } } { 6 => 8 }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-12-27 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls