Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 28th, 2006, 11:30 PM
NevadaSam NevadaSam is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Location: Georgia
Posts: 11 NevadaSam User rank is Private First Class (20 - 50 Reputation Level)NevadaSam User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 8 h 10 m 34 sec
Reputation Power: 0
Replacing a field separator during a read.

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:
Quote:
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
Quote:
#!/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.

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Replacing a field separator during a read.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT