Hi,

I am using perl on the linux platform (v5.8.0 built for
i386-linux-thread-multi).

While debugging a script I came across a scenario where array access was
happening with a negative index.
(because of a corner case that was not properly handled).
This resulted in accessing the array in a reverse order. A script to mimic
the behaviour


  my $a = "/one/two/three/four/five" ;

  my $b = (split (/\//,$a))[-1] ;
  my $c = (split (/\//,$a))[-2] ;
  my $d = (split (/\//,$a))[-3] ;
  my $e = (split (/\//,$a))[-4] ;
  my $f = (split (/\//,$a))[-5] ;

  print "\$b => $b\n";
  print "\$c => $c\n";
  print "\$d => $d\n";
  print "\$e => $e\n";
  print "\$f => $f\n";


On executing the above script the output is


$b => five
$c => four
$d => three
$e => two
$f => one


I wanted to ask others if this is expected behaviour.
If I make use of this feature will it cause compatibility issues with the
later versions of perl.

Thanks in advance for the help.

Reply via email to