The book says stay away from this, so I never messed with it (until now for this test) but...
$[ = 1;
will change the first element of the array to one. On my box it actually loads the first value read into both subscript zero and one, but accessing the array starting from one would get the whole thing.
And if you mess up and access zero as well, you'll get that value twice, assuming of course yours works the same way, which it very well may not because this isn't the way it "should" be done.
Best to just get used to doing it right. Far to much can fall over when you pull at the bottom stick in the pile. :)
ms
$[ = 1;
open TXT, ('< C:\myperl\test.txt') or die "no joy $!";
@time = <TXT>;
close TXT;print "$time[0] $time[1] $time[2] $time[3] $time[4] $time[5]";
With 1 on line one, 2 on line two, 3 on line three and 4 on line four in test.txt this prints:
1
1
2
3
4
At 01:40 AM 9/26/03, you wrote:
On Thu, 25 Sep 2003, Wong, Danny H. wrote:
> Hi all, > I was wondering if I can start adding elements into an array > starting at 1? Here is what I am trying to do. I'm trying to glob all > files/folders in a directory and assign it to an array, but it start at > subscript 0. I know I can do a loop and start the subscript at 1. Just > see if there is an easier way. > > Chdir ('c:\temp'); > @Array = <*>; > > Is there a shift command? >
There's a shift command but it won't do what you want. Use the unshift command instead. Build the array as usual and then do a unshift(@array,0) and the 0 will become element zero with all other elements shifted up one element, i.e. what was originally element 0 will become element 1, the original element 1 will become element 2, etc. You can also consider simply setting $] to 1 so that the base of _all_ arrays will become 1 instead of 0 but that may cause more problems than it solves.
**** [EMAIL PROTECTED] <Carl Jolley> **** All opinions are my own and not necessarily those of my employer ****
_______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
