Sounds like to need to look at perldoc perllol
and perldoc perdsc, both of which cover this in
some detail.
In summary you'd do something like this (assuming your
delimiter is a tab):
my @data;
open(DATA, $file) || die "Can't open $file: $!\n";
while (<DATA>) {
push @data, [split /\t/];
}
You would then access the various elements like this:
my $town = 'London';
my ($lat, $long);
foreach (@data) {
if $_->[0] eq $town;
($lat, $long) = ($_->[1], $_->[2]);
last;
}
However, if this is how you are going to be using the
data, then you might be better off building a hash of
arrays, where the key to the hash is the town name and the
value is a two element list containing lat and long. You
would construct that something like this:
my %data;
open(DATA, $file) || die "Can't open $file: $!\n";
while (<DATA>) {
my ($town, @vals) = split(/\t/);
$data{$town} = \@vals;
}
you could then get the lat and long for a particular
town like this:
my ($lat, $long) = @{$data{$town}};
Hope this helps
--
<
http://www.dave.org.uk>
European Perl Conference - Sept 22/24 2000
<
http://www.yapc.org/Europe/>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.