develooper Front page | perl.perl6.language | Postings from January 2003

Re: Arrays: Default Values

From:
Juergen Boemmels
Date:
January 29, 2003 12:08
Subject:
Re: Arrays: Default Values
Message ID:
m23cnbg1o6.fsf@helium.physik.uni-kl.de
Jonathan Scott Duff <duff@cbi.tamucc.edu> writes:

> On Wed, Jan 29, 2003 at 08:49:42PM +0100, Juergen Boemmels wrote:
> > Solution 3: The autoset sets the value to the default value.
> > 
> >      my Int @a is default(5);
> > 
> >      @a[3] = 3;      # there are now 4 items in the array
> >      @a[2];          # was autoset 5 so returns 5
> >      @a[4];          # doesn't exist, so returns 5
> > 
> >      @a[2] = undef;  # set to undef, so returns undef
> 
> Can someone give me a realish world example of when you would want an
> array that can store both undefined values and default values and those
> values are different?

Ok, here is one

my float @weight_factor is default (1.0);

$weighted_sum = sum (@weight_factor »*« @a);

$weight_factor[4711] = 0.0;

bye
b.
-- 
Juergen Boemmels			boemmels@physik.uni-kl.de
Fachbereich Physik			Tel: ++49-(0)631-205-2817
Universitaet Kaiserslautern		Fax: ++49-(0)631-205-3906
PGP Key fingerprint = 9F 56 54 3D 45 C1 32 6F  23 F6 C7 2F 85 93 DD 47



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About