Old Fortran programmer trying to learn Perl. Having problems with arrays. File consists of 4 fields separated by the pipe (|). I am trying to pull out each field from the line, then print each field.
This code does not split the 4 fields. The delimiter ($delim) is still present after the split. What's worse, foreach is putting each character, not field, into each column.
help
Sample from data file:
00-11-15|W|02:04:44|vote.txt|
00-11-15|W|02:05:50|tabletut.txt|
Code snippet:
open (DUMPME, "< $_[0]");
print "<table>\n";
while ($line=<DUMPME>) {
chomp($line);
print "<tr>";
@aray = split /$delim/, $line;
foreach $item (@aray) {
print "<td>$item</td>\n";
}
print "</tr>\n";
}
close <DUMPME>;
This code does not split the 4 fields. The delimiter ($delim) is still present after the split. What's worse, foreach is putting each character, not field, into each column.
help
Sample from data file:
00-11-15|W|02:04:44|vote.txt|
00-11-15|W|02:05:50|tabletut.txt|
Code snippet:
open (DUMPME, "< $_[0]");
print "<table>\n";
while ($line=<DUMPME>) {
chomp($line);
print "<tr>";
@aray = split /$delim/, $line;
foreach $item (@aray) {
print "<td>$item</td>\n";
}
print "</tr>\n";
}
close <DUMPME>;