Tuna has asked for the wisdom of the Perl Monks concerning the following question:
I have some serious problems here:#!/usr/bin/perl -w use strict; my @array = (1, 2, 3, 4); my $string; my $item; foreach $item(@array) { &some_sub($item); } sub some_sub { if ($item = "1") { $string = "one"; } elsif ($item = "2" ) { $string = "two"; } elsif ($item = "3" ) { $string = "three"; } else { $string = "four" } print "My number is $string\n"; }
When I change "=" to "==", I get:Found = in conditional, should be == at ./testsub.pl line 22. Found = in conditional, should be == at ./testsub.pl line 19. Found = in conditional, should be == at ./testsub.pl line 16. My number is one My number is one My number is one My number is one
I suppose that I have two questions:Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. My number is four Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. My number is four Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. My number is four Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. Use of uninitialized value in numeric eq (==) at ./testsub.pl line 16. My number is four
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using array elements as subroutine args
by danger (Priest) on Feb 19, 2001 at 05:20 UTC | |
|
(dkubb) Re: (2) Using array elements as subroutine args
by dkubb (Deacon) on Feb 19, 2001 at 06:41 UTC | |
|
Re: Using array elements as subroutine args
by Coyote (Deacon) on Feb 19, 2001 at 05:15 UTC | |
|
Re: Using array elements as subroutine args
by Tuna (Friar) on Feb 19, 2001 at 05:37 UTC |