SPUG: 'my' question :)

Alyssa Harding axhard2 at uswest.com
Thu May 18 13:14:10 CDT 2000


I encountered something wierd yesterday and I wonder if someone
could explain why this happens.

I had a script which was doing something like this:
  #!/usr/bin/perl -w 
  
  ...

  foreach $pair (@pairs){
    ($name, $value) = split(/&/, $buffer);
     $hash{$name} = $value;
  }

  ...
  This got me a nice hash with values and everything.

Okay, not too complicated or anything, but it wasn't using strict
(and it had no reason for not doing so).  So I changed it to use
strict;

  #!/usr/bin/perl -w 

  use strict;

  ...
  my %hash;
  foreach my $pair( @pairs ){
    my($name, $value) = split(/&/, $buffer );
    $hash{$name} = $value;
  }
 

  The resulting hash gets only one key/value pair - $pairs[0] - and
nothing else.
  Can someone please explain why this happens?  Shouldn't it work
just as well?

  I changed it to:
  
  #!/usr/bin/perl

  use strict;
  ...
  my(%hash, $pair);
  foreach $pair( @pairs ){
   etc. etc.
  }

  and it worked just fine.

A.
-- 
Alyssa W. Harding 
Web Programmer
U S WEST Creative Services
phon: (206) 345-4073
cell: (206) 769-8735
-------------------------------------------------------------------
People who didn't need people needed people around to know that they
were
the kind of people who didn't need people.
        -- (Terry Pratchett, Maskerade)

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 For Subscriptions, Email to majordomo at pm.org:  ACTION  spug-list  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email address





More information about the spug-list mailing list