Link to home
Start Free TrialLog in
Avatar of jfuller
jfuller

asked on

How do I represent a TAB in CGI program.

I was wondering if anybody knew how to represent a TAB stop in a Perl CGI Program.  I have a simple cgi program that manipulates a d-base when a link is followed (or image is clicked).  It works great when the DBASE is PIPED between fields.  I need it to work when the d-base is TABBED.  Any reply would be greatly appreciated.

Here is the Code if you need it.  The areas that I need TABBED instead of PIPED are marked with.

#-=-=-=-=-=-=-=-TAB should take place of PIPE Here.-=-=-=-=-=-=-=-


<----------------Begin Code--------------------->

#!/usr/bin/perl
$MINBAK = "min/min.bak";
$MINCNT = "min/min.cnt";
$MINDAT = "min/min.dat";
$MINLOG = "min/min.log";
$MINFLK = "flk/min.flk";

$command   = "IMG"; # set default
$minNbr = 0;     # set default
$minUrl = "/cgi-localbin/min";
$scriptUrl = "/cgi-localbin/minmat.cgi";


######################################################################
# Read the QUERY STRING

if ($ENV{'QUERY_STRING'})
{ ($command,$minNbr) = split (/=/,$ENV{'QUERY_STRING'});
}

######################################################################
# Case: Send Image to browser

if ($command eq "IMG")
{
  # Get the min info
  &lock ($MINFLK);
  open (DAT,"<$MINDAT");
  @minFile = <DAT>;
  close (DAT);

#-=-=-=-=-=-=-=-TAB should take place of PIPE Here.-=-=-=-=-=-=-=-
  @minLine = split(/\|/,$minFile[$minNbr]);
 
  # send HTML to browser
  print "Content-type: text/html\n\n";
  print "<a href=\"$scriptUrl?URL=$minNbr\"><font size=1>PLEASE CLICK HERE:</font><br>\n";
  print "<img src=\"$minLine[1]\" border=1></a>\n";


} # end Case IMG

######################################################################
# Case: Send browser to the image's URL

elsif ($command eq "URL")
{
  # Get the min info
  &lock ($MINFLK);
  open (DAT,"<$MINDAT");
  @minFile = <DAT>;
  close (DAT);

#-=-=-=-=-=-=-=-TAB should take place of PIPE Here.-=-=-=-=-=-=-=-
  @minLine = split(/\|/,$minFile[$minNbr]);

  # send browser to URL corresponding to IMG
  print "Location: $minLine[0]\n";
  print "Content-type: text/html\n\n";

  # subtract one from dbase field
  $minLine[2] --;

#-=-=-=-=-=-=-=-TAB should take place of PIPE Here.-=-=-=-=-=-=-=-
  $minFile[$minNbr] = join ("\|",@minLine);
 
  # backup and update min file
  if (-s $MINDAT) {print `cp $MINDAT $MINBAK`;}
  open (DAT,">$MINDAT");
  print (DAT @minFile);
  close (DAT);
  &unlock ($MINFLK);

} # end Case URL

##################################################################
# Sub: File locks prevent simultaneous changes

sub lock
{ $LOCKFILE = $_[0];
  if (-e $LOCKFILE)
  { $endTime = time + 3;
    while (-e $LOCKFILE && time < $endTime)
    { sleep 1;
    }
  }
  open (LOCK,">$LOCKFILE");
  print (LOCK "busy");
  close (LOCK);
} # end lock

sub unlock
{ $LOCKFILE = $_[0];
  if (-e $LOCKFILE)
  { unlink ($LOCKFILE);
  }
} # end lock
ASKER CERTIFIED SOLUTION
Avatar of yxw1
yxw1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial