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
In reply to Using array elements as subroutine args by Tuna
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |