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

Re: I feel stupid... 2 hours later

by Kenosis (Priest)
on Nov 24, 2012 at 07:37 UTC ( #1005340=note: print w/ replies, xml ) Need Help??


in reply to I feel stupid... 2 hours later

I second 2teez's question about using a CSV module to parse your file. Given this, here's one option:

use strict; use warnings; use Text::CSV; my $csvFile = 'irregular-verbs.csv'; my $outFile = 'new.htm'; open my $outFH, '>', $outFile or die "Cannot open $outFile: $!"; my $csv = Text::CSV_XS->new( { binary => 1, auto_diag => 2 } ) or die "Cannot use CSV: " . Text::CSV->error_diag(); open my $csvFH, '<', $csvFile or die "Cannot open $csvFile: $!"; # $row contains an array reference to the parsed csv line's data while ( my $row = $csv->getline($csvFH) ) { print $outFH '<tr>'; print $outFH "<td>$_</td>" for @$row; print $outFH "<tr>\n"; } close $csvFH; close $outFH;

Output to file:

<tr><td>Base Form</td><td>Past Simple</td><td>Past Participle</td><td> +3rd Person Singular</td><td>Present Participle / Gerund</td><tr> <tr><td>Abide</td><td>Abode/Abided</td><td>Abode/Abided/Abidden</td><t +d>Abides</td><td>Abiding</td><tr> <tr><td>Aby/Abye</td><td>Abought</td><td>Abought</td><td>Abys/Abyes</t +d><td>Abying</td><tr> <tr><td>Alight</td><td>Alit/Alighted</td><td>Alit/Alighted</td><td>Ali +ghts</td><td>Alighting</td><tr> <tr><td>Arise</td><td>Arose</td><td>Arisen</td><td>Arises</td><td>Aris +ing</td><tr> <tr><td>Awake</td><td>Awoke</td><td>Awoken</td><td>Awakes</td><td>Awak +ing</td><tr>

Hope this helps!


Comment on Re: I feel stupid... 2 hours later
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2015-07-30 15:41 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 (272 votes), past polls