- To: "'slug@xxxxxxxxxxx'" <slug@xxxxxxxxxxx>
- Subject: [SLUG] Perl splitting help
- From: George Vieira <georgev@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat Jul 22 17:52:41 2000
Hi all,
I have a problem as I don't know Perl very well and need to do the
following:
1. Grab a file containing a list of people and phone numbers seperated by a
| .eg.
--- playlist.txt---
George Vieira|0410123123
Another Person|0414321321
2. Split the lines into fields so I can print each field into a cell in a
table.
This is what I have so far but don't understand how "split" works and only
get 1 character. At the moment the bottom is a mess and fails miserably but
just to give you an idea what I'm trying to do...
@players;
open (FILE, "/tmp/playlist.txt") ||
die "Cannot open file for reading\!";
while(<FILE>)
{
$players[$nob] = $_;
$nob = $nob + 1;
}
close(FILE);
$num="0";
foreach @players {
($name, $number)=split(/|/,@players[$num]);
print " <tr>\n";
print " <td>$name</td>\n";
print " <td>$number</td>\n";
print " </tr>\n";
$num = $num + 1;
}
Can someone help me with this?
thanks,
George Vieira.