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

Re: [MacPerl] (QXP => HTML) && OOP



"Richard Pfeiffer" <pfeiffer@well.com> writes:
[snip]
}
}my $Style1 = new Style_Sheet("Body_Text", 12, "Times");
}my $Style2 = new Style_Sheet("Head", 18, "Helvetica");
}
}
}print "Style sheet \"", $Style1->Name, "\" has a point size of ",
} $Style1->Size, " and uses ", $Style1->Font, ".\n";
}print "Style sheet \"", $Style2->Name, "\" has a point size of ",
} $Style2->Size, " and uses ", $Style2->Font, ".\n";
}
}exit(0);
}
}
}As you can see, I have to have a hard-coded reference variable name
}($Style1, $Style2, etc.) for each new style sheet object, when what I'd
}like to be able to do is refer to it indirectly by setting the value of a
}scalar to the variable name, and then using that as a reference.  I tried
}setting up a scalar to contain the name of a style sheet, and then
}referencing/dereferencing it, but I was told this wasn't allowed.
}
}Is there a way to do this in Perl?

If I understand what you want correctly, you want to name the variable to be
the same as the name of the style sheet:

my $Body_Text = new Style_Sheet("Body_Text", 12, "Times");

Then, according to the Camel, page 254 of the second edition, you can do things
like

$name = "Body_Text";
print $$name->Name."\n";

Is that what you're trying to do?  (It looks like it from your AppleScript
snippet, which seems to be doing something similar).  I assume you can do
something like this if you have a list of names

foreach $name (@names) {
	${$name} = new Style_Sheet($name,12,$font);
}

but of course you should try it and see to make sure.  Alternatively, you
could always make a hash of references to the sheets:

foreach $name (@names) {
	$Sheets{$name} = new...
}

You should try these out, of course, since I haven't tested any of them.

}
}
}Richard
}
}__________________________
}Richard Pfeiffer <pfeiffer@well.com>
}Publishing Automation/Database Consulting/Book Production
}BMUG Scripting SIG -- Next Meeting:
}Monday 4/21/97, BMUG offices @ 6:00 p.m.


---
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693, Greenbelt, MD 20771
schinder@pjstoaster.pg.md.us