Solved

how to format html output

Posted on 2000-03-13
3
227 Views
Last Modified: 2010-03-05
his 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.


how to use html ouput format to make the output exactly llike this?

thanks!
0
Comment
Question by:syu1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2612446
just add a <pre> tag before printing the output and a </pre> tag after you  have finished printing.

Eg.

print "Content-type: text/html\n\n";
print "<pre>\n";
# Start printing out the dbm information.
                                              for $number (sort keys %contents)
                                              {

........................

      # Write it...
                                                 write;
                                              }

print "</pre>\n";

0
 
LVL 16

Accepted Solution

by:
maneshr earned 50 total points
ID: 2612574
or you could try this too!!

#!/usr/local/bin/perl

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

$count=1;
$number=100;
$type="Hardware";
$name="Nail";
$price="0.15";
$desc="Used to sand all sorts of things, except sand.";

$^=STDOUT_TOP;
write;

$count=2;
$number=400;
$type="Hardware";
$name="Nuts";
$price="0.45";
$desc="Used to drive people crazy!!.";

$^=STDOUT_TOP;
write;

print "</table>\n";

# Top of picture formats.
format STDOUT_TOP=
<TABLE BORDER=1>
<TD>Count</TD><TD>Item #</TD><TD>Item Type</TD><TD>Item Name</TD><TD>Price</TD>
<TD>Description</TD><TD>Page @>>>>>>
$FORMAT_PAGE_NUMBER
</TD><TR>
..

format STDOUT=
<TD> @>>>> </TD><TD> @|||||| </TD><TD> @<<<<<<<<< </TD><TD> @<<<<<<<<<<<<< $</T
D><TD> @####.## </TD><TD>^<<<<<<<<<<<<<<<<<<<<<<<<<
$count,$number,$type,$name,$price,$desc
~   ^<<<<<<<<<<<<<<<<<<<<<<<<<
$desc
~   ^<<<<<<<<<<<<<<<<<<<<<<<<<
$desc
</TD><TR>
..
0
 

Author Comment

by:syu1
ID: 2613807
thanks lot for your hint, I use the table , it works fine.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using Perl to parse rows 7 101
Perl regex to replace any capital letters not preceded by ">" 6 164
Regex rule to match two different url 5 76
Perl Snippet to Parse String 1 38
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

733 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