Hi all,
I'm fairly new to Perl, and lately I've been converting my old awk scripts to Perl by using
a2p. I'm running version 5.004_04 on Irix. (I know there's a newer version but our admins are tied down by corporate red tape when it comes to installing software). Anyway, I noticed that it always inserts these three lines in the generated Perl code:
$[ = 1; # set array base to 1
$, = ' '; # set output field separator
$\ = "\n"; # set output record separator
I'm puzzled by the
$[ variable. I read in
Programming Perl that it's set to 1:
"...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?:
...
while (<FILE>) {
chomp; # strip record separator
@in_data = split(/ +/, $_);
...
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:
"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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.