|There's more than one way to do things|
How to improve my code? main concern:array as hash elementby xargon (Initiate)
|on Nov 23, 2011 at 15:21 UTC||Need Help??|
xargon has asked for the
wisdom of the Perl Monks concerning the following question:
I have come to seek the wisdom of the Perl
I'm working on a little project of mine (i'm a biologist, as you will notice :P). I'm trying to read through a pre-formatted text file, locate specific words and replace them, then print the changed lines.
Here's what I came up with:
This works perfectly if i'm not gravely mistaken, yet it seems rather unorthodox. I mean, i'm creating a table (eg @gi)which is read in the hash as a scalar and i split it again to get a new table, so i can get all the different outputs. If i use Gi=>@gi , without "", then i only get the gi instead of the whole @gi table. Any ideas how to improve on this code?UPDATE:
Thank you for your responses.
You are right of course about the data. As hbm guessed it looks like this:RandomID Name Gi Tissue
RandomID Name Gt Tissue
RandomID Name Gs Tissue
(all separated by tabs to be able to use the file easily on excel)
I read all about references before writing the original code but as i was pretty inexperienced in using them, i did away with them.
++wsfp, what you suggested was actually my first try (trying to figure out if my variable was an array or scalar) but i had no idea how to do hat, hence the work-around :)
++hbm, sorry about the modifiers, old habits you see :PI'll give it a run and let you know how it turns out. Thank you
Yet another UPDATE:
Thank you all