Ask a Question related to PERL Beginners, Design and Development.
-
Eric Walker #1
modules and _DATA_
I have some code I want to add a package in the same file. I already
have some _DATA_ in the file. Currently, the code is not seeing the
_DATA_. How can I add a package in the same file then.
Thanks
perlknucklehead
example:
while <DATA>{
do something
}
_DATA_
this
is my
data
section
Eric Walker Guest
-
PHP & modules
Hi all I've just taken over a website and it has link like this index.php?mod=site. Now I need to make a news section that displays the topics... -
RE : how to use PPM ? If modules haven't in PPM ???
Sorry , I have to ask another question because PPM has no something... I search tk by ppm. It has no TK::JPEG. I saw JPEG from CPAN site. So, How... -
MMS Modules?
Hi has anyone heard of a Perl Module that can allow you to compose a MMS message, I wish to send a still image to my MMS phone from my PC -- Ian... -
using modules only when available
I have a program that has an optional GUI which makes use of Tk. On machines without Tk, the program errors out looking for the Tk modules. ... -
Modules for XS.
I need to call C functions from my Perl code, which requires XS. Since I never used it before, I want to know what modules need to be installed in... -
James Edward Gray II #2
Re: modules and _DATA_
On Jan 23, 2004, at 3:27 PM, Eric Walker wrote:
I believe your DATA tag at the end is the problem. It's supposed to be> I have some code I want to add a package in the same file. I already
> have some _DATA_ in the file. Currently, the code is not seeing the
> _DATA_. How can I add a package in the same file then.
__DATA__. That's underscore underscore D A T A underscore underscore.
Hope that helps.
James
> example:
> while <DATA>{
> do something
> }
>
> _DATA_
> this
> is my
> data
> section
>James Edward Gray II Guest
-
Eric Walker #3
Re: modules and _DATA_
On Fri, 2004-01-23 at 14:34, James Edward Gray II wrote:
On Jan 23, 2004, at 3:27 PM, Eric Walker wrote:
I believe your DATA tag at the end is the problem. It's supposed to be> I have some code I want to add a package in the same file. I already
> have some _DATA_ in the file. Currently, the code is not seeing the
> _DATA_. How can I add a package in the same file then.
__DATA__. That's underscore underscore D A T A underscore underscore.
Hope that helps.
James
sorry I was typing to fast, it is __DATA__ This program was working before but> example:
> while <DATA>{
> do something
> }
>
> _DATA_
> this
> is my
> data
> section
>
when I tried to add a package to it, I did some test and its not reading
the DATA anymore. Is there a certain order?
Eric Walker Guest
-
Drieux #4
Re: modules and _DATA_
On Jan 23, 2004, at 1:27 PM, Eric Walker wrote:
[..]> I have some code I want to add a package in the same file. I already
> have some _DATA_ in the file. Currently, the code is not seeing the
> _DATA_. How can I add a package in the same file then.
since the
__DATA__
vice
_DATA_
has been addressed, my pet favorite way to include a
package inside of a piece of code is
BEGIN {
package Foo::Bar;
....
}
That way it will be compiled early and so you can
place it above the __DATA__ section since it is
not 'data'.
ciao
drieux
---
Drieux Guest
-
Randy W. Sims #5
Re: modules and _DATA_
On 1/23/2004 4:36 PM, Eric Walker wrote:
__DATA__ must be in package main;>
> when I tried to add a package to it, I did some test and its not reading
> the DATA anymore. Is there a certain order?
#!perl
use strict;
use warnings;
while (<DATA>) {
print;
}
package Test;
sub a {}
1;
package main; # DATA must be in main
__DATA__
this
is my
data
section
Randy W. Sims Guest
-
Drieux #6
Re: modules and _DATA_
On Jan 23, 2004, at 1:36 PM, Eric Walker wrote:
[..][..]>
> when I tried to add a package to it, I did some test and its not
> reading
> the DATA anymore. Is there a certain order?
How did you put the package in?
ciao
drieux
---
#!/usr/bin/perl -w
use strict;
my $foo = new Foo::Bar;
while(<DATA>){
$foo->showMe($_);
}
BEGIN {
package Foo::Bar;
use 5.006;
use strict;
use warnings;
our $VERSION = '0.01';
#---------------------------------
# Our Stock Constructor
# note: <http://www.perlmonks.org/index.pl?node_id=52089>
sub new
{
my $class = shift;
my $self = {};
bless $self, $class;
} # end of our simple new
#---------------------------------
# so that AUTOLOAD finds one here
sub DESTROY {}
#------------------------
#
sub showMe
{
my ($me,$line) = @_;
print $line;
} # end of showMe
1; # so that the 'use Foo::Bar'
# will know we are happy
} # end begin
__DATA__
This line
and then the world.
Drieux Guest
-
Eric Walker #7
Re: modules and _DATA_
On Fri, 2004-01-23 at 14:43, Randy W. Sims wrote:
On 1/23/2004 4:36 PM, Eric Walker wrote:__DATA__ must be in package main;>
> when I tried to add a package to it, I did some test and its not reading
> the DATA anymore. Is there a certain order?
#!perl
use strict;
use warnings;
while (<DATA>) {
print;
}
package Test;
sub a {}
1;
package main; # DATA must be in main
__DATA__
this
is my
data
section
worked like a charm thanks, now its working but correctly time to get my handy dandy
print statement out...
Thanks..
Eric Walker Guest
-
Eric Walker #8
Re: modules and _DATA_
On Fri, 2004-01-23 at 14:46, drieux wrote:
On Jan 23, 2004, at 1:36 PM, Eric Walker wrote:
[..][..]>
> when I tried to add a package to it, I did some test and its not
> reading
> the DATA anymore. Is there a certain order?
How did you put the package in?
ciao
drieux
---
#!/usr/bin/perl -w
use strict;
my $foo = new Foo::Bar;
while(<DATA>){
$foo->showMe($_);
}
BEGIN {
package Foo::Bar;
use 5.006;
use strict;
use warnings;
our $VERSION = '0.01';
#---------------------------------
# Our Stock Constructor
# note: <http://www.perlmonks.org/index.pl?node_id=52089>
sub new
{
my $class = shift;
my $self = {};
bless $self, $class;
} # end of our simple new
#---------------------------------
# so that AUTOLOAD finds one here
sub DESTROY {}
#------------------------
#
sub showMe
{
my ($me,$line) = @_;
print $line;
} # end of showMe
1; # so that the 'use Foo::Bar'
# will know we are happy
} # end begin
__DATA__
This line
and then the world.
--
To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
while <DATA>{
do something;}
package ONE
package stuff;
1;
package main
__DATA__
data stufff
Eric Walker Guest
-
Drieux #9
Re: modules and _DATA_
On Jan 23, 2004, at 2:47 PM, Eric Walker wrote:
[..]yes, one can do the reset back to package main.>
> while <DATA>{
> do something;}
> *********** package ONE
> ************ package stuff;
> ************ 1;
>
> *********** package main
> **********
> ************ __DATA__
> *********** data stufff
part of the reason I opt for the
BEGIN { package .... }
approach is so that I know that the compiler
will deal with the BEGIN { BLOCK } before
worrying about anything else in the code.
That way I know that my objects will be sorted out foist.
As a general rule of thumb, though, once I have played
out an idea then it is going off to it's own
Monkey.pm
file where it is a fully externalized perl module...
ciao
drieux
---
Drieux Guest



Reply With Quote

