I would recommend against naming variables based on dynamic input; that can get you into all sorts of troubles. A better idea (besides using DB files or an RDBMS, of course) would be to have a hash whose values are anonymous array references containing the data you need. As for separating the file data, you need to split the line on spaces. As far as I understand the question, I think this will work for you: use strict;
my %users;
open USERS, "<users.txt";
while (<USERS>) {
chomp;
my @line = split / /;
$users{shift @line} = \@line;
}
close USERS;
To get back at the data, you need to dereference the array, i.e. @{$users{$name}}. For example, to get a dump of the users,print join ' ', ($_, map($_, @{$users{$_}}), "\n") for (keys %users);Of course, you'd be better off using a DB file if you can; flat files require you to reinvent the wheel in a lot of ways. Provided tied hashes properly handle array references (which I'm not sure of; I stick to RDBMSs), this should extend to that pretty easily. | [reply] [d/l] [select] |
Start with the library. The intro to data structures is excellent. It would be easy to make it a list of lists just through your file into an array and then search by position.
@C = <INFILE>;
$start = 0;
foreach $foo(@C) {
until ($start > $#@C)
if($foo$start=~/joe || bob/)
{push (@NewUser,$foo$start);
$start++;
push (@NewUser,$foo$start);
$start++;
push (@NewUser,$foo$start);
$start++;
push (@NewUser,$foo$start);
$start++;}
$start++;}
{push (@AllUsers, @NewUser;}
you get
@AllUsers = (
'joe','2','9','8',
'bob','4','u','2',
);
or a hash where Joe is the key and the value is a list of the next three lines. Just my little thoughts.
Gandalf tea Wednesday. | [reply] |
need to work on that formattin.
Gandalf tea Wednesday.
| [reply] |
@C=<<>INFILE<>> lost in the formatting. Sorry.
| [reply] |
ok I really need to work on the formattin.
one last try for the night.
@C=<INFILE>
| [reply] |
See the Site How To for info on formatting stuff. The easiest way is to embed code blocks in <CODE></CODE> tags; everything inside them will be spaced as intended and it won't strangely interpret any of your characters. Also, rather than posting 4 follow-ups, if you go to the actual node of your original reply, you can modify it in most cases.
| [reply] |