SPUG: assigning to slice of anon hash?

Jim Flanagan jimfl at colltech.com
Wed Jun 27 14:30:42 CDT 2001


--Also Sprache El JoPe Magnifico <jope-spug at jope.net> On Wednesday, June 
27, 2001 12:12 PM -0700:

     > Quick (hopefully) perl syntax question that I ran into last night.
     > You can assign to a slice of a hash with the following:
     >
     >   @hash{ @fields } = @values;
     >
     > However, I can't figure out how to do the same with a hash ref.
     > The following gives a runtime error, "Can't coerce array into hash",
     > since the @{$ref} construct is generally how you deref an array ref:
     >
     >   @{ $hash_ref }->{ @fields } = @values;
     >
     > And the following (which wouldn't be syntactically consistent,
     > but I tried just in case) doesn't do the trick either:
     >
     >   %{ $hash_ref }->{ @fields } = @values;

  You're close!

    @{$hashref}{@fields} = @values.

--
Jim Flanagan          Collective Technologies
jimfl at colltech.com   http://www.colltech.com

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





More information about the spug-list mailing list