Ask a Question related to PERL Beginners, Design and Development.
-
Dodo #1
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
-
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... -
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; -
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... -
"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... -
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... -
Jeff 'Japhy' Pinyan #2
Re: undefined subroutine
On Oct 8, Dodo said:
That's because none of those are Perl functions. You need to look at some>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.
Perl tutorial or beginner's manual so you know what you're doing.
open BLAH, "< c:/Inetpub/wwwroot/dg/menu.txt">$fd = fopen('C:\Inetpub\wwwroot\dg\menu.txt',"r");
or die "can't read c:/Inetpub/wwwroot/dg/menu.txt: $!";
That can be done in many ways...>$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.
close BLAH;>fclose($fd);
my @chunks = split /%%/, $content;>$lines = explode ("%%",$line);
I don't know what to tell you here... Perl has nicer for loops than C, so>for ($i=0;$i<$line[0];$i++) {$item = $lines[$i+1];
you might want to use a Perl loop.
You probably want require().>include ($strMiddleCell);
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
-
Dodo #3
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
-
Rob Dixon #4
Re: undefined subroutine
Jeff 'Japhy' Pinyan wrote:
my $fd;>
> 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: $!";
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.
I'm staying faithful to:>> >$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.
my $content = do {local $/; <$fd>};
:)
....but even so it looks like it should work as it is.>> >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.
What exactly is the problem?
I guess it's a question from a job interview. They're>> >include ($strMiddleCell);
> You probably want require().
>
> But WHY are you converting a PHP program to Perl? What's the point?
waiting to see if he comes back and asks :-D
Rob
Rob Dixon Guest
-
Jeff 'Japhy' Pinyan #5
Re: undefined subroutine
On Oct 8, Rob Dixon said:
Only if he's got a version of Perl that supports that syntax.>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.
Last I checked, that makes TWO copies of the string from <$fd>: one in>>>>> >$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>};
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
-
Dodo #6
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
-
Rob Dixon #7
Re: undefined subroutine
Jeff 'Japhy' Pinyan wrote:
True. I think it's been around since 5.0. Do you know?>
> 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.
That's interesting. You mean there's a temporary internal>> >> >> >$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.
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
-
Jan Gruber #8
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
-
Rob Dixon #9
Re: Undefined subroutine
Jan Gruber wrote:
At first guess it looks like a problem with DynaLoader. But can>
> 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 ...."
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
-
Jan Gruber #10
Re: Undefined subroutine
Hi
Right, its in there.> 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
NO, it didn't.> and should read
> package Modules::Eris_Gate
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
-
Drieux #11
Re: Undefined subroutine
On Dec 3, 2003, at 3:59 AM, Jan Gruber wrote:
[..]that looks like an 'autoloader' event.> 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]
Ok, so what IS at that lines 146..148 ???> First of all, the line numbers are wrong, looking at the source there
> is no
> sub definition in these lines.
That is basically bassEndYakWard.> In Eris_Gate.pm:
> @EXPORT contains the names for the subs to be exported, @EXPORT_OK is
> empty
> and the package @ISA (Exporter).
It would be politer to have them in
the @EXPORT_OK, and only push out a few
key default ones in @EXPORT.
It might help us if you told us where we could> I use Modules::Eris_Gate; in the script, but calling a sub defined in
> there
> results in "Undefined subroutine &main::return_sumfink called at ...."
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
-
Drieux #12
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



Reply With Quote

