Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Hash Variable

by OeufMayo (Curate)
on Apr 06, 2001 at 00:15 UTC ( [id://70274]=note: print w/replies, xml ) Need Help??


in reply to Hash Variable

Hey qball, Where in your example are you trying to use a hash?
Now here are some tips you might want to follow:

  • Use the -w switch and use strict.
  • You probably don't want to put you file in an array. There's no real use here and it can be a performance issue if your file is several hundreds MB large. Use the while (<DATA>){} construction instead. The line will be stored in the scalar $_.
  • Use the map function when you have to repeat the same operation several time on array elements and get another array back (or use a foreach loop if you don't want a new array).
  • Your loop and regex seem to be stripping the commas and whitespaces on the current line. There's more efficient ways to do it (ex: s/(?:\s|,)//g, and/or use a join to print the array back without commas).
  • You can save some keystrokes on your split by assiging it directly to an array, and later access the array elements with $array[n], where n is the array index (starting from 0).
  • To affect a key in a hash, it's really easy just say $hash{$key}=$value. $value can be just anything, but it has to be something (even undef or '').

By mixing these advices and your current code, you'll probably get the results you want. (I hope so!)

<kbd>--
my $OeufMayo = new PerlMonger::Paris({http => 'paris.mongueurs.net'});</kbd>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-19 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found