Win32::OLE msxml collection problem

M

Marcus

This is probably a stupid questions since I'm a beginner in Win32::OLE and
Perl...
In the code below I can get the length from $members, but the next line
outputs:
"member array name: Win32::OLE=HASH(0x1825090)->Item(0)->{text}"

code:
$members = $object->getElementsByTagName("BriefDescription");
print "$members->{length}\n";
print "member array name: $members->Item(0)->{text}\n";

I don't think there's anything wrong with $members itself, since the below
will print the value I'm looking for:
foreach my $tmp (in ($members)) {
print "member name: $tmp->{text}\n";
}


Thanks!!
Marcus
 
J

Jay Tilton

: This is probably a stupid questions since I'm a beginner in Win32::OLE and
: Perl...
: In the code below I can get the length from $members, but the next line
: outputs:
: "member array name: Win32::OLE=HASH(0x1825090)->Item(0)->{text}"
:
: code:
: $members = $object->getElementsByTagName("BriefDescription");
: print "$members->{length}\n";
: print "member array name: $members->Item(0)->{text}\n";
^^^^^^^^^
Subroutine and method calls are not interpolated into double-quoted
strings.
 
B

Ben Morrow

Quoth Simon Taylor said:
Quite right, unless of course one dereferences the method call
and then creates a scalar reference to that with the ${ } construct,

You've got \ and ${} the wrong way round... :)
in which case a method call can be interpolated in double-quoted string
context, as in:

#!/usr/bin/perl
use strict;
use warnings;
use CGI;

my $q = new CGI;
print "Not the output of the header method: $q->header()\n";
print "The output of the header method: ${ \$q->header() }\n";

However, this still calls $q->header in list context, so it would be
better to use "@{[ $q->header ]}" to make that clear (if you must use
those constructs at all).

Ben
 
S

Simon Taylor

Jay said:
: This is probably a stupid questions since I'm a beginner in Win32::OLE and
: In the code below I can get the length from $members, but the next line
: outputs:
: "member array name: Win32::OLE=HASH(0x1825090)->Item(0)->{text}"
:
: code:
: $members = $object->getElementsByTagName("BriefDescription");
: print "$members->{length}\n";
: print "member array name: $members->Item(0)->{text}\n";
^^^^^^^^^
Subroutine and method calls are not interpolated into double-quoted
strings.

Quite right, unless of course one dereferences the method call
and then creates a scalar reference to that with the ${ } construct,
in which case a method call can be interpolated in double-quoted string
context, as in:

#!/usr/bin/perl
use strict;
use warnings;
use CGI;

my $q = new CGI;
print "Not the output of the header method: $q->header()\n";
print "The output of the header method: ${ \$q->header() }\n";

Simon Taylor
 
B

Ben Morrow

Quoth Simon Taylor said:
No, it's quite correct, run it and see...

I wasn't talking about your code, but your prose. You said 'deref the
method call and then create a scalar ref with ${}'; what you meant was
'create a scalar ref to (the result of) the method call (with \), and
then deref that with ${}'.

:)

Ben
 
S

Simon Taylor

Ben said:
You've got \ and ${} the wrong way round... :)

No, it's quite correct, run it and see...
in which case a method call can be interpolated in double-quoted string
context, as in:

#!/usr/bin/perl
use strict;
use warnings;
use CGI;

my $q = new CGI;
print "Not the output of the header method: $q->header()\n";
print "The output of the header method: ${ \$q->header() }\n";


However, this still calls $q->header in list context, so it would be
better to use "@{[ $q->header ]}" to make that clear (if you must use
those constructs at all).

I agree, these sort of constructs are a little on the exotic side, and
don't aid readability ;-)

All the best,
 

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

No members online now.

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,434
Latest member
TobiasLoan

Latest Threads

Top