FAQ
Is it possible to have multiple __DATA__
entries in a program. I can seem to find
a way to end __DATA__, and @array is
getting everything. How to I end __DATA__?


Like:

@array = <DATA>;
@array1 = <DATA1>;

__DATA__
stuff
more stuff

__DATA1__
stuff
more stuff

Search Discussions

  • Michael Fowler at Feb 15, 2002 at 5:35 pm

    On Fri, Feb 15, 2002 at 12:06:22PM -0500, zentara wrote:
    Is it possible to have multiple __DATA__ entries in a program.
    No.

    I can seem to find a way to end __DATA__, and @array is getting
    everything. How to I end __DATA__?
    __DATA__ ends at EOF.


    The only alternative I can think of at the moment, short of using multiple
    files, is to place a marker in the text for where @array should stop and
    @array1 should begin.

    For example:

    #!/usr/bin/perl -w

    use strict;

    my(@array, @array1);
    while (my $line = <DATA>) {
    last if $line eq "EOD\n";
    push(@array, $line);
    }

    @array1 = <DATA>

    __DATA__
    stuff
    more stuff
    EOD
    stuff
    more stuff


    Michael
    --
    Administrator www.shoebox.net
    Programmer, System Administrator www.gallanttech.com
    --
  • Andrea Holstein at Feb 15, 2002 at 5:49 pm

    In article wrote "Zentara" <zentara@highstream.net>:

    Is it possible to have multiple __DATA__
    entries in a program. I can seem to find
    a way to end __DATA__, and @array is
    getting everything. How to I end __DATA__?


    Like:

    @array = <DATA>;
    @array1 = <DATA1>;

    __DATA__
    stuff
    more stuff

    __DATA1__
    stuff
    more stuff
    As I know, there is no builtin-possibility.
    But it's simple to simulate.

    my @data;
    my $nr = 0;
    while (<DATA>) {
    /^__DATA__/ ? $nr++ : push $data[$nr], $_;
    }

    Now assuming this data ending:

    __DATA__
    content 1
    __DATA__
    content 2
    __END__

    @{$data[0]} contains the first Data,
    @{$data[1]} the second, and so on.

    Best Wishes,
    Andrea
  • Jeff 'japhy' Pinyan at Feb 15, 2002 at 6:19 pm
    On Feb 15, zentara said:
    Is it possible to have multiple __DATA__
    entries in a program. I can seem to find
    a way to end __DATA__, and @array is
    getting everything. How to I end __DATA__?
    Sounds like you might want the Inline::Files module. If you don't want
    that overhead, though, you can use a homemade solution. I'll come up with
    something a little later.

    --
    Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
    RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
    ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
    <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. ]
  • Dennis G. Wicks at Feb 15, 2002 at 7:09 pm
    That would be great!

    Unfortunately, none of the fragments posted so far work as
    written!

    Looking forward to testing your solution!

    Thanks,
    Dennis
    }On Feb 15, 13:18, "Jeff 'japhy' Pinyan" wrote:
    } Subject: Re: multiple __DATA__ entries possible?

    Sounds like you might want the Inline::Files module. If you don't want
    that overhead, though, you can use a homemade solution. I'll come up with
    something a little later.
  • Michael Fowler at Feb 15, 2002 at 7:56 pm

    On Fri, Feb 15, 2002 at 01:09:32PM -0800, Dennis G. Wicks wrote:
    Unfortunately, none of the fragments posted so far work as
    written!
    None? The example I gave works just fine.


    Michael
    --
    Administrator www.shoebox.net
    Programmer, System Administrator www.gallanttech.com
    --
  • Dennis G. Wicks at Feb 15, 2002 at 8:32 pm
    Sorry, it doesn't *as written*.

    It required a ; after
    @array1 = <DATA>

    I revisited it and find that it does work after removing the
    leading white space from the EOD line.

    Yeah, it might be nit picking but those are the nits that
    drive us "beginners" crazy! It apparently doesn't make a
    difference that __DATA__ has leading white space, but
    obviously a *big* difference if EOD does! (I have figured
    out why. It is obvious from the results.)

    Thanks for your contributions. They have helped me a lot!
    Dennis

    }On Feb 15, 10:55, Michael Fowler wrote:
    } Subject: Re: multiple __DATA__ entries possible?
    On Fri, Feb 15, 2002 at 01:09:32PM -0800, Dennis G. Wicks wrote:
    Unfortunately, none of the fragments posted so far work as
    written!
    None? The example I gave works just fine.


    Michael
    --
    Administrator www.shoebox.net
    Programmer, System Administrator www.gallanttech.com
    --
    }-- End of excerpt from Michael Fowler
  • Michael Fowler at Feb 15, 2002 at 9:29 pm

    On Fri, Feb 15, 2002 at 02:32:19PM -0800, Dennis G. Wicks wrote:
    Sorry, it doesn't *as written*.

    It required a ; after
    @array1 = <DATA>
    It required a ; after that statement provided you put statements after it.

    I revisited it and find that it does work after removing the
    leading white space from the EOD line.
    All of the code was indented four spaces, for readability in email; it was
    intended that the indentation should be removed prior to trying to use it.
    I assumed that was apparent. I'll be more careful of it in the future.

    Thank you for the feedback.


    Michael
    --
    Administrator www.shoebox.net
    Programmer, System Administrator www.gallanttech.com
    --
  • Dennis G. Wicks at Feb 19, 2002 at 7:17 pm
    The split did the trick, and cut out a few lines of code
    also. I had already done some splits and joins to get ready
    for qw() which I can n ow delete!

    Thanks for the help everyone!
    Dennis

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedFeb 15, '02 at 5:07p
activeFeb 19, '02 at 7:17p
posts9
users5
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase