in reply to Style Question: Throwaway Objects

Well. I think for things like this you need to be flexible. In this particular case, the error catching that BrowserUk and others discuss is particularly important as (fwict) Spreadsheet::ParseExcel uses OLE to talk to the Excel com server object and that this type of code is vulnerable to error outside of the scope of your own code. However your question

I'm wondering if other monks approve of this condensed form, or if it seems awkward or might have undesirable side effects I haven't considered. Thoughts?

if considered from the POV of using pure perl objects who do not return errors via the functional interface it is not at all a bad thing. It has for instance been the recommended way of using Data::Dumper for the past ages...

my $dump=Data::Dumper->new([$foo,$bar]) ->Names([qw(foo bar)]) ->Purity(0) ->Terse(1) ->Useqq(1) ->Indent(0) ->Dump();
In fact this touches on what is one of my little pet peeves about Perl. For all intents and purposes this style (which has to be deliberately enabled by the class author) is a replacment for a with statement, without the error catching opportunities of a proper with block. If a real with() was available I would personally say to avoid this style and use the with, but absent that construct I see no reason for the style not to be utilised when error catching through return value isnt a serious issue (such as when using dumper).

For the paranoid, wrapping this construct in an eval{} would provide a clean way to catch the errors.

--- demerphq
my friends call me, usually because I'm late....

Replies are listed 'Best First'.
Re^2: Style Question: Throwaway Objects
by Aristotle (Chancellor) on Dec 09, 2002 at 18:17 UTC
      Interestingly it has been pointed out to me that for() can be used as a with, but it doesnt quite do it for me...
      for ($some->{complex}[$object]{that}{we}[$need]{to}[$use]) { $_->foo; $_->bar; }
      And a proper with construct allows the compiler opportunities to optimize far beyond what any other solution allows as it explicitly states that the object will be immutable for the duration of the with. *sigh*

      :-)

      --- demerphq
      my friends call me, usually because I'm late....

        You do save all the duplicate lookup work in this case, if that's what you mean. Anyway, the Perl compiler is pretty simpleminded as far as optimization goes, so performance is hardly an argument for having a with construct at this point.

        Makeshifts last the longest.