Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi thanks to Perls of Wisdom and a little help from Dmitry Ovsyanko, I'm farther down the line with my new simple script for converting xlsx2csv. Now I have a new error:

"error: No filename given at line 33"

Here's the code again:

#!/usr/local/bin/perl use Spreadsheet::XLSX; use Spreadsheet::XLSX::Utility2007; use Tk; my $mw = new MainWindow; my $mbar = $mw -> Menu(); $mw -> configure(-menu => $mbar); my $file = $mbar -> cascade(-label=>"File", -underline=>0, -tearoff => + 0); $file -> checkbutton(-label =>"Open", -underline => 0, -command => [\&menuopenClicked, "Open"]); $file -> command(-label =>"Save", -underline => 0, -command => [\&menusavedClicked, "Save"]); $file -> separator(); $file -> command(-label =>"Exit", -underline => 1, -command => sub { exit } ); MainLoop; sub menuopenClicked { my $typesopen = [ ['Excel 2007 files', '.xls'], ['All files', '*'],]; my $mainfilepath = $mw->getOpenFile(-filetypes => $typesop +en, -defaultextension => '.xls'); my $regions = '1-A1:G:110' ; my $rotate = 1; open($mainfilepath, "> $mainfilepath"); my $filename = $mainfilepath; close $mainfilepath; my $csvtxt = Spreadsheet::XLSX::Utility2007::xls2csv($filename, $regio +ns, $rotate); sub menusavedClicked { my $typesaved = [ ['Excel 2007 files', '.xlsx'], ['All files', '*'],]; my $saved = $mw->getSaveFile(-filetypes => $typessaved, -defaultextension => '.csv'); open($saved, "> $saved") || die "Can't create <$saved> for output!\n"; print ($saved $csvtxt) if $saved; close $saved; }}
I have tried various methods to get rid of this error, like putting single or double quotes around $filename or removing the statement:
open($mainfilepath, "> $mainfilepath");
I also tried loading an xls file instead of an xlsx file, after all the function is called xls2csv for some reason. That's the way the script is now, but it doesn't make a bit of difference. Additionally I copied both xls and xlsx files to the root, C:\ in my Windows installation thinking it might be a path issue. Neither file worked and neither file has a space in the name. It seems I am defining the filename with $filename, what's wrong?

In reply to Further On Down the Line by socrtwo

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2022-01-19 22:25 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (56 votes). Check out past polls.