Silver
10-24-2004, 08:00 AM
Today, while chatting, I was just explaining to my friend from Mckode about some minor details in references. The point of 2D arrays came along, and, well, from there came about tables.
Anyways, I was wondering if all you PERL guys out there know any more ways of storing tables. For eg, lets take a table like-
|Name of Host| |URL|
|Crazyghost| |http://www.crazyghost.com|
|@webhosting| |http://www.atwebhosting.com|
|HostMatrix| |http://www.hostmatrix.org|
Now consider, you wish to store all the info in the table above in memory. Ofcourse, one way of doing it is to create an array for each row. But consider the number of rows is not know. Then how can it be done.
Here are 2 ways (1 pretty well know, and other, i thought of it)-
--Using References-
-Declaration and assigning
my(@array)=(['Name of Host','URL'],['Crazyghost','http://www.crazyghost.com'],['@webhosting','http://www.atwebhosting.com'],['HostMatrix','http://www.hostmatrix.org']);
-To get a particular value-
$array[2]->[0] will have value '@webhosting'
--Using join and split-
-Declaration and assigning
my(@array)=('Name of Host¢URL','Crazyghost¢http://www.crazyghost.com','@webhosting¢http://www.atwebhosting.com','HostMatrix¢http://www.hostmatrix.org');
-To get a particular value-
(undef,$column)=split(/¢/,$array[2],2);
print $column;
It will print out- http://www.hostmatrix.org
Anyways, any1 can suggest more ways to store tables in PERL?
Anyways, I was wondering if all you PERL guys out there know any more ways of storing tables. For eg, lets take a table like-
|Name of Host| |URL|
|Crazyghost| |http://www.crazyghost.com|
|@webhosting| |http://www.atwebhosting.com|
|HostMatrix| |http://www.hostmatrix.org|
Now consider, you wish to store all the info in the table above in memory. Ofcourse, one way of doing it is to create an array for each row. But consider the number of rows is not know. Then how can it be done.
Here are 2 ways (1 pretty well know, and other, i thought of it)-
--Using References-
-Declaration and assigning
my(@array)=(['Name of Host','URL'],['Crazyghost','http://www.crazyghost.com'],['@webhosting','http://www.atwebhosting.com'],['HostMatrix','http://www.hostmatrix.org']);
-To get a particular value-
$array[2]->[0] will have value '@webhosting'
--Using join and split-
-Declaration and assigning
my(@array)=('Name of Host¢URL','Crazyghost¢http://www.crazyghost.com','@webhosting¢http://www.atwebhosting.com','HostMatrix¢http://www.hostmatrix.org');
-To get a particular value-
(undef,$column)=split(/¢/,$array[2],2);
print $column;
It will print out- http://www.hostmatrix.org
Anyways, any1 can suggest more ways to store tables in PERL?