pissflaps has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks! I was placed in charge of a ticket-alert system written and perl and cannot get past half of this code. I have been trying to split a string of lines into variables representing each delimited word within the line. If that is unclear, maybe a visual representation will help: A flat-file DB system is sitting on an HTML page.Tickets are formatted like such: (All on one line)
<TR><TD> 371540 | </TD><TD>4/07/2011 | </TD><TD>08:03 | </TD><TD>11 +:03 | </TD><TD>2 | </TD><TD>Company Name(MAIN SITE) | </TD><TD> +DB PURGE | </TD><TD> </TD></TR> <TR><TD>
which was generated from splitting the input values for creating the tickets. I assign the input into an array and regex off the markup and spaces. I'm now left with something like this:
371540|4/07/2011|08:03|11:03|2|Company Name (MAIN SITE)|DB PURGE| and want to assign variables to each word in this format: $ticket,$DateAdded,$STime,$ETime,$Pri,$SiteName,$CommentsThis way, I can access the variables and email alerts based on the time variables to be compared to the current time. Where I'm having trouble seems to be around the following segment of code. Any help or advice would be GREATLY appreciated, since I am very new to Perl and have been debugging this script line-by-line with warnings and just can't figure out some of the functions I'm applying.
#!C:/Perl/bin/perl.exe use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use Net::SMTP; use Data::Dumper::Simple; use warnings; use diagnostics; open(DB, '<', "C:/Inetpub/wwwroot/DBase.htm") || die "Error: $!\n"; our ($i, $line); my @arr = <DB>; splice (@arr, 0, 14); #this trims off all the html setup and t +able markup close (DB); foreach $line(@arr){ $line =~ s/\|//g; $line =~ s/<\/TD><\/TR><TR><TD>/\n/g; $line =~ s/<\/TD><TD>/\|/g; $line =~ s/ //g; $line =~ s/<\/TD><\/TR>//g; $line =~ s/<TR><TD>//g; chomp($line); } my $lines = \@arr; my ($Ehour, $Emin); for $i (0 .. $#arr){ $line[$i] = $arr[$i]; } my @lines = ($line[0], $line[1], $line[2], $line[3], $line[4] +, $line[5], $line[6]); print (Dumper (@lines)); #shows all lines are in the array pro +perly. my ($ticket,$DateAdded,$STime,$ETime,$Pri,$SiteName,$Comments) = split(/\|/,$line[0]); print "$line->[0]\n"; #prints "371225 |3/23/2011|16:34 | 19:34 |2 |Com +pany Name ||
You can see that I'm able to split a single line into the variables, but I want to iterate over every line in the $line string to place these variables onto the data. Am I totally setting myself up for failure, or is there a better way to do this?
|
---|