Path: utzoo!utgpu!watserv1!watmath!att!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!cs.utexas.edu!rutgers!ub.d.umn.edu!cs.umn.edu!cybrspc!roy From: roy%cybrspc@cs.umn.edu (Roy M. Silvernail) Newsgroups: comp.lang.perl Subject: $# question Message-ID: Date: 19 Nov 90 05:08:56 GMT Organization: Villa CyberSpace, Minneapolis, MN Lines: 36 I'm a little confused about a detail regarding $#... The manual (PL18, MS-DOS) says that you may find the length of an array by evaluating $#arrayname. It goes on to explain that $# is actually the index of the last element, and mentions that most arrays have a 0'th element. OK, given an array of 5 elements such as @foo = ('1','2','3','4','5') $#foo, in this case, will be 4, and therin lies the confusion. The array is obviously 5 elements long. Wouldn't $# make more sense if it were to point to the array element _past_ the last element assigned? (i.e. to the null element past '5' in the above example) Then it could be used directly as an indication of size, and as well, you could do while () { @foo[$#foo] = $_; } to fill an array with an incoming stream of fields. (using @foo[$#foo +1] works, but it's less intuitive to me) It's possible that this has been addressed in later patch-levels, but until PL41 comes around for DOS, I'm stuck at PL18. [ :-( ] (not-quite-related question: how does one unlink() a file not in the current directory? I've tried explicit pathnames with both / and \ as separators, but to no avail) Thanks in advance! -- Roy M. Silvernail |+| roy%cybrspc@cs.umn.edu |+| #define opinions ALL_MINE; main(){float x=1;x=x/50;printf("It's only $%.2f, but it's my $%.2f!\n",x,x);} "This is cyberspace." -- Peter da Silva :--: "...and I like it here!" -- me