| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Member Join Date: Nov 2003 Location: UK
Posts: 53
![]() | Perl Scripters - Please Help Me!! Are there any genius perl scripters out there? If there are can you give me some help.....I have no idea how to create perl scripts My task is as follows: I need to create a script that will read a text file line by line and print the data into a HTML page and format in appropriate tables. ????: NamePros.com http://www.namepros.com/programming/15734-perl-scripters-please-help-me.html The script must read each line and store it in a suitable data contruct. The file consist of line of comments beginning with # and lines of data. A valid data line consists of 6 space delimited fields in the following order: Surname (case insensitive) Forename (case insensitive) Subject (case insensitive) Mark1 (integer between 0 - 100) Mark2 (integer between 0 - 100) Mark3 (integer between 0 - 100) For example a data line would read as follows: Yates Ian,Bob Science 75 54 45 In other words how do i parse the data from the text file to a properly formatted HTML pages with tables? Any help will be appreciated!! |
| |
| | #3 (permalink) |
| Senior Member Join Date: Aug 2002
Posts: 1,255
![]() ![]() | Hey just noticed this post. I don't know if you've figured it out yet or not, but you can use a foreach loop and split in Perl http://www.perldoc.com/perl5.8.0/pod/func/split.html to loop through the text file and split the strings into separate variables and then display them. It would make it a whole lot easier if your text file only had one delimiter and didn't contain any other content besides the delimited data. ![]() Here's a little snippet you may be able to use that reads a space delimited text file and then displays html output for each line which is what I think you want to do. Code: #!/usr/bin/perl
$file= "file.txt";
open(FILE, "$file") || die "Couldn't open file: $file: $! n";
my @list = <FILE>;
close (FILE);
print "Content-type: text/htmlnn";
print "<html>n";
print "<body>n";
foreach my $var (@list) {
chop($var);
($one,$two,$three,$four,$five,$six)=split(/ /, $var);
my $results = <<__W__D__T__;
$one $two $three $four $five $six<br>
__W__D__T__
print $results;
}
print "</body>n";
print "</html>n"; |
| |
| | THREAD STARTER #4 (permalink) |
| NamePros Member Join Date: Nov 2003 Location: UK
Posts: 53
![]() | Please could someone have a look at the file attached within the zip file and run the .pe file as a command line thru linux: perl -w assig1.pe 3a8.txt 6a1.txt There are errors occuring - if anyone can help me debug it i will be grateful.... |
| |