in reply to Re: Scope and Context
in thread Scope and Context

I hope you won't take this the wrong way, but ...

Nah, never taken the wrong way ... *memo to self - add perrin to the list* ... :)

I understand your point with regard to readability ... I have been guilty of writing some horrendously difficult code to decipher before, purely without intent - The reason for the embedding of the subroutine within the code at this point is so that the regular expressions in the file are loaded entirely within the BEGIN {} block. Yes I can still call the subroutine from this point, but for my own mindset, I like keeping such initialisation code in the one place. Nevertheless, your point is well noted ...

The hard-coding of the constant 8 is more of an oversight, but one which I should most definitely correct - Guess that's what happens when you get too pensive regarding programming methodology and ignore the practicalities *grin*

 

Ooohhh, Rob no beer function well without!

Replies are listed 'Best First'.
Re: Re: Re: Scope and Context
by perrin (Chancellor) on Nov 14, 2001 at 07:13 UTC
    The reason for the embedding of the subroutine within the code at this point is so that the regular expressions in the file are loaded entirely within the BEGIN {} block. Yes I can still call the subroutine from this point, but for my own mindset, I like keeping such initialisation code in the one place.

    You could put the sub definition in the BEGIN block...

      If you're never going to call the sub from outside the BEGIN block then maybe something like:
      BEGIN { my $get_regexes = sub { ... return map {...} }; ... }
      Which has the advantage of keeping the subroutine private.

      Oh yes, don't forget that in recent perl you can do open my $fh, ..., which is far nicer than

      local *FH; open FH, ...