in reply to print problem
No strict and no warnings means that you are not alerted to the mistake of passing the bareword names to which_element_is().
use strict; use warnings; my @array = qw /fred barney betty dino wilma pebbles bamm-bamn/; my $result = which_element_is ("dino", @array); sub which_element_is { my ($what, @array) = @_; foreach (0 .. $#array) { if ($what eq $array[$_]) { print "$_\n"; return $_; } } print "99\n"; -1; } print "Item $result is $array[$result]\n"
Always use strict and warnings. Always.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: print problem
by yueli711 (Sexton) on May 08, 2018 at 13:53 UTC |