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

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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. ...
    5. 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...
  3. #2

    Default Re: modules and _DATA_

    On Jan 23, 2004, at 3: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.
    I believe your DATA tag at the end is the problem. It's supposed to be
    __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

  4. #3

    Default 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 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.
    I believe your DATA tag at the end is the problem. It's supposed to be
    __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
    >
    sorry I was typing to fast, it is __DATA__ This program was working before but

    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

  5. #4

    Default 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

  6. #5

    Default Re: modules and _DATA_

    On 1/23/2004 4: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?
    __DATA__ must be in package main;

    #!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

  7. #6

    Default 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

  8. #7

    Default 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:
    >
    > 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?
    __DATA__ must be in package main;

    #!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

  9. #8

    Default 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

  10. #9

    Default Re: modules and _DATA_


    On Jan 23, 2004, at 2:47 PM, Eric Walker wrote:
    [..]
    >
    > while <DATA>{
    > do something;}
    > *********** package ONE
    > ************ package stuff;
    > ************ 1;
    >
    > *********** package main
    > **********
    > ************ __DATA__
    > *********** data stufff
    yes, one can do the reset back to package main.

    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

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