Re: scoping problem with hash

2006-06-16 Thread Mr. Shawn H. Corey
On Fri, 2006-16-06 at 12:15 +0200, Paul Johnson wrote: > On Tue, Jun 13, 2006 at 12:06:02PM -0700, Lawrence Statton wrote: > > > Charles Clarkson wrote: > > > @{ %$hash_ref }{ keys %kv_pairs } = values %kv_pairs; > > > > You can excise a little of the snyactic sugar there > > > > @$hash_ref{

Re: scoping problem with hash

2006-06-16 Thread John W. Krahn
Beginner wrote: > On 16 Jun 2006 at 12:15, Paul Johnson wrote: > >>On Tue, Jun 13, 2006 at 12:06:02PM -0700, Lawrence Statton wrote: >> >>>Charles Clarkson wrote: @{ %$hash_ref }{ keys %kv_pairs } = values %kv_pairs; >>>You can excise a little of the snyactic sugar there >>> >>>@$hash_ref{

Re: scoping problem with hash

2006-06-16 Thread Beginner
On 16 Jun 2006 at 12:15, Paul Johnson wrote: > On Tue, Jun 13, 2006 at 12:06:02PM -0700, Lawrence Statton wrote: > > > Charles Clarkson wrote: > > > @{ %$hash_ref }{ keys %kv_pairs } = values %kv_pairs; > > > > You can excise a little of the snyactic sugar there > > > > @$hash_ref{keys %kv_

Re: scoping problem with hash

2006-06-16 Thread Paul Johnson
On Tue, Jun 13, 2006 at 12:06:02PM -0700, Lawrence Statton wrote: > Charles Clarkson wrote: > > @{ %$hash_ref }{ keys %kv_pairs } = values %kv_pairs; > > You can excise a little of the snyactic sugar there > > @$hash_ref{keys %kv_pairs} = values %kv_pairs; %hash = (%hash, %kv_pairs); hmmm,

Re: scoping problem with hash

2006-06-15 Thread Lawrence Statton
Charles Clarkson wrote: > @{ %$hash_ref }{ keys %kv_pairs } = values %kv_pairs; You can excise a little of the snyactic sugar there @$hash_ref{keys %kv_pairs} = values %kv_pairs; -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Lawrence Statton - [EMAIL PROTECTED] s

RE: scoping problem with hash

2006-06-13 Thread Charles K. Clarkson
Mr. Shawn H. Corey wrote: : for ( keys %kv_pairs ){ : $hash_ref->{$_} = $kv_pairs{$_}; : } You could use a hash slice there. @{ %$hash_ref }{ keys %kv_pairs } = values %kv_pairs; HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-

Re: scoping problem with hash

2006-06-13 Thread Mr. Shawn H. Corey
On Tue, 2006-13-06 at 13:08 -0400, Mr. Shawn H. Corey wrote: > $times{$hashkey}{home} = $time; > $times{hashkey}{total} = $total; > > # Your code replaces, not augments Consider adding this to your library of useful Perl utilities: # -- # hset %hash, ( $ke

Re: scoping problem with hash

2006-06-13 Thread Mr. Shawn H. Corey
On Tue, 2006-13-06 at 17:20 +0100, [EMAIL PROTECTED] wrote: > Hi, > > This is a bit of an extension on an earlier post. > > I am trying to create a data structure from a file (contents below). It is > meant to be a hash of > hashes but I suspect there is either a typo somewhere or I am hitting

Re: scoping problem with hash

2006-06-13 Thread Dermot Paikkos
On 13 Jun 2006 at 12:27, Mr. Shawn H. Corey wrote: > On Tue, 2006-13-06 at 17:20 +0100, [EMAIL PROTECTED] wrote: > > print STDERR Dumper(%times); > > print STDERR Dumper( \%times ); That seems to have helped the Dumper output but I still haven't managed to get the other assignments to stick.

Re: scoping problem with hash

2006-06-13 Thread Mr. Shawn H. Corey
On Tue, 2006-13-06 at 17:20 +0100, [EMAIL PROTECTED] wrote: > print STDERR Dumper(%times); print STDERR Dumper( \%times ); -- __END__ Just my 0.0002 million dollars worth, --- Shawn "For the things we have to learn before we can do them, we learn by doing them." Aristotle * Perl t

Re: Scoping question

2002-09-19 Thread Michael Fowler
On Thu, Sep 19, 2002 at 09:39:54AM +0100, Gary Stainburn wrote: > I've got a problem understanding a scoping issue I've got. http://perl.plover.com/FAQs/Namespaces.html is a good online resource for learning about scoping. > I've got 2 hashes which I defined inside the sub that generates the f

Re: Scoping question

2002-09-19 Thread david
Gary Stainburn wrote: > Hi all, > > I've got a problem understanding a scoping issue I've got. > > I've got 2 hashes which I defined inside the sub that generates the form > thus: > > sub do_form() { > my ($error)=@_; > my %dships=('X'=>'','L'=>'Leeds','D'=>'Doncaster'); > my %depts=('X'

Re: $_ scoping

2002-02-25 Thread birgit kellner
--On Montag, 25. Februar 2002 10:24 -0900 Michael Fowler <[EMAIL PROTECTED]> wrote: > On Mon, Feb 25, 2002 at 07:45:30PM +0100, Birgit Kellner wrote: >> for (@array) { # contains a bunch of numbers >> my %hash = &get_record($_); >> } > Are you under the mistaken impression that 'for' is no

Re: $_ scoping

2002-02-25 Thread birgit kellner
--On Montag, 25. Februar 2002 10:24 -0900 Michael Fowler <[EMAIL PROTECTED]> wrote: > On Mon, Feb 25, 2002 at 07:45:30PM +0100, Birgit Kellner wrote: >> for (@array) { # contains a bunch of numbers >> my %hash = &get_record($_); >> } > Are you under the mistaken impression that 'for' is no

Re: $_ scoping

2002-02-25 Thread Luke Bakken
> Small question: I thought when doing a for loop over an array, I can simply > do this: > for (@array) { # do stuff with $_ } for my $ele (@array) { # stuff with $ele } In 99.99% of the perl programs you write you'll use my instead of local. In fact, if you think you need to use local with a va

Re: $_ scoping

2002-02-25 Thread Michael Fowler
On Mon, Feb 25, 2002 at 07:45:30PM +0100, Birgit Kellner wrote: > for (@array) { # contains a bunch of numbers > my %hash = &get_record($_); > } > foreach (@array) { print "$_\n";\ # problem - $_ is not the array element anymore It isn't? $\ = "\n"; my @array = qw(foo bar baz qux);

Re: $_ scoping

2002-02-25 Thread Peter Scott
At 07:45 PM 2/25/02 +0100, Birgit Kellner wrote: >Small question: I thought when doing a for loop over an array, I can >simply do this: >for (@array) { # do stuff with $_ } > >Now I have this situation: > >for (@array) { # contains a bunch of numbers > my %hash = &get_record($_); >} >fore

Re: $_ scoping

2002-02-25 Thread Paul Johnson
On Mon, Feb 25, 2002 at 07:45:30PM +0100, Birgit Kellner wrote: > Small question: I thought when doing a for loop over an array, I can simply > do this: > for (@array) { # do stuff with $_ } > > Now I have this situation: > > for (@array) { # contains a bunch of numbers > my %hash = &get_

RE: $_ scoping

2002-02-25 Thread Lyon, Justin
Yeah, for normal variables, you can declare them "local", but I'm not sure you can do that with $_. Try it by adding "local($_);" to the first line of your subroutine. Otherwise, it will get overwritten, and you may have to declare a variable to do what you want to do. Justin -Original Mes