R
Roger
My code is this:
use warnings;
use strict;
my $number = my_rand();
print "The number is ".$number;
{ my $seed = 1;
sub my_rand (){
$seed = int(($seed * 1103515245 + 12345) / 65536) % 32768;
return $seed;
}
I derived it from an article here: (apparently wrong??)
http://perl.plover.com/FAQs/Namespaces.html#glos_lexical_variable
The issue is that declaring 'seed' inside the brackets as shown above yields an
error of:
main::my_rand() called too early to check prototype at test_scope.pl line 6.
Use of uninitialized value in multiplication (*) at test_scope.pl line 11.
Basically I understand local, and am working on 'my' ... it would seem as if
using 'my' one needs to always use it in a sub in the context of returning it as
an lvalue...
like:
my $number = my_rand();
but like I said the code above does not work the way they:
http://perl.plover.com/FAQs/Namespaces.html#glos_lexical_variable
said it should or I am missing the big picture. BTW before I posted I read
'Learning Perl' 3rd edition... and prehaps I *should* have 'got it' from that
the example URL I reference above has me scratching my head...
TIA
use warnings;
use strict;
my $number = my_rand();
print "The number is ".$number;
{ my $seed = 1;
sub my_rand (){
$seed = int(($seed * 1103515245 + 12345) / 65536) % 32768;
return $seed;
}
I derived it from an article here: (apparently wrong??)
http://perl.plover.com/FAQs/Namespaces.html#glos_lexical_variable
The issue is that declaring 'seed' inside the brackets as shown above yields an
error of:
main::my_rand() called too early to check prototype at test_scope.pl line 6.
Use of uninitialized value in multiplication (*) at test_scope.pl line 11.
Basically I understand local, and am working on 'my' ... it would seem as if
using 'my' one needs to always use it in a sub in the context of returning it as
an lvalue...
like:
my $number = my_rand();
but like I said the code above does not work the way they:
http://perl.plover.com/FAQs/Namespaces.html#glos_lexical_variable
said it should or I am missing the big picture. BTW before I posted I read
'Learning Perl' 3rd edition... and prehaps I *should* have 'got it' from that
the example URL I reference above has me scratching my head...
TIA