ActivePerl perlscript output inconsistencies

Discussion in 'Perl Misc' started by Henry Law, Sep 18, 2005.

  1. Henry Law

    Henry Law Guest

    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.
    Henry Law, Sep 18, 2005
    #1
    1. Advertising

  2. Henry Law

    Guest

    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
    , Sep 18, 2005
    #2
    1. Advertising

  3. Henry Law

    Henry Law Guest

    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?
    Henry Law, Sep 19, 2005
    #3
  4. Henry Law

    Anno Siegel Guest

    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.
    Anno Siegel, Sep 19, 2005
    #4
  5. Henry Law

    Henry Law Guest

    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
    Henry Law, Sep 19, 2005
    #5
  6. Henry Law

    Joe Smith Guest

    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
    Joe Smith, Sep 23, 2005
    #6
    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. =?Utf-8?B?QUxQTw==?=

    Datagrid bind inconsistencies.......

    =?Utf-8?B?QUxQTw==?=, Nov 14, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    337
    Eliyahu Goldin
    Nov 15, 2005
  2. =?Utf-8?B?QUxQTw==?=

    Datagrid binding inconsistencies...............

    =?Utf-8?B?QUxQTw==?=, Nov 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    383
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Nov 15, 2005
  3. Carsten Brauer
    Replies:
    1
    Views:
    389
    Chris Smith
    Nov 24, 2004
  4. Anand S Bisen
    Replies:
    2
    Views:
    2,213
    Steve Holden
    Mar 4, 2005
  5. Ted
    Replies:
    7
    Views:
    541
    Sisyphus
    Dec 16, 2006
Loading...

Share This Page