Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please Help - WHY IS THIS NOT WORKING?

Status
Not open for further replies.

mtorbin

Technical User
Nov 5, 2002
369
US
Hey all,

Unfortunately, I can't get to my logs so I'm relying on you guys and gals. Why is the following giving me an error?

#!/usr/bin/Perl -wT
print "Content-type:text/html\n\n";
open(fileIN,"log.txt") or dienice("Cannot open log.txt: $!");
@logData = <fileIN>;
close(fileIN);
print <<EndHTML;
<html>\n<head>\n
<title> Log File Data </title>\n
</head>\n<body>\n
<h2>Log File Data</h2>\n
EndHTML
foreach $line (@logData)
{
chomp($line);
print "$line<br>\n";
}
print "</body>\n</html>";

# Error Trapping Sub...should things go pear shaped!
sub dienice
{
my($msg) = @_;
print "<html>\n<head>\n<title>Error Opening File!</title>\n";
print "</head>\n";
print "<body><h2>Error</h2>\n<b>";
print $msg;
print "\n</b></body>\n</html>";
exit;
}

Thanks. BTW, all the necessary ingrediants are there, so I think it's a syntax thing.

- MT

Matt Torbin
Web and Graphic Arts Engineer
PEI-Genesis

aim: dgtlby
direct email: mtorbin_at_earthlink.net
 
Only 3 things I can see that might be causing problems:

1 - take out the T switch in the shebang

2 - put a blank line after ENDHTML

3 - change Perl to perl (possible case senisitivity...)

There's always a better way. The fun is trying to find it!
 
Tell me about it. I'm working on a new app now that if I finish will probaby be the toughest thing I've ever attempted to write.... for me.

- MT

Matt Torbin
Web and Graphic Arts Engineer
PEI-Genesis

aim: dgtlby
direct email: mtorbin_at_earthlink.net
 
Ok, so that worked! Thank you. Now I have this in my text db:

0001|mtorbin|password|Tue May 18 15:33:27 2004|in

How do I split this information into an array?

- MT

Matt Torbin
Web and Graphic Arts Engineer
PEI-Genesis

aim: dgtlby
direct email: mtorbin_at_earthlink.net
 
You've already got it in an array! foreach $line (@logData). Just use $line[0], $line[1], $line[2], etc. to access the array values.

Ex:
[0] [1] [2] [3] [4]
0001|mtorbin|password|Tue May 18 15:33:27 2004|in

This is always a tough one to grasp and I hope I've explained it adequately for you to run with it.

There's always a better way. The fun is trying to find it!
 
Darn, pressed the wrong key!

Here's a better explanation:

this is the data on a single '$line (@logData)'
0001|mtorbin|password|Tue May 18 15:33:27 2004|in

Since arrays are zero based (the first element is 0, not 1), this is how the values be assigned:

$line[0] = 0001
$line[1] = mtorbin
$line[2] = password
$line[3] = Tue May 18 15:33:27 2004
$line[4] = in


There's always a better way. The fun is trying to find it!
 
Code:
($number,$user,$password,$date,$status)=split /\|/,$line;

Should do it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top