The code you've posted does not display the error to describe. If I run the following (lightly modified)
#!/usr/bin/perl
use strict;
use warnings;
&populatemessagedefs(undef, '1,2,3,4,5,6');
sub populatemessagedefs()
{
my ($ref_to_msg_defs,$Everythingelse) = @_;
my $temp_value;
my $temp_key;
my @Interface_Message_List = split (',',$Everythingelse);
my $i=0;
my %ref_to_msg_defs;
foreach my $field(@Interface_Message_List) {
print "$i\n";
#In next iteration $i is ‘0’ again
if ($i == 0) {
$temp_key = $field;
$i++;
#Value of $i is 1 now
}
elsif ($i == 1) {
$temp_value = $field;
if (exists $ref_to_msg_defs->{$temp_key}) {
if ($field > $ref_to_msg_defs->{$temp_key}) {
$ref_to_msg_defs{$temp_key} = $field;
$i--;
}
}
else {
$ref_to_msg_defs{$temp_key} = $field;
$i--;
}
}
}
}
I get
0
1
0
1
0
1
which I'd expect. Two items of note for you:
- You are using Prototypes incorrectly by declaring your subroutine with sub populatemessagedefs(). You expect two scalar arguments, not zero as you've written there. Unless you know what prototypes are and what they are not, you should really replace that line with sub populatemessagedefs.
- You never use $ref_to_msg_defs, which I assume is a hash reference. Rather, in your code you use $ref_to_msg_defs{$temp_key}, which accesses the hash %ref_to_msg_defs, which is not declared in your code. In order to run under strict, I had to declare the appropriate local hash.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.