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

  • Thread starter niall.macpherson
  • Start date
N

niall.macpherson

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
 
P

Paul Lalli

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
 
N

niall.macpherson

Paul said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top