in reply to Re^2: Return Value from sub
in thread Return Value from sub
When I try to run the code you posted, I only get these errors:
C:\>perl -w tmp.pl Name "main::IN" used only once: possible typo at tmp.pl line 8. Use of uninitialized value $id in seek at tmp.pl line 10. seek() on unopened filehandle In at tmp.pl line 10. readline() on unopened filehandle In at tmp.pl line 11. Use of uninitialized value $name in concatenation (.) or string at tmp +.pl line 3.
Please try to make sure that the code you post actually exhibits the problem you are trying to diagnose.
When I change your code to the following:
my $id= shift; my ($name) = seekName($id); print "$name\n"; sub seekName { my ($id) = $_[0]; open (IN, "<:utf8", $0) or die "Can't open: $!"; seek IN, $id, 0; my $line = <IN>; return $line; }
... it assigns $name a value depending on what number I give on the command line. So I would assume that this works and does not exhibit the problem of always printing 1.
|
|---|