Using process as filehandle causes change in behaviour of <DATA>

Discussion in 'Perl Misc' started by niall.macpherson@ntlworld.com, Apr 7, 2006.

  1. Guest

    Sorry if the answer to this is obvious but I have been staring at this
    for some time now and searched clpm for <DATA> without any further
    enlightenment :(

    The attached code may seem pointless but it is the smallest piece of
    self contained code I could produce which replicates the problem I am
    seeing in my real code.

    When it is run as given it produces

    $VAR1 = 'string1';
    $VAR1 = 'string2';

    which is precisely what I would expect.

    However when I uncomment the #my $results = RunCommand(); line

    I see the following

    $VAR1 = 'string1';
    $VAR1 = '';
    $VAR1 = 'string2';

    Can anyone please explain where the extra empty value comes from ? I am
    running Active Perl 5.8.7 build 813 on Windoze XP

    Thanks

    use strict;
    use warnings;
    use Data::Dumper;
    ##---------------------------------------------------------------------
    sub RunCommand
    {
    my $cmd_string = 'dir';
    my $output = '';

    open(SQLPROC, "$cmd_string 2>NUL |");

    while(<SQLPROC>)
    {
    $output .= $_;
    }
    close SQLPROC;
    return($output);
    }
    ##--------------------------------------------------------------------------------------
    while(<DATA>)
    {
    chomp;
    print Dumper $_;
    #my $results = RunCommand();
    #print Dumper $results;
    }
    __DATA__
    string1
    string2
     
    , Apr 7, 2006
    #1
    1. Advertising

  2. Paul Lalli Guest

    wrote:
    > Sorry if the answer to this is obvious but I have been staring at this
    > for some time now and searched clpm for <DATA> without any further
    > enlightenment :(
    >
    > The attached code may seem pointless but it is the smallest piece of
    > self contained code I could produce which replicates the problem I am
    > seeing in my real code.
    >
    > When it is run as given it produces
    >
    > $VAR1 = 'string1';
    > $VAR1 = 'string2';
    >
    > which is precisely what I would expect.
    >
    > However when I uncomment the #my $results = RunCommand(); line
    >
    > I see the following
    >
    > $VAR1 = 'string1';
    > $VAR1 = '';
    > $VAR1 = 'string2';
    >
    > Can anyone please explain where the extra empty value comes from ? I am
    > running Active Perl 5.8.7 build 813 on Windoze XP


    There was a very similar thread just a few days ago:
    http://groups.google.com/group/comp.lang.perl.misc/browse_frm/thread/8e041391eddabe83/#

    I don't think any conclusive reasoning resulted from it, but the
    general consensus seems to be that there really is a problem with
    __DATA__ under Activestate's release of Perl. I don't know if anyone
    has submitted a bug to them yet, but you might want to consider it.

    Paul Lalli




    >
    > Thanks
    >
    > use strict;
    > use warnings;
    > use Data::Dumper;
    > ##---------------------------------------------------------------------
    > sub RunCommand
    > {
    > my $cmd_string = 'dir';
    > my $output = '';
    >
    > open(SQLPROC, "$cmd_string 2>NUL |");
    >
    > while(<SQLPROC>)
    > {
    > $output .= $_;
    > }
    > close SQLPROC;
    > return($output);
    > }
    > ##--------------------------------------------------------------------------------------
    > while(<DATA>)
    > {
    > chomp;
    > print Dumper $_;
    > #my $results = RunCommand();
    > #print Dumper $results;
    > }
    > __DATA__
    > string1
    > string2
     
    Paul Lalli, Apr 7, 2006
    #2
    1. Advertising

  3. Guest

    Paul Lalli wrote:

    >
    > There was a very similar thread just a few days ago:
    > http://groups.google.com/group/comp.lang.perl.misc/browse_frm/thread/8e041391eddabe83/#
    >
    > I don't think any conclusive reasoning resulted from it, but the
    > general consensus seems to be that there really is a problem with
    > __DATA__ under Activestate's release of Perl. I don't know if anyone
    > has submitted a bug to them yet, but you might want to consider it.
    >


    Thanks Paul - I do remember seeing this thread a couple of days ago now
    you mention it but being Friday afternoon my brain is working even more
    slowly than normal :(

    I've never submitted a bug report before but perldoc perlbug seems to
    give me all the information I require to do so , so I will give it a try
     
    , Apr 7, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xavier Osa
    Replies:
    0
    Views:
    645
    Xavier Osa
    Jan 9, 2004
  2. Jorge Godoy
    Replies:
    2
    Views:
    258
    Jorge Godoy
    Oct 14, 2003
  3. Alan J. Flavell

    The DATA filehandle and utf8

    Alan J. Flavell, Feb 19, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    87
    Alan J. Flavell
    Feb 19, 2004
  4. Shmuel (Seymour J.) Metz
    Replies:
    0
    Views:
    339
    Shmuel (Seymour J.) Metz
    May 21, 2006
  5. PerlFAQ Server
    Replies:
    0
    Views:
    185
    PerlFAQ Server
    Apr 23, 2011
Loading...

Share This Page