develooper Front page | perl.perl5.porters | Postings from December 2000

[PATCH] Idea: Declare multiple constants at once (fwd)

From:
Casey R. Tweten
Date:
December 29, 2000 09:03
Subject:
[PATCH] Idea: Declare multiple constants at once (fwd)
Message ID:
Pine.OSF.4.21.0012291201150.17186-100000@home.kiski.net
Please don't forget the tests :-)

The previous message was an accident, please forget about it.

-- 

---------- Forwarded message ----------
Date: Thu, 21 Dec 2000 17:45:31 -0500 (EST)
From: Casey R. Tweten <crt@kiski.net>
To: perl5-porters@perl.org
Cc: Tom Phoenix <rootbeer@teleport.com>
Subject: [PATCH] Idea: Declare multiple constants at once


  
*** t/pragma/constant.t.orig	Thu Dec 21 15:45:16 2000
--- t/pragma/constant.t	Thu Dec 21 17:12:12 2000
***************
*** 14,20 ****
  
  ######################### We start with some black magic to print on failure.
  
! BEGIN { $| = 1; print "1..73\n"; }
  END {print "not ok 1\n" unless $loaded;}
  use constant 1.01;
  $loaded = 1;
--- 14,20 ----
  
  ######################### We start with some black magic to print on failure.
  
! BEGIN { $| = 1; print "1..82\n"; }
  END {print "not ok 1\n" unless $loaded;}
  use constant 1.01;
  $loaded = 1;
***************
*** 229,231 ****
--- 229,251 ----
  test 72, (shift @warnings) =~ /^Constant name 'INC' is forced into package main:: at/;
  test 73, (shift @warnings) =~ /^Constant name 'SIG' is forced into package main:: at/;
  @warnings = ();
+ 
+ 
+ use constant {
+ 	THREE  => 3,
+ 	FAMILY => [ qw( John Jane Sally ) ],
+ 	AGES   => { John => 33, Jane => 28, Sally => 3 },
+ 	RFAM   => [ [ qw( John Jane Sally ) ] ],
+ 	SPIT   => sub { shift },
+ 	PHFAM  => [ { John => 1, Jane => 2, Sally => 3 }, 33, 28, 3 ],
+ };
+ 
+ test 74, @{+FAMILY} == THREE;
+ test 75, @{+FAMILY} == @{RFAM->[0]};
+ test 76, FAMILY->[2] eq RFAM->[0]->[2];
+ test 77, AGES->{FAMILY->[1]} == 28;
+ test 78, PHFAM->{John} == AGES->{John};
+ test 79, PHFAM->[3] == AGES->{FAMILY->[2]};
+ test 80, @{+PHFAM} == SPIT->(THREE+1);
+ test 81, THREE**3 eq SPIT->(@{+FAMILY}**3);
+ test 82, AGES->{FAMILY->[THREE-1]} == PHFAM->[THREE];

-- 
print(join(' ', qw(Casey R. Tweten)));my $sig={mail=>'crt@kiski.net',site=>
'http://home.kiski.net/~crt'};print "\n",'.'x(length($sig->{site})+6),"\n";
print map{$_.': '.$sig->{$_}."\n"}sort{$sig->{$a}cmp$sig->{$b}}keys%{$sig};
my $VERSION = '0.01'; #'patched' by Jerrad Pierce <belg4mit at MIT dot EDU>




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