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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML - flatfile question 1

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
US
I am writing a Perl5 script to run on my web server. I am writing the variables to a flatfile as below:

open (GBLOG, ">>/flock(GBLOG,2);
seek(GBLOG,0,2);
print GBLOG "$caption|$type|";
print GBLOG "$format|$background|";
print GBLOG "$category|$keywords|";
print GBLOG "$source|$copyright|";
print GBLOG "$permission|$restrictions|";
print GBLOG "$initials|$createdate|";
print GBLOG "$editdate|$id|";
print GBLOG "$imagefile|$filename|";
print GBLOG "$mattefile|$mattename|$link\n";
close(GBLOG);
chmod 0666, $gblog;


Then I create an html page. I want to make the $caption clickable as I have done below but When the user clicks on the link, I want to parse the above GBLOG and print it out in normal speak like Caption: $caption etc.

open (LOG, ">>/ || dienice("Can't open Log");
flock(LOG,2);
seek(LOG,0,2);
print LOG &quot;<HTML><HEAD><Title>Associated Press Graphics Bank Upload Log</TITLE></HEAD>\n&quot;;
print LOG &quot;<BODY><A HREF=/log/$gblog>$caption<BR></BODY></HTML>&quot;;
close(LOG);
chmod 0666, $log;
 
This could be a little more concise, but, I have left it verbose for clarity. I have not run this so there may be typo or other minor blem. Hopefully, it shows a general flow for reading and printing your information.

Code:
open(IPF,&quot;<......mindy/log/$gblog&quot;) or die;
@lines = <IPF>;
close IPF;

# from that, you get an array of lines with a structure like
# caption|type|format|background|category|keywords|source|copyright|...etc.

%field_names = (0=>'caption',2=>'type',3=>'format',4=>'background',
          5=>'category',6=>'keywords',7=>'source',8=>'copyright');

foreach $line (@lines)
    {
    # split the lines on pipes
    @fields = split(/\|/,$line);
    
    # for each field print the field name  and content.
    foreach $num (0..$#fields)
        {
        #      a hash of field names  - an array of field contents.
        print &quot;$field_names{$num}     - $fields[$num]<br>\n&quot;;
        }
    }

HTH


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top