Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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.


Comment on Re: Special variable - set array base
Select or Download Code
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!

    Jim

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://179322]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (14)
As of 2015-07-06 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls