Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: When -w and use strict aren't enough...

by tilly (Archbishop)
on Nov 04, 2003 at 22:19 UTC ( #304554=note: print w/replies, xml ) Need Help??

in reply to When -w and use strict aren't enough...

There is a way to do what you want, but you probably don't want to do it. Here goes:
my $handleNewYear = sub { # do something really useful }; # ... lotsa logic... if (1==$mday && 1==$month) { $handelNewYear->(); }
All that I have done is stored the subroutine in a variable. Do that with all of your subroutines and all of your typos in subroutines become typos in variable names which catches.

You may note that I also reversed the order of your == comparisons. The reason for doing that is so that if you type = instead of == some day, Perl will complain because you can't assign to a constant. This is a useful habit in many C-like languages.

Replies are listed 'Best First'.
Re: Re: When -w and use strict aren't enough...
by greenFox (Vicar) on Nov 07, 2003 at 15:17 UTC
    I read this thread earlier today and I have to admit that I skimmed over the bit about == comparisons and then just now I was reading about the back door attempt on the Linux kernel and way down there in the comments (sorry I can't see a way to link directly to it) are two comments by "legobuff" and "Mr_Z" on the exact same topic. A real world example how a simple change in coding practice can potentially make a profound difference (presuming of course some-one writes the auditing tools). ++tilly its a good meme to spread.

    Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

Re^2: When -w and use strict aren't enough...
by andyford (Curate) on Jun 15, 2006 at 21:56 UTC
    This intrigues me.
    Why do you say "Probably don't want to..."?
    "it's too much work"?
    or because
    "it's dangerous/bad/ugly"?
      Don't know, but one downside (upside?) is that your functions are no longer accessible from outside the package. That can easily be fixed by doing one of the following for exportable functions:
      *handleNewYear = my $handleNewYear = sub { # do something really useful };
      sub handleNewYear { # do something really useful } my $handleNewYear = \&handleNewYear;
      Because it is ugly. And will be sure to generate negative comments from any maintainance programmer. And cannot be mixed with OO techniques.

      Other than that, it is a veru good idea. But its goodness is simply not worth the arguments that you're bound to generate.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://304554]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2021-06-15 07:20 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (67 votes). Check out past polls.