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

Comment on

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

In a module that has worked without error for a very long time, under Linux/Perl 5.8.1 I now get a warning about the following code:

package Chess::PGN::EPD; use strict; use warnings; use Chess::PGN::Moves; use File::Spec::Functions; use Storable qw( retrieve ); use Cwd qw( realpath ); use Try::Tiny qw( try catch ); require Exporter; my ( $hECO, $hNIC, $hOpening ); my %hash = ( ECO => \$hECO, NIC => \$hNIC, Opening => \$hOpening ); my $db_dir_qfn = realpath( catfile( __PACKAGE__, updir(), 'db' ) ); unless (-d $db_dir_qfn) { $db_dir_qfn = realpath('db'); }
The quote from the PAUSE report is:
Use of uninitialized value in -d at /home/sand/.cpan/build/Chess-PGN-E +PD-0.28-WRroyj/blib/lib/Chess/PGN/EPD.pm line 22. t/01_epdcode.t ...... ok t/02_Storable.t ..... ok Use of uninitialized value in -d at /home/sand/.cpan/build/Chess-PGN-EPD-0.28-WRroyj/blib/lib/Chess/PG +N/EPD.pm line 22 (#1) (W uninitialized) An undefined value was used as if it were alread +y defined. It was interpreted as a "" or a 0, but maybe it was a mi +stake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl tells you what ope +ration you used the undefined value in. Note, however, that perl optimiz +es your program and the operation displayed in the warning may not necessa +rily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer +to the concatenation (.) operator, even though there is no . in your program.
Line 22 is the unless (-d $db_dir_qfn) { line. I'd check to see just what is going on, but I'm flying blind until I replicate the test environment---in other words it works fine on all other Perls and under Windows of any type since 2K.

I've been pointed towards File::ShareDir and its associated modules but I found the documentation pretty much opaque (at least to me) leaving me hoping for a 'relative files for dummies' how-to. I'd certainly settle for an example based on the code fragment shown above :)

Note: I should point out that I realize that this is a warning, not an error. In addition, the code still manages to work in that all of the tests that depend on the presence of the data base files all work as designed. (Yes, I'm puzzled myself as to why it works given the warning...)

Update: A large single thanks to your collective wisdom. I am handicapped by the lack (for now) of a Linux box to test on. Had I one, I would have hit this with the appropriate size stick until the problem was solved. That said, I would have missed your observations and probably not have produced as accurate a solution. The observation about undef and that __PACKAGE__ was a wash point me in the correct direction. We'll see---again thanks much!

--hsm

"Never try to teach a pig to sing...it wastes your time and it annoys the pig."

In reply to Finding files relative to a module by hsmyers

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (13)
    As of 2014-07-11 16:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (232 votes), past polls