another way will be to define $test as local so all subs called from
the sub where is defined local $test has access to $test
Martin
On Mon, 3 Dec 2001 23:34:59 -0500 (EST), you wrote:
>On Tue, 4 Dec 2001, Daniel Falkenberg wrote:
>
>> Hi All,
>>
>> while(1) {
>> #Read from a sub outside of the while loop...
>> get_sub();
>> }
>>
>> get_sub {
>> print $test;
>> }
>>
>> I understand that the above code doesn't really say much but it gives a
>> brief understading of my problem. Baiscally when I compile the script I
>> get a compilation error saying...
>>
>> Name "main::test" used only once: possible typo at ./test line (n).
>
>Something tells me you aren't using the -w option and don't have 'use
>strict' at the top of your script, otherwise, you may have caught
>something like this.
>
>Where is $test declared and/or defined? Inside the sub or outside? If
>you declare and/or define $test outside the sub, then you should pass it
>into the sub as an argument:
>
>my $test = 0;
>while(1) {
>
> #do stuff
> get_sub($test);
>}
>
>sub get_sub {
>
> my $test_msg = shift;
> print $test_msg;
>}
>
>The basic idea, if I am following your problem, is to not use global
>variables inside of subs, if you can help it. It can lead to subtle bugs
>and cause unwanted side effects. There's nothing wrong wioth using a sub
>inside a loop -- if you need to process each element of an array or a
>hash, a loop is the best way to do it.
>
>-- Brett
> http://www.chapelperilous.net/
>------------------------------------------------------------------------
>The angry man always thinks he can do more than he can.
> -- Albertano of Brescia
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]