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 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 (<INPUTFILE>{<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(<F>{<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(<F>{<br>
($field1,$field2,$field3)=split(/\t/,$_); # fixed here<br>
# do something with the record<br>
}<br>
--snip--<br>
<br>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.