Replacing a field separator during a read.
I want to replace a pipe symbol (|) field seperator with a tab when I print the contents of records in a file. This is my text file:
Jeremiah Stein|LW89W|1|U
Patty Smith|JJ12R|2|W
The cgi script I wrote will read it and print it out with the | between field. How can I replace the | with a tab? This is my script. It can be called up from a link or in the browser's window: http://localhost/cgi-bin/cvtc/c05ex4b.cgi
#!/usr/bin/perl
#c05ex4b.cgi - reads data from a text file and creates a dynamic Web page
# that prints registered information
print "Content-type: text/html\n\n";
use CGI qw(:standard -debug);
use strict;
#declare variables
my ($name, $serial, $modnum, $sysletter, @records, $rec);
#Read Records
open(INFILE, "<", "c05ex4.txt")
or die "Error opening c05ex4.txt. $!, stopped";
@records = <INFILE>;
close(INFILE);
foreach my $rec (@records) {
chomp($rec);
($name, $serial, $modnum, $sysletter) = split(/\|/, $rec);
}
#create Web page
print "<HTML><HEAD><TITLE>Juniper Printer Registrations</TITLE></HEAD>\n";
print "<BODY><H2>\n";
print "<B>View Registration File</B></h2><br />\n";
print "The Following Printers have been registratered.<br /><br /> \n";
foreach my $rec(@records) {
print "$rec<br />\n";
}
print "</BODY></HTML>\n";
I am learning from a text book and it is not covered.