×
Home About Us Products Services News Free Scripts Contact
news php scripts and software

Perl example - How to assign the lines contained in a text file to an array?


Perl - How to assign the lines contained in a text file to an array?

$file = 'data.txt' ;                # Name the file
open(INFO, "<$file" ) ;             # Open the file
@lines = <INFO> ;                     # Read it into an array
close(INFO) ;                         # Close the file

print "<HTML> <HEAD> <TITLE> PERL output </TITLE> </HEAD>\n" ;
print "  <BODY>\n" ;

foreach $line (@lines)                # assign @lines to $line, one at a time
{                                     # braces {} are required, bracket code
   print "\n   <P> $line   </P>" ;   # print formatted lines to screen 
}

print "\n  </BODY>\n</HTML>\n" ;

Category: Perl

 
<< Go back