Solved

output using Html format.

Posted on 2000-03-08
9
205 Views
Last Modified: 2010-03-05
this is the code I want to output from a database,  but  it only output for
unix console, I want the output using Html format, how ?


#!/usr/local/bin/perl -w

# Use the DBM module.
use Getopt::Long;
use English;
use AnyDBM_File;

# Set up the command line options.
my $ret            = GetOptions ("d|database:s");
#my $database    = $opt_d || die "Usage: $0 -d database\n";

#my $database      ="/cgi-bin/process/hctu/she/testDir/convert.dbm";
my $database   = "convert.dbm";
my (%contents,$count,$type,$name,$price,$desc,$record);

# Open the DBM database file.
dbmopen (%contents, $database, 0700) || die "Could not open DBM file $database : $!\n";

# Force the top of page.
$FORMAT_LINES_LEFT = 0;
$count = 0;

# Start printing out the dbm information.
for $number (sort keys %contents)
{
   # Get the contents from the hash.
   $record = $contents{$number};

   # Split the record up.
   ($type,$name,$price,$desc) = split (/\|/, $record);
   $count++;

   # Write it...
   write;
}

# Close the DBM database.
dbmclose %contents;

# Top of picture formats.
format STDOUT_TOP=
Count Item #  Item Type  Item Name      Price     Description   Page @>>>>>>
$FORMAT_PAGE_NUMBER
============================================================================
.

format STDOUT=
@>>>> @|||||| @<<<<<<<<< @<<<<<<<<<<<<< $@####.## ^<<<<<<<<<<<<<<<<<<<<<<<<<
$count,$number,$type,$name,$price,$desc
~                                                 ^<<<<<<<<<<<<<<<<<<<<<<<<<
$desc
~                                                 ^<<<<<<<<<<<<<<<<<<<<<<<<<
$desc
.




this is the unix output!

ount Item #  Item Type  Item Name      Price     Description   Page       1
============================================================================
    1   100   Hardware   Hammer         $   25.00 A thing to hit nails with.
    2   122   Hardware   Nail           $    0.15 A thing to be hit by a
                                                  hammer. (see hammer)
    3   142   Hardware   Sander         $   10.15 Used to sand all sorts of
                                                  things, except sand.
    4   206   Household  Kitchen Sink   $  100.00 Lost the last time I went
                                                  on vacation. (next time
                                                  this I won't check it in)
    5   210   Household  Windows        $   45.00 User friendly and does not
                                                  need to be plugged in.
    6   242   Household  Vacuum         $  300.00 I'm not sure what this is
                                                  used for; but people seem
                                                  to have them anyway.
    7   266   Household  Microwave      $  100.00 Kitchen item. (Also see
                                                  hot water heater)
    8   312   Garden     Rake           $   25.00 Used to rake leaves, cut
                                                  grass and break noses if
                                                  left lying on the ground.
    9   344   Garden     Gravel         $   30.00 Why bother the dog is
                                                  going to dig through it
                                                  again anyway.
   10   362   Garden     Top Soil       $   10.00 Is there such a thing as
                                                  "Bottom Soil"?
   11   384   Garden     Mosquitoes     $    0.00 Some are large as a dog
                                                  and will carry you away.
   12   500   Sports     Hockey Stick   $   10.00 Used to push the puck
                                                  around.
   13   502   Sports     Bike           $  400.00 Sits in the garage and
                                                  collects dust.
   14   556   Sports     First Aid Kit  $   25.00 Used more times than not
                                                  unfortunately.
   15   602   Misc       Dog Food       $    1.50 The stuff the cat eats.
   16   624   Misc       Cat Food       $    0.75 The stuff the dog eats.
   17   644   Misc       Socks          $    1.00 What both the dog and cat
                                                  destroy.

0
Comment
Question by:syu1
  • 5
  • 3
9 Comments
 
LVL 3

Expert Comment

by:guadalupe
ID: 2597479
Try this:

print "Content-type: text/html\n\n";

print "<pre>\n";

# Start printing out the dbm information.
for $number (sort keys %contents)
{
   # Get the contents from the hash.
   $record = $contents{$number};

   # Split the record up.
   ($type,$name,$price,$desc) = split (/\|/, $record);
   $count++;

   # Write it...
   write;
}
print "</pre>\n";

Didn't put it as an answer as I'm not sure but give it a try...  try from the command line first then from a web browser...
0
 

Author Comment

by:syu1
ID: 2597896
thanks , the command line is ok, but the web browser doesnt works at all.


0
 

Author Comment

by:syu1
ID: 2597898
thanks , the command line is ok, but the web browser doesnt works at all.


0
 
LVL 3

Expert Comment

by:guadalupe
ID: 2597958
What happens when you run it from the browser...?

Could it be a problem of permissions?

Try doing a chmod of 755 to give all users permission to execute the script.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:syu1
ID: 2598039
it is just empty page , is seems nothing print out.

I change like following, it is still empty page, but
the header is print out, I have use chmod, it is nothing to to with it,

thanks!
0
 
LVL 3

Expert Comment

by:guadalupe
ID: 2598281
What happens when you run it from the browser...?

Could it be a problem of permissions?

Try doing a chmod of 755 to give all users permission to execute the script.
0
 
LVL 3

Expert Comment

by:guadalupe
ID: 2598292
And what do you get from the command line...?
0
 
LVL 3

Expert Comment

by:guadalupe
ID: 2600410
Are you outputting anything before the  MIME type header...?  Make sure that this is the veryt first print line that goes to standard out (that is to say the first print that doesn't explicitly specify some file handle)

print "Content-type: text/html\n\n";



And what doe you see in the browser wibd when you call it...?
0
 
LVL 1

Accepted Solution

by:
Hardaway earned 50 total points
ID: 2607861
One more thing, please view the HTML source code. It was because blank page should contained some HTML tags. If you can see the "<pre>" tag, then the blank page might cause by the for loop(output nothing). Otherwise, the Perl script was not writting HTML output.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now