licking9Volts has asked for the wisdom of the Perl Monks concerning the following question:
I'm puzzled by the $[ variable. I read in Programming Perl that it's set to 1:$[ = 1; # set array base to 1 $, = ' '; # set output field separator $\ = "\n"; # set output record separator
"...to make Perl behave more like awk...when evaluating the index and substr functions".I don't mind using 0 as the array base so I started tinkering around with this variable just to see what would happen. Well, nothing happened when I changed it. Shouldn't it have some effect on arrays like this?:
I changed the array base to 0, 1, 5, 20, etc. and it had no effect on my program. So I read further in Programming Perl, (the next line as a matter of fact =), and it says:... while (<FILE>) { chomp; # strip record separator @in_data = split(/ +/, $_); ...
"Because it was found to be so dangerous, assignment to $[ is now treated as a lexically scoped compiler directive and cannot influence the behavior of any other file."Well I have no clue what that means. I was wondering if any of you could shed some light on what this variable does. I tried Super Search, but it keeps giving me errors. Thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Special variable - set array base
by Jim Morrison (Novice) on Jul 03, 2002 at 20:53 UTC | |
Re: Special variable - set array base
by licking9Volts (Pilgrim) on Jul 03, 2002 at 21:17 UTC | |
by Jim Morrison (Novice) on Jul 03, 2002 at 22:22 UTC | |
Re: Special variable - set array base
by emilford (Friar) on Jul 03, 2002 at 20:53 UTC |