in reply to I hate the leading underscores.

Does anyone else hate the way method names with leading underscores look?
Personally I don't, but then again it's just a matter of personal preference. Just the other day I wrote some code that used a dispatch table and since the involved subs were not really trivial nor "minimal" I wrote them separately as named subs and put in the table references to them. Even if they were not methods of a class, since they were coneceptually somewhat "private" to the table, I used names with leading underscores for them. I find it quite natural...

UPDATE: In an even different situation in which I want a "private portion of a namespace" since I'm only using it as an "anonymous tool" I still use those leading underscores, e.g.:

sub is { return bless \shift, '_hidden'; } sub _hidden::in { my $s=${shift,}; $s eq $_ and return 1 for @_; 0; }

Replies are listed 'Best First'.
Re^2: I hate the leading underscores.
by Jenda (Abbot) on Feb 16, 2005 at 13:30 UTC

    You mean instead of

    my %dispatch; $dispatch{foo} = sub { ... }; $dispatch{bar} = sub { ... }; ...
    ?-)

    Jenda
    We'd like to help you learn to help yourself
    Look around you, all you see are sympathetic eyes
    Stroll around the grounds until you feel at home
       -- P. Simon in Mrs. Robinson

      I mean like this:
      my %dispatch=(FOO => \&_foo, BAR => \&_bar, # ... LAST => \&_last); # And at the end of the script: sub _foo { # ... } sub _bar { # ... } # ...
      (Yes, I may have done as suggested by you instead.)