[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-Modules] Glue: Fun with reference forms again



Remeber that disjoint selection from my previous example:
{record id 188149 of window
"Computers" of application "netOctopus", record id -1.062730223E+9 of
window "Computers" of application "netOctopus", record id 145567 of window
"Computers" of application "netOctopus", records from record id
1.068117901E+9 to record id 189211 of window "Computers" of application
"netOctopus", records from record id 154996 to record id 189588 of window
"Computers" of application "netOctopus"}

Chris's example of
  my @selection = $no->get( whateveryouputhere );
  my @owner_list;
  for my $item (@selection) {
      push @owner_list, $no->get( $no->obj( cell => 'Owner' => $item) );
  }

Works okay.   I know I said it worked like a charm, but it doesn't, completely.

It works fine for lists of references that are single items.  It would not
work properly for the above list of references, it would only give me the
owner name of the first record from each set like "records from record id x
to record id y".

Well, okay, it works 'properly' in the above example.  What happens is that
for a reference to more than one item, the get is returning (properly) a
list.  The push takes notice of that, and pushes every item in the list.

If, however, I try and use the Owner names to populate a hash
for my $item (@selection) {
	my $user = $netOGlue->get($netOGlue->obj(cell => 'Owner' => $item));
	$report{$user}{'status'} = 'ready';
	$report{$user}{'reason'} = undef;
	print "report initialized for $user\n" if $debug;
};

by putting the result of the get into the scalar $user, I lose the list.

If I do this instead
for my $item (@selection) {
	my @result = $netOGlue->get($netOGlue->obj(cell => 'Owner' => $item));
	foreach my $user (@result)	{
		$report{$user}{'status'} = 'ready';
		$report{$user}{'reason'} = undef;
		print "report initialized for $user\n" if $debug;
	};
};

It works just fine again.  So pay attention to list context when working
with glue, I guess.

-Jeff Lowrey



==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-modules-request@macperl.org