Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Creating a table from text delimited by newlines

by chipmunk (Parson)
on Nov 26, 2001 at 08:49 UTC ( #127489=note: print w/replies, xml ) Need Help??


in reply to Creating a table from text delimited by newlines

I'm not completely certain what you want the result to be, but I think this code does something like what you're looking for:
$line = ''; while (<FH>) { chomp; if (length) { $line .= "$_ "; } else { print <<"EOHTML"; <TR> <TD>Checkbox</TD> <TD>$line</TD> </TR> <TR bgcolor=#000066><TD WIDTH=298>&nbsp;</TD><TD WIDTH=298>&nbsp;</TD> +</TR> EOHTML $line = ''; } } if (length $line) { print <<"EOHTML"; <TR> <TD>Checkbox</TD> <TD>$line</TD> </TR> EOHTML }
Note that I replaced the regex with a call to length. I think this is a clearer way to check whether the line contained any text (after chomping, of course).

Your question would be clearer with sample input and output...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2020-01-21 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?