in reply to Re: my, my, my
in thread my, my, my

Either that or given that my is so common it might be the default or pragma-chooseable.

Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality

Replies are listed 'Best First'.
Re^3: my, my, my
by Aristotle (Chancellor) on Nov 16, 2002 at 00:12 UTC

    No, that wouldn't help. There has to be a way to discriminate declaration from use if you want to be able to tell a use of a mistyped variable apart from a declaration of a new one. I don't think three characters is a high price to pay for that service - especially considering you can, if the occasion lends itself to it, declare multiple variables with a single my.

    Your code has room for clarification and shortening in other areas; I'd write it like this:

    sub getDivisionList { (my ($agency_name, $nodes_only) = @_) or return; my $obj = __PACKAGE__->new($agency_name); my @node = $obj->{ts}->get_node_list('division'); return (!@node) ? () : $nodes_only ? ($o, @n) : map {($n->value('divname'), $n->value('siebel_id'))} @n; }
    (The jury's still out on how to indent the dangling last "default" expression, btw. I'm not entirely satisfied with any of the options so far.)

    Makeshifts last the longest.

      I think I'd layout the return expression like this, but like you, I'm not convinced its necessarially the 'best way'?

      return (!@node) ? () : $nodes_only ? ($o, @n) : map { ( $n->value('divname'), $n->value('siebel_id') ) } @n;

      As for the first line of the sub...without actually trying it, I'm not sure quite what the or is checking for. Is that equivalent to

      return unless my($agency_name, $nodes_only) = @_;

      If so, is there an advantage in using the or form?


      Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
      Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
      Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
      Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

        I thought of that layout but don't like it. Much too verbose, and the nested ternaries are supposed to look like a switch construct.

        I didn't think of return unless for some reason. There's no real difference. I'm pretty sure (without deparsing to verify right now), that the unless form compiles to the or form, internally, and I like it because the return is not the expected path - but it requires an extra pair of noisy parens, so the jury's out on that one too. :)

        (You can tell I spend a fair bit of time pondering style questions..)

        Makeshifts last the longest.