Re: accessing variables in subroutines

2013-06-28 Thread Shlomi Fish
Hi Lee, On Fri, 28 Jun 2013 15:15:27 +0200 lee wrote: > timothy adigun <2teezp...@gmail.com> writes: > > use strict; > use warnings; > > > sub test { > print $counter . "\n"; > } > > > my $counter = 0; > while($counter < 5) { >

Re: accessing variables in subroutines

2013-06-28 Thread lee
timothy adigun <2teezp...@gmail.com> writes: use strict; use warnings; sub test { print $counter . "\n"; } my $counter = 0; while($counter < 5) { test(); $counter++; } It says "Global symbol "$counter"

Re: accessing variables in subroutines

2013-06-27 Thread Dr.Ruud
On 27/06/2013 15:44, Shawn H Corey wrote: On Thu, 27 Jun 2013 15:07:58 +0200 "Dr.Ruud" wrote: On 27/06/2013 12:58, lee wrote: Ok, so perl has a totally broken design with variables :( No, your understanding is broken. Can you come back after you fixed it? That is rude. The reason this li

Re: accessing variables in subroutines

2013-06-27 Thread Andy Bach
On Thu, Jun 27, 2013 at 11:22 AM, Rob Dixon wrote: > Something like this may help you > > use strict; > use warnings; > > do_something({ title => 'TEST', value => 42 }); > > sub do_something { > my ($params) = @_; > print $params->{title}, "\n"; > do_something_el

Re: accessing variables in subroutines

2013-06-27 Thread Rob Dixon
On 27/06/2013 11:58, lee wrote: Shlomi Fish writes: lee wrote: the following example doesn't compile: use strict; use warnings; sub test { print $counter . "\n"; } my $counter = 0; while($counter < 5) { test(); $counter++; } It says "Global symbol "$counter" requires exp

Re: accessing variables in subroutines

2013-06-27 Thread Brandon McCaig
On Thu, Jun 27, 2013 at 12:58:38PM +0200, lee wrote: > The subroutine is never called before $counter is declared, so > it is always available to the subroutine. There should be an > error only for instances when the subroutine is called before > $counter is declared. Much like in C or C++ (and m

Re: accessing variables in subroutines

2013-06-27 Thread John SJ Anderson
> That is rude. The reason this list exists is to help people, not to > tell them to go away. No wonder Perl is not a popular language. Agreed. Dr. Ruud, that was uncalled for. You're not obligated to respond to posters, and if that's the best response you have, not responding would be a better ch

Re: accessing variables in subroutines

2013-06-27 Thread Shawn H Corey
On Thu, 27 Jun 2013 15:07:58 +0200 "Dr.Ruud" wrote: > On 27/06/2013 12:58, lee wrote: > > > Ok, so perl has a totally broken design with variables :( > > No, your understanding is broken. Can you come back after you fixed > it? > That is rude. The reason this list exists is to help people, no

Re: accessing variables in subroutines

2013-06-27 Thread timothy adigun
Hi, On 6/27/13, lee wrote: > Shlomi Fish writes: > >> Hi Lee, >> >> On Wed, 26 Jun 2013 10:18:44 +0200 >> lee wrote: >> >>> Hi, >>> >>> the following example doesn't compile: >>> >>> >>> use strict; >>> use warnings; >>> >>> >>> sub test { >>> print $counter . "\n"; >>> } >>> >>> >>> my $cou

Re: accessing variables in subroutines

2013-06-27 Thread Dr.Ruud
On 27/06/2013 12:58, lee wrote: Ok, so perl has a totally broken design with variables :( No, your understanding is broken. Can you come back after you fixed it? -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http:/

Re: accessing variables in subroutines

2013-06-27 Thread Shawn H Corey
On Thu, 27 Jun 2013 12:58:38 +0200 lee wrote: > Ok, so perl has a totally broken design with variables :( What's the > solution to this problem? The usual technique is to declare the configuration variables at the top, followed by the file-scoped variables. It is convention that these variable

Re: accessing variables in subroutines

2013-06-27 Thread lee
Shlomi Fish writes: > Hi Lee, > > On Wed, 26 Jun 2013 10:18:44 +0200 > lee wrote: > >> Hi, >> >> the following example doesn't compile: >> >> >> use strict; >> use warnings; >> >> >> sub test { >> print $counter . "\n"; >> } >> >> >> my $counter = 0; >> while($counter < 5) { >> te

Re: accessing variables in subroutines

2013-06-26 Thread timothy adigun
Hi On 26 Jun 2013 09:49, "lee" wrote: > > Hi, > > the following example doesn't compile: > > > use strict; > use warnings; > > > sub test { > print $counter . "\n"; The variable $counter is not known here > } > > > my $counter = 0; > while($counter < 5) { > test(); > $counter++; > } >

Re: accessing variables in subroutines

2013-06-26 Thread Shlomi Fish
Hi Lee, On Wed, 26 Jun 2013 10:18:44 +0200 lee wrote: > Hi, > > the following example doesn't compile: > > > use strict; > use warnings; > > > sub test { > print $counter . "\n"; > } > > > my $counter = 0; > while($counter < 5) { > test(); > $counter++; > } > > > It says "Gl

Re: accessing variables in subroutines

2013-06-26 Thread bill pemberton
Scope? On Wednesday, June 26, 2013, lee wrote: > Hi, > > the following example doesn't compile: > > > use strict; > use warnings; > > > sub test { > print $counter . "\n"; > } > > > my $counter = 0; > while($counter < 5) { > test(); > $counter++; > } > > > It says "Global symbol "$cou

accessing variables in subroutines

2013-06-26 Thread lee
Hi, the following example doesn't compile: use strict; use warnings; sub test { print $counter . "\n"; } my $counter = 0; while($counter < 5) { test(); $counter++; } It says "Global symbol "$counter" requires explicit package name ...". When I put the subroutine after the 'whil