Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > ActivePerl perlscript output inconsistencies

Reply
Thread Tools

ActivePerl perlscript output inconsistencies

 
 
Henry Law
Guest
Posts: n/a
 
      09-18-2005
Running ActivePerl under Win XP; I'm trying to work out how to make
Perlscript do what Perl does (why doesn't it ... answers on a postcard).
Here's a sample script:

<Job ID="tryit">
<script language=PerlScript>

use strict;
use warnings;
use vars('$WScript'); # Avoid "strict" warnings

my $arg = $WScript->{Arguments};

my $countArgs = $arg->{Count};

open OUTPUT,">>tryit.log";

for(my $i=0; $i<$countArgs; $i++) {
$WScript->Echo($arg->Item($i));
#print OUTPUT "$arg->Item($i)\n";
}
</script>
</job>

Call it "tryit.wsf" and run it with "tryit.wsf one two three" and it
puts up messages boxes with "one", "two" and "three" in them, as desired.

Now comment out the $WScript->Echo line and remove the comment on the
line below it; I expect this to write "one", "two" and "three" to the
log file. Instead when I run "tryit.wsf one two three" I get the
following log file:

Win32::OLE=HASH(0x179cea0)->Item(0)
Win32::OLE=HASH(0x179cea0)->Item(1)
Win32::OLE=HASH(0x179cea0)->Item(2)

Can anyone help me find out why replacing this "Echo" thing with a print
statement apparently changes the data printed? I'm mystified.
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      09-18-2005
Henry Law <> wrote:

> $WScript->Echo($arg->Item($i));
> #print OUTPUT "$arg->Item($i)\n";

....
>
> Now comment out the $WScript->Echo line and remove the comment on the
> line below it; I expect this to write "one", "two" and "three" to the
> log file. Instead when I run "tryit.wsf one two three" I get the
> following log file:
>
> Win32::OLE=HASH(0x179cea0)->Item(0)
> Win32::OLE=HASH(0x179cea0)->Item(1)
> Win32::OLE=HASH(0x179cea0)->Item(2)
>
> Can anyone help me find out why replacing this "Echo" thing with a print
> statement apparently changes the data printed? I'm mystified.


It is not because you changed print to Echo, it is because in the
process you changed (...) to "..." in the process.

print OUTPUT $arg->Item($i), "\n";

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
Henry Law
Guest
Posts: n/a
 
      09-19-2005
wrote:
> Henry Law <> wrote:
>
>
>> $WScript->Echo($arg->Item($i));
>> #print OUTPUT "$arg->Item($i)\n";

>
> ....
>
>>Can anyone help me find out why replacing this "Echo" thing with a print
>>statement apparently changes the data printed? I'm mystified.

>
>
> It is not because you changed print to Echo, it is because in the
> process you changed (...) to "..." in the process.
>
> print OUTPUT $arg->Item($i), "\n";


Xho, thank you for seeing what my eyes had failed to see a hundred
times. You've led me to an even more surprising conclusion, however,
which is that Perlscript and Perl don't seem to interpolate strings the
same way. Another version of the test program shows the problem:

<Job ID="tryit">
<script language=PerlScript>

use strict;
use warnings;
use vars('$WScript'); # Avoid "strict" warnings

my $arg = $WScript->{Arguments};

open OUTPUT,">tryit.log";

for(my $i=0; $i<$arg->{Count}; $i++) {
print OUTPUT $arg->Item($i),"\n";
print OUTPUT "$arg->Item($i)\n";
}
</script>
</job>

F:>tryit.wsf one two three

F:>type tryit.log
one
Win32::OLE=HASH(0x17da744)->Item(0)
two
Win32::OLE=HASH(0x17da744)->Item(1)
three
Win32::OLE=HASH(0x17da744)->Item(2)

Should those two print statements not produce the same result in Perl?
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      09-19-2005
Henry Law <> wrote in comp.lang.perl.misc:
> wrote:
> > Henry Law <> wrote:


[...]

> times. You've led me to an even more surprising conclusion, however,
> which is that Perlscript and Perl don't seem to interpolate strings the
> same way. Another version of the test program shows the problem:
>
> <Job ID="tryit">
> <script language=PerlScript>
>
> use strict;
> use warnings;
> use vars('$WScript'); # Avoid "strict" warnings
>
> my $arg = $WScript->{Arguments};
>
> open OUTPUT,">tryit.log";
>
> for(my $i=0; $i<$arg->{Count}; $i++) {
> print OUTPUT $arg->Item($i),"\n";
> print OUTPUT "$arg->Item($i)\n";
> }
> </script>
> </job>
>
> F:>tryit.wsf one two three
>
> F:>type tryit.log
> one
> Win32::OLE=HASH(0x17da744)->Item(0)
> two
> Win32::OLE=HASH(0x17da744)->Item(1)
> three
> Win32::OLE=HASH(0x17da744)->Item(2)
>
> Should those two print statements not produce the same result in Perl?


No, neither on Perl, nor in perlscript. Perl doesn't interpolate
function calls (including method calls) in double-quote context.

perl -le 'print sin(0); print "sin(0)"'

shows the same discrepancy.

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
Henry Law
Guest
Posts: n/a
 
      09-19-2005
Anno Siegel wrote:

> No, neither on Perl, nor in perlscript. Perl doesn't interpolate
> function calls (including method calls) in double-quote context.
>
> perl -le 'print sin(0); print "sin(0)"'
>
> shows the same discrepancy.


Bother, I hadn't spotted that it's a method call and not a dereference.
All is clear now; thanks.

--

Henry Law <>< Manchester, England
 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      09-23-2005
Henry Law wrote:
> wrote:
>
>> Henry Law <> wrote:
>>
>>
>>> $WScript->Echo($arg->Item($i));
>>> #print OUTPUT "$arg->Item($i)\n";

>>
>>
>> ....
>>
>>> Can anyone help me find out why replacing this "Echo" thing with a print
>>> statement apparently changes the data printed? I'm mystified.

>>
>>
>>
>> It is not because you changed print to Echo, it is because in the
>> process you changed (...) to "..." in the process.
>>
>> print OUTPUT $arg->Item($i), "\n";

>
>
> Xho, thank you for seeing what my eyes had failed to see a hundred
> times. You've led me to an even more surprising conclusion, however,
> which is that Perlscript and Perl don't seem to interpolate strings the
> same way. Another version of the test program shows the problem:
>
> <Job ID="tryit">
> <script language=PerlScript>
>
> use strict;
> use warnings;
> use vars('$WScript'); # Avoid "strict" warnings
>
> my $arg = $WScript->{Arguments};
>
> open OUTPUT,">tryit.log";
>
> for(my $i=0; $i<$arg->{Count}; $i++) {
> print OUTPUT $arg->Item($i),"\n";
> print OUTPUT "$arg->Item($i)\n";
> }
> </script>
> </job>
>
> F:>tryit.wsf one two three
>
> F:>type tryit.log
> one
> Win32::OLE=HASH(0x17da744)->Item(0)
> two
> Win32::OLE=HASH(0x17da744)->Item(1)
> three
> Win32::OLE=HASH(0x17da744)->Item(2)
>
> Should those two print statements not produce the same result in Perl?


Nope. Simple variables are interpolated in double-quoted strings,
functions are not.

linux% cat temp
print " Inside quotes: sin(2)\n";
print "Outside quotes: ",sin(2),"\n";
linux% perl temp
Inside quotes: sin(2)
Outside quotes: 0.909297426825682

You're use of "->" is very much like a function call.
-Joe
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Upgrading from 32 bit ActivePerl-5.8.8.817 to 64 bit ActivePerl-5.8.8.819 Ted Perl Misc 7 12-16-2006 03:45 AM
Datagrid binding inconsistencies............... =?Utf-8?B?QUxQTw==?= ASP .Net 3 11-15-2005 07:22 PM
Datagrid bind inconsistencies....... =?Utf-8?B?QUxQTw==?= ASP .Net 1 11-15-2005 08:20 AM
"Checking drive for inconsistencies" =?ISO-8859-1?Q?R=F4g=EAr?= Computer Support 0 12-30-2004 03:21 PM
Framecheck does only work with static pages, not with perlscript-output Carsten Brauer Java 1 11-24-2004 02:34 PM



Advertisments
 



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