undefined subroutine

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default undefined subroutine

    I'm doing a php to pl migration and having a little trouble. Help
    appreciated!

    Undefined subroutine &main::fopen called at C:\Inetpub\wwwroot\dg\index.pl
    line 91.
    I get the same error for filesize, fclose, explode and include.

    $fd = fopen('C:\Inetpub\wwwroot\dg\menu.txt',"r");
    $line = fread($fd,filesize("C:\Inetpub\wwwroot\dg\menu.txt "));
    fclose($fd);
    $lines = explode ("%%",$line);
    for ($i=0;$i<$line[0];$i++) {$item = $lines[$i+1];

    include ($strMiddleCell);


    Dodo Guest

  2. Similar Questions and Discussions

    1. subroutine problem
      Hi all, I have recently started to learn perl. After reading Randal Schwartz’s Learning perl, I decided to give my first program a whirl. Upon...
    2. Undefined subroutine &IO::String
      Hey, When I run the following programme: #! c:\Perl\bin\perl.exe -w -i use strict; use warnings; use Bio::Perl; use Bio::SeqIO;
    3. using subroutine from another file
      Let's say thatI wroute some code long time ago: code1.pl. In the file there is this subroutine1(); now I am writting another code code2.pl, and...
    4. "Undefined subroutine" error (but it's defined, I think?)
      I have a program divided into 3 modules plus a main script, and some of the modules call functions within other modules. Most of the time this...
    5. What is an undefined offset? An undefined index?
      I just switched error_reporting to ALL so I could debug my site. I got a huge page full of errors. One of the most common was that in my arrays I'm...
  3. #2

    Default Re: undefined subroutine

    On Oct 8, Dodo said:
    >Undefined subroutine &main::fopen called at C:\Inetpub\wwwroot\dg\index.pl
    >line 91.
    >I get the same error for filesize, fclose, explode and include.
    That's because none of those are Perl functions. You need to look at some
    Perl tutorial or beginner's manual so you know what you're doing.
    >$fd = fopen('C:\Inetpub\wwwroot\dg\menu.txt',"r");
    open BLAH, "< c:/Inetpub/wwwroot/dg/menu.txt"
    or die "can't read c:/Inetpub/wwwroot/dg/menu.txt: $!";
    >$line = fread($fd,filesize("C:\Inetpub\wwwroot\dg\menu.txt "));
    That can be done in many ways...

    my $content = join "", <BLAH>;
    # or
    my $content; { local $/; $content = <BLAH>; }
    # or
    read(BLAH, my $content, -s BLAH);
    # etc.
    >fclose($fd);
    close BLAH;
    >$lines = explode ("%%",$line);
    my @chunks = split /%%/, $content;
    >for ($i=0;$i<$line[0];$i++) {$item = $lines[$i+1];
    I don't know what to tell you here... Perl has nicer for loops than C, so
    you might want to use a Perl loop.
    >include ($strMiddleCell);
    You probably want require().

    But WHY are you converting a PHP program to Perl? What's the point?

    --
    Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
    RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
    <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
    [ I'm looking for programming work. If you like my work, let me know. ]

    Jeff 'Japhy' Pinyan Guest

  4. #3

    Default Re: undefined subroutine

    I'm trying to convert so I can use a server that doesn't support PHP, but
    I'm giving up. With my limited knowledge I think it's impossible. I was told
    that the scripting was all Perl, so conversion should have been easy. But, I
    guess there's some C mixed in there as well or maybe some of it is PHP
    specific.


    Dodo Guest

  5. #4

    Default Re: undefined subroutine

    Jeff 'Japhy' Pinyan wrote:
    >
    > On Oct 8, Dodo said:
    >
    > >Undefined subroutine &main::fopen called at C:\Inetpub\wwwroot\dg\index.pl
    > >line 91.
    > >I get the same error for filesize, fclose, explode and include.
    >
    > That's because none of those are Perl functions. You need to look at some
    > Perl tutorial or beginner's manual so you know what you're doing.
    >
    > >$fd = fopen('C:\Inetpub\wwwroot\dg\menu.txt',"r");
    >
    > open BLAH, "< c:/Inetpub/wwwroot/dg/menu.txt"
    > or die "can't read c:/Inetpub/wwwroot/dg/menu.txt: $!";
    my $fd;
    open $fd, '< c:/Inetpub/wwwroot/dg/menu.txt';

    might be a better match? With $fd in place of 'BLAH' in the
    rest of the code.
    > >$line = fread($fd,filesize("C:\Inetpub\wwwroot\dg\menu.txt "));
    >
    > That can be done in many ways...
    >
    > my $content = join "", <BLAH>;
    > # or
    > my $content; { local $/; $content = <BLAH>; }
    > # or
    > read(BLAH, my $content, -s BLAH);
    > # etc.
    I'm staying faithful to:

    my $content = do {local $/; <$fd>};

    :)
    > >fclose($fd);
    >
    > close BLAH;
    >
    > >$lines = explode ("%%",$line);
    >
    > my @chunks = split /%%/, $content;
    >
    > >for ($i=0;$i<$line[0];$i++) {$item = $lines[$i+1];
    >
    > I don't know what to tell you here... Perl has nicer for loops than C, so
    > you might want to use a Perl loop.
    ....but even so it looks like it should work as it is.
    What exactly is the problem?
    > >include ($strMiddleCell);
    >
    > You probably want require().
    >
    > But WHY are you converting a PHP program to Perl? What's the point?
    I guess it's a question from a job interview. They're
    waiting to see if he comes back and asks :-D

    Rob


    Rob Dixon Guest

  6. #5

    Default Re: undefined subroutine

    On Oct 8, Rob Dixon said:
    >Jeff 'Japhy' Pinyan wrote:
    >>
    >> open BLAH, "< c:/Inetpub/wwwroot/dg/menu.txt"
    >> or die "can't read c:/Inetpub/wwwroot/dg/menu.txt: $!";
    >
    > my $fd;
    > open $fd, '< c:/Inetpub/wwwroot/dg/menu.txt';
    >
    >might be a better match? With $fd in place of 'BLAH' in the
    >rest of the code.
    Only if he's got a version of Perl that supports that syntax.
    >> >$line = fread($fd,filesize("C:\Inetpub\wwwroot\dg\menu.txt "));
    >>
    >> my $content = join "", <BLAH>;
    >> # or
    >> my $content; { local $/; $content = <BLAH>; }
    >> # or
    >> read(BLAH, my $content, -s BLAH);
    >> # etc.
    >
    >I'm staying faithful to:
    >
    > my $content = do {local $/; <$fd>};
    Last I checked, that makes TWO copies of the string from <$fd>: one in
    the do BLOCK, and then it gets copied and returned to $content. I could
    be wrong, but I think I heard about it on p5p.

    --
    Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
    RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
    <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
    [ I'm looking for programming work. If you like my work, let me know. ]

    Jeff 'Japhy' Pinyan Guest

  7. #6

    Default Re: undefined subroutine

    I'm trying to convert so I can use a server that doesn't support PHP, but
    I'm giving up. With my limited knowledge I think it's impossible. I was told
    that the scripting was all Perl, so conversion should have been easy. But, I
    guess there's some C mixed in there as well or maybe some of it is PHP
    specific.


    Dodo Guest

  8. #7

    Default Re: undefined subroutine

    Jeff 'Japhy' Pinyan wrote:
    >
    > On Oct 8, Rob Dixon said:
    > >
    > >Jeff 'Japhy' Pinyan wrote:
    > >>
    > >> open BLAH, "< c:/Inetpub/wwwroot/dg/menu.txt"
    > >> or die "can't read c:/Inetpub/wwwroot/dg/menu.txt: $!";
    > >
    > > my $fd;
    > > open $fd, '< c:/Inetpub/wwwroot/dg/menu.txt';
    > >
    > >might be a better match? With $fd in place of 'BLAH' in the
    > >rest of the code.
    >
    > Only if he's got a version of Perl that supports that syntax.
    True. I think it's been around since 5.0. Do you know?
    > >> >$line = fread($fd,filesize("C:\Inetpub\wwwroot\dg\menu.txt "));
    > >>
    > >> my $content = join "", <BLAH>;
    > >> # or
    > >> my $content; { local $/; $content = <BLAH>; }
    > >> # or
    > >> read(BLAH, my $content, -s BLAH);
    > >> # etc.
    > >
    > >I'm staying faithful to:
    > >
    > > my $content = do {local $/; <$fd>};
    >
    > Last I checked, that makes TWO copies of the string from <$fd>: one in
    > the do BLOCK, and then it gets copied and returned to $content. I could
    > be wrong, but I think I heard about it on p5p.
    That's interesting. You mean there's a temporary internal
    scalar in the copy process? It's almost certainly the same
    as:

    sub readall {
    my $fh = shift;
    local $/;
    <$fh>;
    }

    my $content = readall \*FH;

    when the return value would have to be stacked.

    Certainly worth thinking about for Gb files, but
    it's ripe for in-line optimisation.

    I might check. One day :)

    Cheers,

    Rob


    Rob Dixon Guest

  9. #8

    Default Undefined subroutine

    Hi!

    What could be a possible reason, that functions exported by a module appear
    like that in the Symbol Table:

    Eris_Gate::__ANON__[/usr/lib/perl5/site_perl/5.8.0/Modules/Eris_Gate.pm:146]
    Eris_Gate::__ANON__[/usr/lib/perl5/site_perl/5.8.0/Modules/Eris_Gate.pm:147]
    Eris_Gate::__ANON__[/usr/lib/perl5/site_perl/5.8.0/Modules/Eris_Gate.pm:148]

    First of all, the line numbers are wrong, looking at the source there is no
    sub definition in these lines.

    In Eris_Gate.pm:
    @EXPORT contains the names for the subs to be exported, @EXPORT_OK is empty
    and the package @ISA (Exporter).

    I use Modules::Eris_Gate; in the script, but calling a sub defined in there
    results in "Undefined subroutine &main::return_sumfink called at ...."

    What am i missing?

    TIA
    Jan
    --
    cat /dev/world | perl -e "while (<>) {(/(^.*?\?) 42\!/) && (print $1)}"
    errors->(c)
    -
    Jan Gruber Guest

  10. #9

    Default Re: Undefined subroutine

    Jan Gruber wrote:
    >
    > What could be a possible reason, that functions exported by a module appear
    > like that in the Symbol Table:
    >
    > Eris_Gate::__ANON__[/usr/lib/perl5/site_perl/5.8.0/Modules/Eris_Gate.pm:146]
    > Eris_Gate::__ANON__[/usr/lib/perl5/site_perl/5.8.0/Modules/Eris_Gate.pm:147]
    > Eris_Gate::__ANON__[/usr/lib/perl5/site_perl/5.8.0/Modules/Eris_Gate.pm:148]
    >
    > First of all, the line numbers are wrong, looking at the source there is no
    > sub definition in these lines.
    >
    > In Eris_Gate.pm:
    > @EXPORT contains the names for the subs to be exported, @EXPORT_OK is empty
    > and the package @ISA (Exporter).
    >
    > I use Modules::Eris_Gate; in the script, but calling a sub defined in there
    > results in "Undefined subroutine &main::return_sumfink called at ...."
    At first guess it looks like a problem with DynaLoader. But can
    you show us what code you've used to produce your output?

    Where is Eris_Gate.pm, and what is its package declaration? From
    what you say it should be in

    /usr/lib/perl5/site_perl/5.8.0/Modules

    and should read

    package Modules::Eris_Gate

    Is that right?

    Rob


    Rob Dixon Guest

  11. #10

    Default Re: Undefined subroutine

    Hi
    > Where is Eris_Gate.pm, and what is its package declaration? From
    > what you say it should be in
    > /usr/lib/perl5/site_perl/5.8.0/Modules
    Right, its in there.
    > and should read
    > package Modules::Eris_Gate
    NO, it didn't.
    It read "package Eris_gate" before. Thanks, I missed this one at least 50
    times and I wont forget to name my packages correctly from now on.

    Best regards,
    Jan
    --
    cat /dev/world | perl -e "while (<>) {(/(^.*?\?) 42\!/) && (print $1)}"
    errors->(c)
    -
    Jan Gruber Guest

  12. #11

    Default Re: Undefined subroutine


    On Dec 3, 2003, at 3:59 AM, Jan Gruber wrote:
    [..]
    > What could be a possible reason, that functions exported by a module
    > appear
    > like that in the Symbol Table:
    >
    > Eris_Gate::__ANON__[/usr/lib/perl5/site_perl/5.8.0/Modules/
    > Eris_Gate.pm:146]
    > Eris_Gate::__ANON__[/usr/lib/perl5/site_perl/5.8.0/Modules/
    > Eris_Gate.pm:147]
    > Eris_Gate::__ANON__[/usr/lib/perl5/site_perl/5.8.0/Modules/
    > Eris_Gate.pm:148]
    that looks like an 'autoloader' event.
    > First of all, the line numbers are wrong, looking at the source there
    > is no
    > sub definition in these lines.
    Ok, so what IS at that lines 146..148 ???
    > In Eris_Gate.pm:
    > @EXPORT contains the names for the subs to be exported, @EXPORT_OK is
    > empty
    > and the package @ISA (Exporter).
    That is basically bassEndYakWard.
    It would be politer to have them in
    the @EXPORT_OK, and only push out a few
    key default ones in @EXPORT.
    > I use Modules::Eris_Gate; in the script, but calling a sub defined in
    > there
    > results in "Undefined subroutine &main::return_sumfink called at ...."
    It might help us if you told us where we could
    find this module, and what it is suppose to be about.
    > What am i missing?

    As Rob noted, there is that question
    of how exactly does the package line
    in it read. Does it read as

    package Modules::Eris_Gate;

    and hence your

    use Modules::Eris_Gate;

    should have picked it up correctly.

    OR does it read

    package Eris_Gate;

    hence you should have used

    use lib "/usr/lib/perl5/site_perl/5.8.0/Modules";
    use Eris_Gate;




    ciao
    drieux

    ---

    Drieux Guest

  13. #12

    Default Re: Undefined subroutine


    On Dec 3, 2003, at 7:55 AM, Jan Gruber wrote:
    [..]
    >> Where is Eris_Gate.pm, and what is its package declaration? From
    >> what you say it should be in
    >> /usr/lib/perl5/site_perl/5.8.0/Modules
    >
    > Right, its in there.
    >
    >> and should read
    >> package Modules::Eris_Gate
    >
    > NO, it didn't.
    > It read "package Eris_gate" before. Thanks, I missed this one at least
    > 50
    > times and I wont forget to name my packages correctly from now on.
    [..]

    You might want to take the time to read

    perldoc h2xs

    it can be such a help when one is starting
    out with creating perl modules.

    ciao
    drieux

    ---

    Drieux Guest

Posting Permissions

  • You may not post new threads
  • You may 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