Re: Variable in for loop is not automatically local?

2009-05-02 Thread John W. Krahn
Kelly Jones wrote: If I do a for loop in a subroutine, do I have to declare it private with my()? I always though for() did that for me, but I ran into a bug where code like this: sub foo {for $i (1..2) {print $i;}} affected my global $i (I think). Or was I imagining it? The variable in a for

Re: Variable in for loop is not automatically local?

2009-05-02 Thread Gunnar Hjalmarsson
Kelly Jones wrote: If I do a for loop in a subroutine, do I have to declare it private with my()? I always though for() did that for me, but I ran into a bug where code like this: sub foo {for $i (1..2) {print $i;}} affected my global $i (I think). Or was I imagining it? Probably, since $i ou

Variable in for loop is not automatically local?

2009-05-02 Thread Kelly Jones
If I do a for loop in a subroutine, do I have to declare it private with my()? I always though for() did that for me, but I ran into a bug where code like this: sub foo {for $i (1..2) {print $i;}} affected my global $i (I think). Or was I imagining it? -- We're just a Bunch Of Regular Guys, a c

RE: A Problem Using Hashes

2009-05-02 Thread David Christensen
Thomas H. George wrote: > The difficulty is in the next to last line, the 'unless ...' > statement which causes warning: > Use of uninitialized value in string eq at chap4-take6.pl line 49. Some debugging hints: 1. Set the output autoflush ($|) Perl variable to a true value near the top of your

Re: A Problem Using Hashes

2009-05-02 Thread John W. Krahn
Thomas H. George wrote: I am inching my way through INTERMEDIATE PERL and tried using hashes to solve Chapter 4, Problem 2. I never used hashes before but my attempted solution convinced me of their value as contrasted to the solution with arrays. The Problem: My solution works but with an err

Re: A Problem Using Hashes

2009-05-02 Thread jaime sanmartin
Hope this helps you... #!/usr/bin/perl -w # formatted with perltidy use warnings;# I always use this use strict; my %required_list = ( life_jacket => 'preserver', lotion => 'sunscreen', water => 'water_bottle', coat=> 'jacket', ); my %captain = ( name

A Problem Using Hashes

2009-05-02 Thread Thomas H. George
I am inching my way through INTERMEDIATE PERL and tried using hashes to solve Chapter 4, Problem 2. I never used hashes before but my attempted solution convinced me of their value as contrasted to the solution with arrays. The Problem: My solution works but with an error I can't eliminate. The