Remove all uses of $[, both reads and writes, from library code.
Test code (which must test behaviour of $[) is unchanged, as is the
actual implementation of $[. Uses in CPAN libraries are also untouched:
I've opened tickets at rt.cpan.org regarding them.
if ($#$v >= 0) {
$short = $sp . "0..$#{$v} " .
join(" ",
- map {exists $v->[$_] ? $self->stringify($v->[$_]) : "empty"} ($[..$tArrayDepth)
+ map {exists $v->[$_] ? $self->stringify($v->[$_]) : "empty"} (0..$tArrayDepth)
) . "$shortmore";
} else {
$short = $sp . "empty array";
}
(print "$short\n"), return if length $short <= $self->{compactDump};
}
- for my $num ($[ .. $tArrayDepth) {
+ for my $num (0 .. $tArrayDepth) {
return if $DB::signal and $self->{stopDbSignal};
print "$sp$num ";
if (exists $v->[$num]) {
local(*domain) = @_;
shift(@_);
@cmp = @_;
- local($[) = 0;
foreach $name (@_) {
@extra = split(//,$name);
$abbrev = shift(@extra);
# routine shamelessly borrowed from the perl debugger.
sub assert {
- &panic("ASSERTION BOTCHED: $_[$[]",$@) unless eval $_[$[];
+ &panic("ASSERTION BOTCHED: $_[0]",$@) unless eval $_[0];
}
sub panic {
# negation
sub main'fneg { #(fnum_str) return fnum_str
- local($_) = &'fnorm($_[$[]);
+ local($_) = &'fnorm($_[0]);
vec($_,0,8) ^= ord('+') ^ ord('-') unless $_ eq '+0E+0'; # flip sign
if ( ord("\t") == 9 ) { # ascii
s/^H/N/;
# absolute value
sub main'fabs { #(fnum_str) return fnum_str
- local($_) = &'fnorm($_[$[]);
+ local($_) = &'fnorm($_[0]);
s/^-/+/; # mash sign
$_;
}
# multiplication
sub main'fmul { #(fnum_str, fnum_str) return fnum_str
- local($x,$y) = (&'fnorm($_[$[]),&'fnorm($_[$[+1]));
+ local($x,$y) = (&'fnorm($_[0]),&'fnorm($_[1]));
if ($x eq 'NaN' || $y eq 'NaN') {
'NaN';
} else {
\f
# addition
sub main'fadd { #(fnum_str, fnum_str) return fnum_str
- local($x,$y) = (&'fnorm($_[$[]),&'fnorm($_[$[+1]));
+ local($x,$y) = (&'fnorm($_[0]),&'fnorm($_[1]));
if ($x eq 'NaN' || $y eq 'NaN') {
'NaN';
} else {
# subtraction
sub main'fsub { #(fnum_str, fnum_str) return fnum_str
- &'fadd($_[$[],&'fneg($_[$[+1]));
+ &'fadd($_[0],&'fneg($_[1]));
}
# division
# result has at most max(scale, length(dividend), length(divisor)) digits
sub main'fdiv #(fnum_str, fnum_str[,scale]) return fnum_str
{
- local($x,$y,$scale) = (&'fnorm($_[$[]),&'fnorm($_[$[+1]),$_[$[+2]);
+ local($x,$y,$scale) = (&'fnorm($_[0]),&'fnorm($_[1]),$_[2]);
if ($x eq 'NaN' || $y eq 'NaN' || $y eq '+0E+0') {
'NaN';
} else {
if ( $cmp < 0 ||
($cmp == 0 &&
( $rnd_mode eq 'zero' ||
- ($rnd_mode eq '-inf' && (substr($q,$[,1) eq '+')) ||
- ($rnd_mode eq '+inf' && (substr($q,$[,1) eq '-')) ||
+ ($rnd_mode eq '-inf' && (substr($q,0,1) eq '+')) ||
+ ($rnd_mode eq '+inf' && (substr($q,0,1) eq '-')) ||
($rnd_mode eq 'even' && $q =~ /[24680]$/) ||
($rnd_mode eq 'odd' && $q =~ /[13579]$/) )) ) {
$q; # round down
} else {
- &'badd($q, ((substr($q,$[,1) eq '-') ? '-1' : '+1'));
+ &'badd($q, ((substr($q,0,1) eq '-') ? '-1' : '+1'));
# round up
}
}
# round the mantissa of $x to $scale digits
sub main'fround { #(fnum_str, scale) return fnum_str
- local($x,$scale) = (&'fnorm($_[$[]),$_[$[+1]);
+ local($x,$scale) = (&'fnorm($_[0]),$_[1]);
if ($x eq 'NaN' || $scale <= 0) {
$x;
} else {
if (length($xm)-1 <= $scale) {
$x;
} else {
- &norm(&round(substr($xm,$[,$scale+1),
- "+0".substr($xm,$[+$scale+1,1),"+10"),
+ &norm(&round(substr($xm,0,$scale+1),
+ "+0".substr($xm,$scale+1,1),"+10"),
$xe+length($xm)-$scale-1);
}
}
\f
# round $x at the 10 to the $scale digit place
sub main'ffround { #(fnum_str, scale) return fnum_str
- local($x,$scale) = (&'fnorm($_[$[]),$_[$[+1]);
+ local($x,$scale) = (&'fnorm($_[0]),$_[1]);
if ($x eq 'NaN') {
'NaN';
} else {
# we'll pass a non-normalized "-0" to &round when rounding
# -0.006 (for example), purely so that &round won't lose
# the sign.
- &norm(&round(substr($xm,$[,1).'0',
- "+0".substr($xm,$[+1,1),"+10"), $scale);
+ &norm(&round(substr($xm,0,1).'0',
+ "+0".substr($xm,1,1),"+10"), $scale);
} else {
- &norm(&round(substr($xm,$[,$xe),
- "+0".substr($xm,$[+$xe,1),"+10"), $scale);
+ &norm(&round(substr($xm,0,$xe),
+ "+0".substr($xm,$xe,1),"+10"), $scale);
}
}
}
# returns undef if either or both input value are not numbers
sub main'fcmp #(fnum_str, fnum_str) return cond_code
{
- local($x, $y) = (&'fnorm($_[$[]),&'fnorm($_[$[+1]));
+ local($x, $y) = (&'fnorm($_[0]),&'fnorm($_[1]));
if ($x eq "NaN" || $y eq "NaN") {
undef;
} else {
ord($y) <=> ord($x)
||
( local($xm,$xe,$ym,$ye) = split('E', $x."E$y"),
- (($xe <=> $ye) * (substr($x,$[,1).'1')
+ (($xe <=> $ye) * (substr($x,0,1).'1')
|| &bigint'cmp($xm,$ym))
);
}
\f
# square root by Newtons method.
sub main'fsqrt { #(fnum_str[, scale]) return fnum_str
- local($x, $scale) = (&'fnorm($_[$[]), $_[$[+1]);
+ local($x, $scale) = (&'fnorm($_[0]), $_[1]);
if ($x eq 'NaN' || $x =~ /^-/) {
'NaN';
} elsif ($x eq '+0E+0') {
local($_) = @_;
s/\s+//g; # strip white space
if (s/^([+-]?)0*(\d+)$/$1$2/) { # test if number
- substr($_,$[,0) = '+' unless $1; # Add missing sign
+ substr($_,0,0) = '+' unless $1; # Add missing sign
s/^-0/+0/;
$_;
} else {
# Assumes normalized value as input.
sub internal { #(num_str) return int_num_array
local($d) = @_;
- ($is,$il) = (substr($d,$[,1),length($d)-2);
- substr($d,$[,1) = '';
+ ($is,$il) = (substr($d,0,1),length($d)-2);
+ substr($d,0,1) = '';
($is, reverse(unpack("a" . ($il%5+1) . ("a5" x ($il/5)), $d)));
}
\f
# Compares 2 values. Returns one of undef, <0, =0, >0. (suitable for sort)
sub main'bcmp { #(num_str, num_str) return cond_code
- local($x,$y) = (&'bnorm($_[$[]),&'bnorm($_[$[+1]));
+ local($x,$y) = (&'bnorm($_[0]),&'bnorm($_[1]));
if ($x eq 'NaN') {
undef;
} elsif ($y eq 'NaN') {
}
sub main'badd { #(num_str, num_str) return num_str
- local(*x, *y); ($x, $y) = (&'bnorm($_[$[]),&'bnorm($_[$[+1]));
+ local(*x, *y); ($x, $y) = (&'bnorm($_[0]),&'bnorm($_[1]));
if ($x eq 'NaN') {
'NaN';
} elsif ($y eq 'NaN') {
}
sub main'bsub { #(num_str, num_str) return num_str
- &'badd($_[$[],&'bneg($_[$[+1]));
+ &'badd($_[0],&'bneg($_[1]));
}
# GCD -- Euclids algorithm Knuth Vol 2 pg 296
sub main'bgcd { #(num_str, num_str) return num_str
- local($x,$y) = (&'bnorm($_[$[]),&'bnorm($_[$[+1]));
+ local($x,$y) = (&'bnorm($_[0]),&'bnorm($_[1]));
if ($x eq 'NaN' || $y eq 'NaN') {
'NaN';
} else {
# multiply two numbers -- stolen from Knuth Vol 2 pg 233
sub main'bmul { #(num_str, num_str) return num_str
- local(*x, *y); ($x, $y) = (&'bnorm($_[$[]), &'bnorm($_[$[+1]));
+ local(*x, *y); ($x, $y) = (&'bnorm($_[0]), &'bnorm($_[1]));
if ($x eq 'NaN') {
'NaN';
} elsif ($y eq 'NaN') {
local($signr) = (shift @x ne shift @y) ? '-' : '+';
@prod = ();
for $x (@x) {
- ($car, $cty) = (0, $[);
+ ($car, $cty) = (0, 0);
for $y (@y) {
$prod = $x * $y + $prod[$cty] + $car;
if ($use_mult) {
# modulus
sub main'bmod { #(num_str, num_str) return num_str
- (&'bdiv(@_))[$[+1];
+ (&'bdiv(@_))[1];
}
\f
sub main'bdiv { #(dividend: num_str, divisor: num_str) return num_str
- local (*x, *y); ($x, $y) = (&'bnorm($_[$[]), &'bnorm($_[$[+1]));
+ local (*x, *y); ($x, $y) = (&'bnorm($_[0]), &'bnorm($_[1]));
return wantarray ? ('NaN','NaN') : 'NaN'
if ($x eq 'NaN' || $y eq 'NaN' || $y eq '+0');
return wantarray ? ('+0',$x) : '+0' if (&cmp(&abs($x),&abs($y)) < 0);
@x = &internal($x); @y = &internal($y);
- $srem = $y[$[];
+ $srem = $y[0];
$sr = (shift @x ne shift @y) ? '-' : '+';
$car = $bar = $prd = 0;
if (($dd = int(1e5/($y[$#y]+1))) != 1) {
--$q while ($v2*$q > ($u0*1e5+$u1-$q*$v1)*1e5+$u2);
if ($q) {
($car, $bar) = (0,0);
- for ($y = $[, $x = $#x-$#y+$[-1; $y <= $#y; ++$y,++$x) {
+ for ($y = 0, $x = $#x-$#y-1; $y <= $#y; ++$y,++$x) {
$prd = $q * $y[$y] + $car;
if ($use_mult) {
$prd -= ($car = int($prd * 1e-5)) * 1e5;
}
if ($x[$#x] < $car + $bar) {
$car = 0; --$q;
- for ($y = $[, $x = $#x-$#y+$[-1; $y <= $#y; ++$y,++$x) {
+ for ($y = 0, $x = $#x-$#y-1; $y <= $#y; ++$y,++$x) {
$x[$x] -= 1e5
if ($car = (($x[$x] += $y[$y] + $car) > 1e5));
}
$num = &'bnorm($num);
$dom = &'bnorm($dom);
}
- substr($dom,$[,1) = '';
+ substr($dom,0,1) = '';
"$num/$dom";
}
}
# absolute value
sub main'rabs { #(rat_num) return $rat_num
local($_) = &'rnorm(@_);
- substr($_,$[,1) = '+' unless $_ eq 'NaN';
+ substr($_,0,1) = '+' unless $_ eq 'NaN';
$_;
}
# multipication
sub main'rmul { #(rat_num, rat_num) return rat_num
- local($xn,$xd) = split('/',&'rnorm($_[$[]));
- local($yn,$yd) = split('/',&'rnorm($_[$[+1]));
+ local($xn,$xd) = split('/',&'rnorm($_[0]));
+ local($yn,$yd) = split('/',&'rnorm($_[1]));
&norm(&'bmul($xn,$yn),&'bmul($xd,$yd));
}
# division
sub main'rdiv { #(rat_num, rat_num) return rat_num
- local($xn,$xd) = split('/',&'rnorm($_[$[]));
- local($yn,$yd) = split('/',&'rnorm($_[$[+1]));
+ local($xn,$xd) = split('/',&'rnorm($_[0]));
+ local($yn,$yd) = split('/',&'rnorm($_[1]));
&norm(&'bmul($xn,$yd),&'bmul($xd,$yn));
}
\f
# addition
sub main'radd { #(rat_num, rat_num) return rat_num
- local($xn,$xd) = split('/',&'rnorm($_[$[]));
- local($yn,$yd) = split('/',&'rnorm($_[$[+1]));
+ local($xn,$xd) = split('/',&'rnorm($_[0]));
+ local($yn,$yd) = split('/',&'rnorm($_[1]));
&norm(&'badd(&'bmul($xn,$yd),&'bmul($yn,$xd)),&'bmul($xd,$yd));
}
# subtraction
sub main'rsub { #(rat_num, rat_num) return rat_num
- local($xn,$xd) = split('/',&'rnorm($_[$[]));
- local($yn,$yd) = split('/',&'rnorm($_[$[+1]));
+ local($xn,$xd) = split('/',&'rnorm($_[0]));
+ local($yn,$yd) = split('/',&'rnorm($_[1]));
&norm(&'bsub(&'bmul($xn,$yd),&'bmul($yn,$xd)),&'bmul($xd,$yd));
}
# comparison
sub main'rcmp { #(rat_num, rat_num) return cond_code
- local($xn,$xd) = split('/',&'rnorm($_[$[]));
- local($yn,$yd) = split('/',&'rnorm($_[$[+1]));
+ local($xn,$xd) = split('/',&'rnorm($_[0]));
+ local($yn,$yd) = split('/',&'rnorm($_[1]));
&bigint'cmp(&'bmul($xn,$yd),&'bmul($yn,$xd));
}
# square root by Newtons method.
# cycles specifies the number of iterations default: 5
sub main'rsqrt { #(fnum_str[, cycles]) return fnum_str
- local($x, $scale) = (&'rnorm($_[$[]), $_[$[+1]);
+ local($x, $scale) = (&'rnorm($_[0]), $_[1]);
if ($x eq 'NaN') {
'NaN';
} elsif ($x =~ /^-/) {
$txt = do "unicore/Name.pl" unless $txt;
my $pos = index $txt, "\t\t$arg\n";
- if ($[ <= $pos) {
+ if (0 <= $pos) {
my $posLF = rindex $txt, "\n", $pos;
(my $code = substr $txt, $posLF + 1, 6) =~ tr/\t//d;
return $vianame{$arg} = CORE::hex $code;
- # If $pos is at the 1st line, $posLF must be $[ - 1 (not found);
- # then $posLF + 1 equals to $[ (at the beginning of $txt).
+ # If $pos is at the 1st line, $posLF must be -1 (not found);
+ # then $posLF + 1 equals to 0 (at the beginning of $txt).
# Otherwise $posLF is the position of "\n";
# then $posLF + 1 must be the position of the next to "\n"
# (the beginning of the line).
package ctime;
local($time) = @_;
- local($[) = 0;
local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
# Determine what time zone is in effect.
if ($#$v >= 0) {
$short = $sp . "0..$#{$v} " .
join(" ",
- map {exists $v->[$_] ? stringify $v->[$_] : "empty"} ($[..$tArrayDepth)
+ map {exists $v->[$_] ? stringify $v->[$_] : "empty"} (0..$tArrayDepth)
) . "$shortmore";
} else {
$short = $sp . "empty array";
# print "$short\n";
# return;
#}
- for $num ($[ .. $tArrayDepth) {
+ for $num (0 .. $tArrayDepth) {
return if $DB::signal;
print "$sp$num ";
if (exists $v->[$num]) {
closedir(getcwd'PARENT); #');
return '';
}
- if ($pst[$[] == $cst[$[] && $pst[$[ + 1] == $cst[$[ + 1])
+ if ($pst[0] == $cst[0] && $pst[1] == $cst[1])
{
$dir = '';
}
# return '';
}
}
- while ($dir eq '.' || $dir eq '..' || $tst[$[] != $pst[$[] ||
- $tst[$[ + 1] != $pst[$[ + 1]);
+ while ($dir eq '.' || $dir eq '..' || $tst[0] != $pst[0] ||
+ $tst[1] != $pst[1]);
}
$cwd = "$dir/$cwd";
closedir(getcwd'PARENT); #');
sub Getopt {
local($argumentative) = @_;
local($_,$first,$rest);
- local($[) = 0;
while (@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
($first,$rest) = ($1,$2);
- if (index($argumentative,$first) >= $[) {
+ if (index($argumentative,$first) >= 0) {
if ($rest ne '') {
shift(@ARGV);
}
local($argumentative) = @_;
local(@args,$_,$first,$rest);
local($errs) = 0;
- local($[) = 0;
@args = split( / */, $argumentative );
while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
($first,$rest) = ($1,$2);
$pos = index($argumentative,$first);
- if($pos >= $[) {
+ if($pos >= 0) {
if($args[$pos+1] eq ':') {
shift(@ARGV);
if($rest eq '') {
;# $st_dev = @ary[$ST_DEV];
;#
-$ST_DEV = 0 + $[;
-$ST_INO = 1 + $[;
-$ST_MODE = 2 + $[;
-$ST_NLINK = 3 + $[;
-$ST_UID = 4 + $[;
-$ST_GID = 5 + $[;
-$ST_RDEV = 6 + $[;
-$ST_SIZE = 7 + $[;
-$ST_ATIME = 8 + $[;
-$ST_MTIME = 9 + $[;
-$ST_CTIME = 10 + $[;
-$ST_BLKSIZE = 11 + $[;
-$ST_BLOCKS = 12 + $[;
+$ST_DEV = 0;
+$ST_INO = 1;
+$ST_MODE = 2;
+$ST_NLINK = 3;
+$ST_UID = 4;
+$ST_GID = 5;
+$ST_RDEV = 6;
+$ST_SIZE = 7;
+$ST_ATIME = 8;
+$ST_MTIME = 9;
+$ST_CTIME = 10;
+$ST_BLKSIZE = 11;
+$ST_BLOCKS = 12;
;# Usage:
;# require 'stat.pl';
}
elsif ($code eq '>') {
($code,$tmp,$string) = unpack("CCa99",$string);
- if ($tmp[$[] > $code) {
- $tmp[$[] += $tmp;
+ if ($tmp[0] > $code) {
+ $tmp[0] += $tmp;
}
}
elsif ($code eq '2') {
SvREFCNT_dec(command);
*match_list = get_av("array", 0);
- num_matches = av_len(*match_list) + 1; /** assume $[ is 0 **/
+ num_matches = av_len(*match_list) + 1;
return num_matches;
}