CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: warning message but code works anyway?: Edit Log



Wildcard
Novice

Oct 16, 2017, 6:39 AM


Views: 2967
warning message but code works anyway?

Hello there! :)
My compiler spits out a warning message but somehow the codes works fine anyway. The warning is:
Use of uninitialized value in concatenation (.) or string [..] at line 34

the code is the following:

Code
use strict;  
use warnings;

my $scal = "Hello";
my @array = ( 1, 2, 3);
my %hash = ("1" => "one", "2" => "two", "3" => "three", );


dumpit($scal);
dumpit(\@array);
dumpit(\%hash);

sub dumpit

{
my $ref = shift;
if (ref($ref) eq 'HASH')
{
print "HASH:\n";
foreach (sort (keys %{$ref}))
{
print "\t $_ => $ref->{$_} \n";
}
}

elsif (ref($ref) eq 'ARRAY')
{
print "ARRAY:\n";
for my $i (0 .. @{$ref})
{
print "\t $i: $ref->[$i] \n";
}
}

else
{
print "SKALAR:\n";
print "\t ${ref}\n";
}
}


It gives out the following:

Quote
SKALAR:
Hello
ARRAY:
0: 1
1: 2
2: 3
Use of uninitialized value in concatenation (.) or string at C:\Strawberry\perl\allerlei.pl line 34.
3:
HASH:
1 => one
2 => two
3 => three

I'm not sure but perhaps I neglected to define a boundary for the array iteration or something like that. Weird, the code works, but somehow I managed to mess up anyway. COuld someone explain what it does mean?


(This post was edited by Wildcard on Oct 16, 2017, 6:41 AM)


Edit Log:
Post edited by Wildcard (Novice) on Oct 16, 2017, 6:40 AM
Post edited by Wildcard (Novice) on Oct 16, 2017, 6:41 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives