Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############################################################
- # Ch10Lab3.pl
- # Zachary Shepherd
- # May 12th
- # Final
- ############################################################
- use strict;
- use Spreadsheet::WriteExcel; # Using module for this script.
- # Variables/Arrays
- my ($filename, $row, $column);
- $row = 2;
- $column = 1;
- # Sets up the spreadsheet and creates first (and only) worksheet.
- my $spreadprices = Spreadsheet::WriteExcel->new("prices.xls");
- my $worksheet = $spreadprices->addworksheet("State Prices");
- # Fleshes out the first row of spreadsheet with required information.
- $worksheet->write_string(0,0, "Market St.");
- $worksheet->write_string(0,1, "State Abbr.");
- $worksheet->write_string(0,2, "Market City ");
- $worksheet->write_string(0,3, "Average Sales Price");
- # Input information from user.
- print "Which file would you like to create a spreadsheet with?\n";
- chomp ($filename = <STDIN>); # Should be 'prices_a.txt' for testing purposes.
- open IF, $filename or die "Can't find the file $filename: $!";
- while (<IF>) {
- s/^\t{1,2}//;
- unless (/^State/ or /^\n$/) {
- my @linearray;
- @linearray = split ('\t', $_);
- if (/^\w+$/) {
- $worksheet->write_string($row,0,@linearray);
- } else {
- $worksheet->write_string($row,$column++, $linearray[0]);
- $worksheet->write_string($row,$column++, $linearray[1]);
- $worksheet->write($row,$column++, $linearray[2]);
- $column = 1;
- }
- $row++;
- }
- }
Add Comment
Please, Sign In to add comment