I have this in my project:
sub get_src_info($) {
my $package = shift;
my ($key,$value,$tail) =("","","");
my (@APT_INFO,$r);
open APT, "apt-cache showsrc $package|";
while (<APT>){
chomp;
($key,$value,$tail) = split /:/;
if (defined ($key) && defined ($value)) {
$value =~ s/^\s+|\s+$//;
if (defined($tail)) {
$value = "$value:$tail";
}
if ( $key eq "Package" or $key eq "Version" ) {
$r->{$key} = $value;
}
}
if(/^$/) { push @APT_INFO,$r++; }
}
close APT;
return @APT_INFO;
}
I generally use use strict
to check for errors.
The code works with no strict "refs";
instruction, but fails to run without it, yielding error:
Can't use string ("163277181") as a HASH ref while "strict refs" in use at a.pl line 61, <APT> line 45.
line 61 is: $r->{$key} = $value;
I prefer to fix my code, rather than silence it, but can't get what's wrong/how to fix this.
Also, what's correct way to advance a reference to point to the next object? Although it works I do not feel like $r++
is correct construction in here.
thanks a lot in advance.