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);
}
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
|
for ( $iterator ; $iterator < @$MapFile ; $iterator++ ) {
for ( $iterator = 1; $iterator < @$MapFile ; $iterator++ ) {
for ( ; $iterator < @$MapFile ; $iterator++ ) {
See also Why is the error thrown from close(FH) when the error is the missing <> on while(FH)?, Re: Why is the error thrown from close(FH) when the error is the missing <> on while(FH)? ( line number mismatch, look above, look before )(Bareword found in conditional) | [reply] [d/l] |
|
| [reply] [d/l] |
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 | [reply] [d/l] [select] |
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;
| [reply] [d/l] |
|
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
| [reply] [d/l] [select] |
|
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 }
| [reply] [d/l] |
|
|
|
$HTEC{$5} = {
'Start' => $1,
'End' => $2,
'Size' => $3,
'Symbol' => $4,
'Memory' => $6,
'OutputSection' => $7,
'InputSection' => $8,
'InputObject' => $9,
};
| [reply] [d/l] |
|
and while you're at it, drop the single quotes for barewords :)
$HTEC{perl}{is}{Perl}
| [reply] |
|
|