Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: how to make first element of an string as a the array name

by erroneousBollock (Curate)
on Nov 15, 2007 at 00:13 UTC ( [id://650877]=note: print w/replies, xml ) Need Help??


in reply to how to make first element of an string as a the array name

First you need to parse your file. What have you already tried? Can we see your code?

(When you post your code, please remember to read the Writeup Formatting Tips.)

now i want to make each line as an array and give the first one as the name of the
like this
@IL12::1::287 = ('6','-17','-9','-21','-24','-15','-2','11','4','4','-15','-26','-16','-9','-18','-25','27','17','6')
Please don't use variables as variable names (yes this still applies).

Second, you'd do better to store your arrays as references in a hash, where the keys to the hash could be 'IL12::1::287', 'IL12::1::329', etc.
(Update: thezip gives you an example of the data-structure below.)

As for the array "common elements" problem, the usual way to solve that is to build a hash containing the elements of the first array as keys, then to loop through the elements of the second array testing for existence in the hash.

# you have @arr1 and @arr2 my %lookup = map { $_ => undef } @arr1; my @common = grep { exists $lookup{$_} } @arr2;
-David

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-03-28 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found