Professional Web Applications Themes

cryptic error messages in modules - PERL Beginners

package My::Class; use strict; use warnings; use Class::Struct; use IO::File; struct MyStruct => { f1 => '$', f2 => '$' }; sub new { my ($class, $ifname) = _; my $s = {}; $class = ref($class) || $class; bless ($s, $class); $s->{FILE} = new IO::File($ifname, "r"); if ( !defined($s->{FILE}) ) { print("ERROR: $class: cannot open $ifname for reading\n"); exit(-1); } return $s; } sub f { return MyStruct->new(); } sub DESTROY { $s->{FILE}->close(); } ---------------------------------------------------------------------------------- if i make a perl script that uses My::Class and i construct an instance of My::Class and then call My::Class::f(), i get the following error: ...

  1. #1

    Default cryptic error messages in modules

    package My::Class;
    use strict;
    use warnings;
    use Class::Struct;
    use IO::File;

    struct MyStruct => {
    f1 => '$',
    f2 => '$'
    };

    sub new {
    my ($class, $ifname) = _;
    my $s = {};
    $class = ref($class) || $class;
    bless ($s, $class);
    $s->{FILE} = new IO::File($ifname, "r");
    if ( !defined($s->{FILE}) ) {
    print("ERROR: $class: cannot open $ifname for reading\n");
    exit(-1);
    }
    return $s;
    }

    sub f {
    return MyStruct->new();
    }

    sub DESTROY {
    $s->{FILE}->close();
    }

    ----------------------------------------------------------------------------------

    if i make a perl script that uses My::Class and i construct an instance of
    My::Class and then call My::Class::f(), i get the following error:
    Can't locate object method "new" via package "MyStruct" (perhaps you forgot
    to load "MyStruct"?)

    now obviously the problem is not that no new() method exists for MyStruct,
    but rather that i forgot to declare $s in DESTROY().

    it took me literally hours to figure out what the problem was. i mean,
    could the error message be anymore unrelated to the real problem? what the
    hell does $s not being declared in DESTROY() have anything to do with the
    error message i was given?

    thanks for the help and advice.

    Christopher Guest

  2. #2

    Default RE : cryptic error messages in modules


     
    Bottaro 
    reading\n"); 
    ------------------------------------------------------------------------
    -- 
    instance of 
    MyStruct, 
    mean, 
    what 
    the 

    I made a copy-paste of your above code, added the following to call f():

    package main;
    My::Class::f();

    And got the error message below:
    Global symbol "$s" requires explicit package name at try.pl line 31.
    Execution of try.pl aborted due to compilation errors.

    Which tells exactly what is going wrong: missing to declare $s in
    DESTROY().
    I'm wondering why you have got an other message.
    Double check ...

    José.



    Jose Guest

  3. #3

    Default Re: RE : cryptic error messages in modules

    Jose Nyimi wrote: 

    that is strange indeed. when i use my posted code, i get the proper error
    message, but in the code i'm really using, its as clear as day: if i don't
    declare $s in DESTROY(), perl complains about not finding new() in FHEAD
    (which is a Class::Struct that i declared). if i declare $s, the error
    message goes away.

    i'd post my code that is causing it, but i'd have to post 4 files...=/ if
    you are really curious, just send me an email and i'll send you the 4
    files.

    Christopher Guest

Similar Threads

  1. Multiple Error Messages, starting With 500 null Error
    By chickenloaf in forum Coldfusion Server Administration
    Replies: 1
    Last Post: June 22nd, 07:56 PM
  2. cryptic error message
    By lingo_user in forum Macromedia ColdFusion
    Replies: 2
    Last Post: June 16th, 06:47 PM
  3. Cryptic error message and crash
    By GJA in forum Macromedia Contribute General Discussion
    Replies: 1
    Last Post: February 23rd, 06:01 PM
  4. Error handling and custom error messages
    By Cedomir Markovic in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: July 10th, 09:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139