Guest User

Untitled

a guest
Aug 9th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.45 KB | None | 0 0
  1. ############################################################
  2. # Ch10Lab3.pl
  3. # Zachary Shepherd
  4. # May 12th
  5. # Final
  6. ############################################################
  7.  
  8. use strict;
  9. use Spreadsheet::WriteExcel; # Using module for this script.
  10.  
  11. # Variables/Arrays
  12. my ($filename, $row, $column);
  13. $row = 2;
  14. $column = 1;
  15.  
  16.  
  17. # Sets up the spreadsheet and creates first (and only) worksheet.
  18. my $spreadprices    = Spreadsheet::WriteExcel->new("prices.xls");
  19. my $worksheet       = $spreadprices->addworksheet("State Prices");
  20.  
  21. # Fleshes out the first row of spreadsheet with required information.
  22. $worksheet->write_string(0,0, "Market St.");
  23. $worksheet->write_string(0,1, "State Abbr.");
  24. $worksheet->write_string(0,2, "Market City    ");
  25. $worksheet->write_string(0,3, "Average Sales Price");
  26.  
  27. # Input information from user.
  28. print "Which file would you like to create a spreadsheet with?\n";
  29. chomp ($filename = <STDIN>);        # Should be 'prices_a.txt' for testing purposes.
  30. open IF, $filename or die "Can't find the file $filename: $!";
  31.  
  32. while (<IF>) {
  33.     s/^\t{1,2}//;
  34.     unless (/^State/ or /^\n$/) {
  35.         my @linearray;
  36.         @linearray = split ('\t', $_);
  37.             if (/^\w+$/) {
  38.                 $worksheet->write_string($row,0,@linearray);
  39.                 } else {
  40.                     $worksheet->write_string($row,$column++, $linearray[0]);
  41.                     $worksheet->write_string($row,$column++, $linearray[1]);
  42.                     $worksheet->write($row,$column++, $linearray[2]);
  43.                     $column = 1;
  44.                         }
  45.             $row++;
  46.         }
  47.     }
Add Comment
Please, Sign In to add comment