Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Special variable - set array base

by licking9Volts (Pilgrim)
on Jul 03, 2002 at 21:17 UTC ( #179322=note: print w/replies, xml ) Need Help??

in reply to Special variable - set array base

Jim, you're right. I forgot to show another important piece of my program. Here's a better snippet:
#!/usr/sbin/perl -w use strict; $[ = 7; # set array base to 1 $, = ' '; # set output field separator $\ = "\n"; # set output record separator ... while (<FILE>) { chomp; # strip record separator @in_data = split(/ +/, $_); $out_raw = sprintf(" %8.0f %8.0f", $in_data[1], $in_data[2]); ...
My program runs fine, I'm just curious about the $_ variable and whether or not it is still in use.

Update: I checked perlvar, but it says pretty much the same thing as Programming Perl. It did add that the use of $[ is discouraged.

Replies are listed 'Best First'.
Re: Re: Special variable - set array base
by Jim Morrison (Novice) on Jul 03, 2002 at 22:22 UTC
    Beleive me or not, I got different results when set $[ to 1, 7 and 0 running your piece of code. (slightly modified, but you did not provided exact code to execute. and I'll show you my logs if needed.)

    About usage of "$_" variable -- beware, your "while(<FILE>)" - this loop corrupts "$_", and "local $_;" statement somewhere before that loop will be a good idea, just to preserve its value.

    Sins of Perl Revisited will get you an idea what I mean. Here's an excelent explanation about power plant... well, read on, this certainly worth it!


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://179322]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2018-06-25 18:01 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (128 votes). Check out past polls.