develooper Front page | perl.perl6.internals | Postings from April 2002

Substr with a negative length

From:
Simon Glover
Date:
April 16, 2002 14:27
Subject:
Substr with a negative length
Message ID:
Pine.GSO.4.43.0204161721150.1131-100000@egg.amnh.org

 What should the substr ops produce if given a negative length argument?
 At the moment, the four-arg. form hands back an empty string, while
 the five-arg. form hands back a copy of the original string, ie:

  set S0, "abcdefg"
  substr S1, S0, 0, -1
  print S1
  print "\n"

 and

  set S2, ""
  substr S3, S0, 0, -1, S2
  print S3
  print "\n"

 produce "" and "abcdefg" respectively. The former seems more correct,
 but I thought I'd throw this out for comment before hacking string.c

 Simon






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