Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with tab-delimated database

Status
Not open for further replies.

Cyt0plas

Programmer
Jun 16, 1999
1
US
I am working on a perl script to create HTML files using a template and a Tab-Delimated database. I am trying to figure out how to read data in one letter at a time, and then process it. Can anybody help?<br>
<br>
Thanks in advance,<br>
Cyt0plas
 
I'm not quite sure, but I think there's a Perl equivalent to the JavaScript charat(n) function which retrieves only the character in position n of a variable/file.<br>
<br>
I whish I knew what the Perl alternative was for you, but I'm hoping someone else will.<br>
<br>
<br>
-Robherc<br>
robherc@netzero.net
 
It might be easier if you read a whole line in at a time (i'm assuming here that your tab delimted database file separates records by putting them on different lines in the file) and then process characters from that line using substr.<br>
<br>
Mike<br>

 
You can use the split function like this:<br>
<br>
while (&lt;INPUTFILE&gt;){<br>
@array_of_elements = split /\t/, $_;<br>
@array_of_characters = split //,pop @array_of_elements;<br>
}<br>
<br>
<br>
I haven't tried this, or tested in any way, it's just my guess as to do what you want... ;)<br>
Please correct me if and when I'm off track!!<br>
<br>
- Milamber
 
I use code like this a lot:<br>
<br>
Given a data file with three - tab delimited - fields this code will read and and process each line in the file.<br>
<br>
--snip--<br>
$F='datafile';<br>
open F ¦¦ die;<br>
while(&lt;F&gt;){<br>
($field1,$field2,$field3=split(/\t/,$_);<br>
# do something with the record<br>
}<br>
--snip--<br>
<br>
Hope this is of use.<br>
-ml
 
Missed a bracket - code snippet above should read:<br>
<br>
<br>
--snip--<br>
$F='datafile';<br>
open F ¦¦ die;<br>
while(&lt;F&gt;){<br>
($field1,$field2,$field3)=split(/\t/,$_); # fixed here<br>
# do something with the record<br>
}<br>
--snip--<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top