• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: object instance names generated on the fly?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: object instance names generated on the fly?


  • Subject: Re: object instance names generated on the fly?
  • From: Marcel Weiher <email@hidden>
  • Date: Sat, 22 Mar 2003 17:20:04 +0100

for(my $i=0; $i < 10; $i++) {
${'myobject' . $i} = new Foo;
}

The result would be ten instances of Foo, named $myobject0, $myobject1, etc.

This sort of thing is possible in Perl because variable names are accessible at runtime. In fact, the entire name space is implemented as a series of nested hash tables, which can be manipulated at run time. If you iterate over the keys of the hash named "%Foo::", for example, you'll get a list of all the names in package Foo.

yes you're right, that's exactly the type of thing i'm after

But that's just simulating an array (in a very roundabout way). Just use an NSArray.

Marcel


--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: object instance names generated on the fly?
      • From: Sherm Pendley <email@hidden>
References: 
 >Re: object instance names generated on the fly? (From: Ben Dougall <email@hidden>)

  • Prev by Date: Re: object instance names generated on the fly?
  • Next by Date: Re: object instance names generated on the fly?
  • Previous by thread: Re: object instance names generated on the fly?
  • Next by thread: Re: object instance names generated on the fly?
  • Index(es):
    • Date
    • Thread