- To: George Vieira <georgev@xxxxxxxxxxxxxxxxxxxxxx>
- Subject: Re: [SLUG] Perl splitting help
- From: Scott Howard <scott@xxxxxxxxxx>
- Date: Sat Jul 22 17:58:18 2000
- Cc: "'slug@xxxxxxxxxxx'" <slug@xxxxxxxxxxx>
- User-agent: Mutt/1.2.4i
On Sat, Jul 22, 2000 at 05:52:42PM +1000, George Vieira wrote:
> 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.
You need to quote the | character.
You can also simplify the rest of your code a bit too :
open PLAYLIST, "/tmp/playlist.txt" ||
die "Cannot open file for reading\!";
while(<PLAYLIST>) {
($name, $number) = split /\|/;
print " <tr>\n";
print " <td>$name</td>\n";
print " <td>$number</td>\n";
print " </tr>\n";
}
close PLAYLIST;
Scott.