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

Re^3: Best way to print variables in regex

by tangent (Parson)
on Jan 22, 2014 at 03:04 UTC ( [id://1071559]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Best way to print variables in regex
in thread Best way to print variables in regex

One way would be to create a CSV file and then import that into your spreadsheet:
my $filename = '/path/to/file.csv'; open (my $fh, '>', $filename) or die "Could not open $filename, $!"; my @headers = qw( DET IN JJ NN VBD ); print $fh join(',',@headers) . "\n"; # then, for each of your phrases print $fh join(',', map($tags{$_} || 0, @headers) ) . "\n"; close $fh;
However, if you intend to do the tagging at different times you will need a way to update the data. You could use Spreadsheet::WriteExcel but there is a learning curve and probably overkill. Alternatively, you can keep your spreadsheet data as a CSV file and append to that file, or use Tie::Array::CSV to append:
use Tie::Array::CSV; my $filename = '/path/to/file.csv'; tie my @file, 'Tie::Array::CSV', $filename; # (this bit has been fixed - see comment below) # for each of your phrases my @row = map { $tags{$_} || 0 } @headers; push(@file,\@row); untie @file;

Replies are listed 'Best First'.
Re^4: Best way to print variables in regex
by Mordan (Initiate) on Jan 23, 2014 at 19:45 UTC

    That's great, thanks very much for your help

    One question on the append function - it puts it all into one cell. I can use text to columns in Excel to fix this but is there a way to do this in the append itself?

      One question on the append function - it puts it all into one cell
      There was an error in my code, I have fixed it now, sorry. When using Tie::Array::CSV you append (push) an array reference not a comma delimited string (the module does that bit for you).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (9)
As of 2024-04-23 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found