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

Doubt regarding parsing

by pavanpvss (Novice)
on Apr 04, 2012 at 17:56 UTC ( #963496=perlquestion: print w/ replies, xml ) Need Help??
pavanpvss has asked for the wisdom of the Perl Monks concerning the following question:

use Spreadsheet::ParseExcel; my $filename = shift || "C:\Earthlink.xls"; my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse("$filename"); if ( !defined $workbook ) { die $parser->error(), ".\n"; }

I have saved the excel sheet in C:/ drive in 95-2003 format.In the above code i am getting error as File Not Found. I am not getting any value in $workbook. Can anbody please help me ?

Comment on Doubt regarding parsing
Download Code
Re: Doubt regarding parsing
by toolic (Chancellor) on Apr 04, 2012 at 18:04 UTC
    Tip #2 from the Basic debugging checklist: print
    use Spreadsheet::ParseExcel; my $filename = shift || "C:\Earthlink.xls"; print "$filename\n"; my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse("$filename"); if ( !defined $workbook ) { die $parser->error(), ".\n"; }

    This prints:

    C:arthlink.xls File not found.

    Use single quotes to prevent interpolation of \E:

    my $filename = shift || 'C:\Earthlink.xls';

    A good text editor with syntax highlighting is also helpful in distinguishing literal strings from escape sequences.

      use Spreadsheet::ParseExcel; my $filename = shift || 'c:\\Earthlink.xls'; my $parser = Spreadsheet::ParseExcel->new(); print $filename; my $workbook = $parser->parse($filename); if ( !defined $workbook ) { die $parser->error(), ".\n"; }
      I am still getting the message as file not found.
        Copy and paste the exact line that I showed. You have an extra \

        Why have you changed the single backslash to a double backslash?

        Update: oops, too late...

        The double \\ is always OK (although in single quotes it is often redundant). That is not your problem now, and maybe never was. If you are passing a file name on the command line then the default file name is irrelevant. As a sanity check you should:

        die "Can't find $filename\n" if ! -f $filename;

        before the parse line. Note that -f tests for the existence of a file so the die will happen if the file is missing, even if there is a directory of that name.

        Most likely you are passing a file name for a file that exists in a different directory than is the current directory when you run the script. The die line will detect and report that.

        Note that strictures (use strict; use warnings;) pick up bad escape sequences and would often catch your initial error (although not \E). You should always use strictures.

        True laziness is hard work

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-08-20 12:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (113 votes), past polls