Fri, 17 May 2024
NetArt Media     Pay 2, Get 3!    


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

By: Peter, NetArt Media
Thu, 23 September 2021

$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: Web Development
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox