TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG:3636] perl open file to array
On Thu, 21 Jan 1999, Ben Luey wrote:
> Is there a way to open the content of a text file into a Array?
>
> My text file is just one line of words with spaces:
>
> name1 name2 name3
>
>
> $DATA = "/home/lueyb/hostnames";
> open(DATA, $DATA) || die "Could not open $DATA";
> print <DATA>;
>
> prints out the <DATA>, but I want to treat it as an array, so I can do
> print "@DATA[1]\n";
>
> etc.
>
open(DATA, $DATA) || die "...";
@data = <DATA>;
print @data;
> Also, is there a way to have tables?
>
> If my file is:
>
> name1 name2 name3
> stuff1 stuff2 stuff3
>
>
> can I open it in perl a say
>
> print "@DATA[2,2]\n";
>
> to print stuff2 and 1,2 for name2, etc?
>
An associative array _might_ do this, if I'm understanding what you're
saying. Dunno..
Check out
http://www.uni-hohenheim.de/institute/rz/app/prg/perl/perl/start.html;
great perl reference. If you want hard-print, buy the Camel book.
> Thanks,
>
> Ben
>
>
>
> Ben Luey
> lueyb@carleton.edu
> ICQ: 19144397
>
> It's only work if somebody makes you do it. -- Calvin
>
----
Nate Carlson
the infinite loop
natecars@infiniteloop.com