Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How do I search and output results to HTML from a CSV database file?

by bjelli (Pilgrim)
on May 15, 2001 at 15:48 UTC ( #80504=note: print w/ replies, xml ) Need Help??


in reply to How do I search and output results to HTML from a CSV database file?

nice soultions everyone, but sadly not for this problem. You are all parsing space-seperated data, but Sasquires data ist in fixed-width fields.

If you've got just a few fixed-width fields, you might want to try substr. If you have many fields, I would recommend unpack, like so:

while(<DATA>) @data = unpack("A8A10A2",$_); print join(",", @data), "\n"; } __DATA__ 12345678123456789012 longone evenlongerha a b c

the template string "A8A10A2" tells unpack to look for 8 Ascii Characters, then 10 Ascii Characters, then 2 Ascii Characters. unpack is also used a lot in handling binary data (which I don't understand). I just stick to this usage.

--
Brigitte    'I never met a chocolate I didnt like'    Jellinek
http://www.horus.com/~bjelli/         http://perlwelt.horus.at


Comment on Re: How do I search and output results to HTML from a CSV database file?
Download Code
Re: Re: How do I search and output results to HTML from a CSV database file?
by larryk (Friar) on May 15, 2001 at 16:59 UTC
    which in turn can be shortened to
    print join(",",unpack("A8A10A2",$_)),"\n" while <DATA>;
    and run from the command line as
    perl -i.bak -l -ne "print join(',',unpack('A8A10A2',$_));" filename
    this will do the conversion for you. I'm sure there's a module out there which parses comma delimited files into html tables. hope this helps

    larryk

    ---------------------------------------------------- $less->{'chars'} = `"time in the pub" | more`; # :-D
      The module you're thinking of is Data::Table. From the docs:
      $t = Data::Table::fromCSV("aaa.csv"); # Read a csv file into a table +oject print $t->html; # Display a 'portrait' HTML TAB +LE on web.
      buckaduck

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://80504]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2015-07-06 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (69 votes), past polls