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
  • Comment on Re: How do I search and output results to HTML from a CSV database file?
  • Download Code

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