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,$Comments

This 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/&nbsp;//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?


In reply to Spliting a delimited string into variables by pissflaps

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.