Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Can't locate define.pm

by jaldama (Acolyte)
on Mar 07, 2012 at 16:10 UTC ( #958315=perlquestion: print w/ replies, xml ) Need Help??
jaldama has asked for the wisdom of the Perl Monks concerning the following question:

I've googled around, but haven't found anything regarding this:

Can't locate define.pm in @INC (@INC contains: /Library/Perl/Updates/5 +.10.0/darwin-thread-multi-2level /Library/Perl/Updates/5.10.0 /System +/Library/Perl/5.10.0/darwin-thread-multi-2level /System/Library/Perl/ +5.10.0 /Library/Perl/5.10.0/darwin-thread-multi-2level /Library/Perl/ +5.10.0 /Network/Library/Perl/5.10.0/darwin-thread-multi-2level /Netwo +rk/Library/Perl/5.10.0 /Network/Library/Perl /System/Library/Perl/Ext +ras/5.10.0/darwin-thread-multi-2level /System/Library/Perl/Extras/5.1 +0.0 .) at excel3.pl line 30. BEGIN failed--compilation aborted at excel3.pl line 30.

Does anyone know what is wrong? I am playing around with reading an excel file using Spreadsheet::Parseexcel

#!/usr/bin/perl -w use strict; use Spreadsheet::Parseexcel; #utility function to safely look inside a cell sub cell { my ($Wks, $r, $c) = @_; if (defined $Wks->{Cells} [$r] [$c]) { my $val = $Wks->{Cells} [$r] [$c]->Value; chomp $val; return $val; } return ""; } my $parser = new Spreadsheet::ParseExcel; my $workbook= $parser->Parse('tags sample.xls'); my $page = $workbook->{Worksheet} [0]; use define { TAGS => 0, PAGES => 1, PAGEVIEWS => 2, PAGEVISITS => 3 }; my ($tags, $pages, $pviews, $pvisits); format STDOUT_TOP = Tags Pages Page Views Page Visits . format STDOUT = @<<<<<<>>>>>>>>> @ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> $tags, $pages, $pviews, $pvisits . foreach(my $i=0; $i {MaxRow}; $i++) { $tags= cell ($page, $i, TAGS); $pages = cell($page, $i, PAGES); $pviews = cell($page, $i, PAGEVIEWS); $pvisits = cell($page, $i, PAGEVISITS); write; }

Comment on Can't locate define.pm
Select or Download Code
Re: Can't locate define.pm
by kcott (Abbot) on Mar 07, 2012 at 16:17 UTC

    The problem line (located about the middle of your code) is:

    use define {

    Perhaps you meant constant instead of define:

    use constant {

    Update: Well, you learn something every day. I wasn't aware that a define pragma existed on CPAN.

    From your code, it looks like constant will work just fine and you won't need to install it. If define is definitely what you want to use here, follow choroba's advice below.

    -- Ken

Re: Can't locate define.pm
by choroba (Abbot) on Mar 07, 2012 at 16:18 UTC
    The code tries to use define, but the module is not installed in the directories where Perl searches for modules. It is probably define which must be installed separately - probably by cpan.
Re: Can't locate define.pm
by marto (Chancellor) on Mar 07, 2012 at 16:22 UTC

    Your first problem:

    use Spreadsheet::Parseexcel;

    Should be:

    use Spreadsheet::ParseExcel;

    This is obviously just a typo in your post (hint, copy and paste what your actual code). Secondly, define is an old module you probably don't have installed, it's not core. Thirdly, what is MaxRow, it's only mentioned once in your code:

    foreach(my $i=0; $i {MaxRow}; $i++) {

    Update: Ignore the part I struck out, that's not accurate.

      Got it, thanks a lot everyone
      use Spreadsheet::Parseexcel;
      Should be:
      use Spreadsheet::ParseExcel;
      I'm not sure what you mean, but the proper capitalization is indeed Spreadsheet::ParseExcel. On case-insensitve filesystems and in case the module doesn't export anything (like, apparently this module) that would hardly seem to matter, but it is a proper habit to get into.

        bart, I scored this out because I found this worked when I tried it. I wanted to do some further digging, which I didn't get round to yesterday due to being very busy. I rarely code on Windows and was surprised this worked, as I'm used to the 'case counts' mentality. While I stand by this mentality (as you rightly say, it's a good habit to get into) I wanted to take the time to investigate if I'd done anything wrong in my test, or if perl as actually working as I expected on my windows laptop. Thanks.

Re: Can't locate define.pm
by Khen1950fx (Canon) on Mar 08, 2012 at 01:17 UTC
    define, like constant, is used at compile-time; hence, it has to be declared before any run. In this case, it really doesn't need to be used, but I used it to for debugging. The result might surprise you.
    #!/usr/bin/perl use Modern::Perl '2012'; use strictures 1; no strict 'refs'; use Spreadsheet::ParseExcel; use Devel::SimpleTrace 'showrefs'; use define DEBUG => 1; my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse('tags sample.xls'); my $page = $workbook->{Worksheet}[0]; my ( $tags, $pages, $pviews, $pvisits ); format STDOUT_TOP = Tags Pages Page Views Page Visits . format STDOUT = @<<<<<<>>>>>>>>> @ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> $tags, $pages, $pviews, $pvisits . my %i; foreach ( my $i = 0 ; $i{'MaxRow'} ; ++$i ) { $tags = cell( $page, $i, 0 ); $pages = cell( $page, $i, 1 ); $pviews = cell( $page, $i, 2 ); $pvisits = cell( $page, $i, 3 ); write; } cell(DEBUG); sub cell { my ( $Wks, $r, $c ) = @_; if ( defined( $$Wks{'Cells'}[$r][$c] ) ) { my $val = $$Wks{'Cells'}[$r][$c]->Value; chomp $val; return $val; } return ''; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2014-09-16 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (155 votes), past polls