Connecting Tech Pros Worldwide Help | Site Map

reading .txt file in array format

Newbie
 
Join Date: Nov 2007
Posts: 2
#1: Nov 29 '07
how to store data of .txt file into array. means one line it treats as a one element of array. next line is next elment and so on..
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,569
#2: Nov 29 '07

re: reading .txt file in array format


Quote:

Originally Posted by arpit37720

how to store data of .txt file into array. means one line it treats as a one element of array. next line is next elment and so on..

This is a pretty basic question and I think you need to go and read something like Beginning Perl.

I am not saying that we are above these questions, because we are not, but you learn by reading and doing and that is something that is pretty easy.

Regards,

Jeff
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#3: Nov 29 '07

re: reading .txt file in array format


I agree with Jeff, read the link he posted. Next time pleasae show some effort to solve your questions:

Expand|Select|Wrap|Line Numbers
  1. open (FH, 'filename') or die "$!";
  2. my @array = <FH>;
  3. close FH;
  4. print "$_" for @array;
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,569
#4: Nov 29 '07

re: reading .txt file in array format


Quote:

Originally Posted by KevinADC

I agree with Jeff, read the link he posted. Next time pleasae show some effort to solve your questions:

Expand|Select|Wrap|Line Numbers
  1. open (FH, 'filename') or die "$!";
  2. my @array = <FH>;
  3. close FH;
  4. print "$_" for @array;

Same user, two different questions, same link to the same book given. Gotta love it.
Reply