Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by ColtsFoot (Chaplain)
on May 15, 2001 at 09:34 UTC ( [id://80455]=note: print w/replies, xml ) Need Help??


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

I would use code similar to asiufy but within
the while loop I would use the split
function
while ($line = <FILE1>) { @fields = split / /, $line; $output = pop @fields; foreach $field (@fields) { $output = $output . ',' . $field; } print <FILE2> qq($output\n); }
This should cope with any number of fields and
any number of spaces between fields.

Hope this helps

Replies are listed 'Best First'.
Re: Re: How do I search and output results to HTML from a CSV database file?
by jeroenes (Priest) on May 15, 2001 at 10:21 UTC
    Indeed. But we can tidy up a bit:
    while( <FILE> ) { split; print FILE2 join ',' , @_; print FILE2 "\n"; }
    Here you see that the perl shorthands improve readibility.

    And this even compacts to (trading readability a bit):

    print FILE2 join( ',', split )."\n" while <FILE>; #or use SuperSplit; print FILE2 superjoin( ',', supersplit_open( $filename ) );

    Jeroen
    "We are not alone"(FZ)

      Jeroen your solutions realy show the power of perl
      As Sasquire was an "Initiate" I felt that my solution
      was a little easier to follow

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-03-29 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found