Hello Monks
It's been a long time since I perl'ed! I have a program I wrote a few years back and I did all the bad things, global variables, variables with no initialization etc. (I was just learning at the time)
So I have decided to re-write it, remove all global vars and make sure that use warnings,strict and diagnostics are happy. If there is more I should do to make perl happy, I am all ears.
To my real question. In my 'main' program I have made some local hash tables that i am using to store and control the program and it's data. The thing that beat me up for an hour or two was 'scope' I believe I have a decent handle on it now, but am still struggling a little with implementation. Here's an example snippet.
# call the sub with a local hash
play_around(\%toys);
sub play_around {
my %t = %{$_[0]};
# I found this the only way to get the has in properly,
# otherwise it came in scalar, and mixing and matching
# hash and scalars made me choose to load this way, if
# it's wrong, please correct me.
$t{'leggo'} = "yes";
# this only lasts locally in this sub
$_[0]{'leggo'} = "yes";
# this will modify the actual %toys which is what I want.
# But this is darned ugly! and with a number of
# hashes / scalars it's a pain. Is there not a better
# way, or have I crossed the line into being a
# bad practice perl programmer?
}
Thank you in advance for any insight to my non-grasping of pointer/var handling in perl. I'm used to C and don't have too much trouble there!
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.