Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC PATCH] the begincheck program #6911

Closed
p5pRT opened this issue Nov 10, 2003 · 7 comments
Closed

[DOC PATCH] the begincheck program #6911

p5pRT opened this issue Nov 10, 2003 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 10, 2003

Migrated from rt.perl.org#24460 (status was 'resolved')

Searchable as RT24460$

@p5pRT
Copy link
Author

p5pRT commented Nov 10, 2003

From rootbeer@redcat.com

This doc patch may be added to perlmod, if it succeds in its goal of
making the order of execution clearer.

--Tom Phoenix

- - - - - - - - - - - - - - - - - -

Inline Patch
--- ./perl-5.8.2-orig/pod/perlmod.pod	Tue Sep 30 10:11:48 2003
+++ ./perl-5.8.2/pod/perlmod.pod	Mon Nov 10 08:56:10 2003
@@ -257,7 +257,8 @@

 Four special subroutines act as package constructors and destructors.
 These are the C<BEGIN>, C<CHECK>, C<INIT>, and C<END> routines.  The
-C<sub> is optional for these routines.
+C<sub> is optional for these routines. Try the B<begincheck> program, at
+the end of this section, to see them in action.

 A C<BEGIN> subroutine is executed as soon as possible, that is, the moment
 it is completely defined, even before the rest of the containing file
@@ -300,6 +301,35 @@
 Both C<BEGIN> and C<CHECK> blocks are run when you use the B<-c>
 switch for a compile-only syntax check, although your main code
 is not.
+
+The B<begincheck> program makes it all clear, eventually:
+
+  #!/usr/bin/perl
+
+  # begincheck
+
+  print " 8. Ordinary code runs at runtime.\n";
+
+  END { print "14.   So this is the end of the story.\n" }
+  INIT { print " 5. INIT blocks run FIFO just before runtime.\n" }
+  CHECK { print " 4.   So this is the fourth line.\n" }
+
+  print " 9.   It runs in order, of course.\n";
+
+  BEGIN { print " 1. BEGIN blocks run FIFO during compilation.\n" }
+  END { print "13.   Read perlmod for the rest of the details.\n" }
+  CHECK { print " 3. CHECK blocks run LIFO at compilation's end.\n" }
+  INIT { print " 6.   Run this again, using Perl's -c switch.\n" }
+
+  print "10.   This is anti-obfuscated code.\n";
+
+  END { print "12. END blocks run LIFO at quitting time.\n" }
+  BEGIN { print " 2.   So this line comes out second.\n" }
+  INIT { print " 7.   You'll see the difference right away.\n" }
+
+  print "11.   It merely _looks_ like it should be confusing.\n";
+
+  __END__

 =head2 Perl Classes

@p5pRT
Copy link
Author

p5pRT commented Nov 11, 2003

From rick@bort.ca

I think this would be a great addition to perlmod. It's a nice quick
reference as well as a beautiful illustration. It would be nice if all
the numbers lined up in a nice, neat column though.

On Mon, Nov 10, 2003 at 05​:16​:55PM -0000, Tom Phoenix wrote​:

+
+ #!/usr/bin/perl
+
+ # begincheck
+
+ print " 8. Ordinary code runs at runtime.\n";
+
+ END { print "14. So this is the end of the story.\n" }
+ INIT { print " 5. INIT blocks run FIFO just before runtime.\n" }
+ CHECK { print " 4. So this is the fourth line.\n" }
+
+ print " 9. It runs in order, of course.\n";
+
+ BEGIN { print " 1. BEGIN blocks run FIFO during compilation.\n" }
+ END { print "13. Read perlmod for the rest of the details.\n" }
+ CHECK { print " 3. CHECK blocks run LIFO at compilation's end.\n" }
+ INIT { print " 6. Run this again, using Perl's -c switch.\n" }
+
+ print "10. This is anti-obfuscated code.\n";
+
+ END { print "12. END blocks run LIFO at quitting time.\n" }
+ BEGIN { print " 2. So this line comes out second.\n" }
+ INIT { print " 7. You'll see the difference right away.\n" }
+
+ print "11. It merely _looks_ like it should be confusing.\n";
+
+ __END__

=head2 Perl Classes

--
Rick Delaney
rick@​bort.ca

@p5pRT
Copy link
Author

p5pRT commented Nov 11, 2003

From rootbeer@redcat.com

On Mon, 11 Nov 2003, Rick Delaney wrote​:

It would be nice if all the numbers lined up in a nice, neat column
though.

Which ones don't? Of course, you have to run the program...

--Tom

@p5pRT
Copy link
Author

p5pRT commented Nov 11, 2003

From rick@bort.ca

On Mon, Nov 10, 2003 at 08​:15​:47PM -0800, Tom Phoenix wrote​:

On Mon, 11 Nov 2003, Rick Delaney wrote​:

It would be nice if all the numbers lined up in a nice, neat column
though.

Which ones don't? Of course, you have to run the program...

Of course I mean in the code (POD). I'm not saying this as a style
nitpick but so that it's easier to pick out the numbers when reading the
code so it's easy to see the order of execution without running the
code (well, maybe that is a style nitpick). Running the code the first
time one reads this is fine but later it could make a nice reference. I
just think it would be a quicker reference with the numbers lined up in
the POD.

--
Rick Delaney
rick@​bort.ca

@p5pRT
Copy link
Author

p5pRT commented Nov 11, 2003

From rootbeer@redcat.com

Ah, I see what you mean. You're right. I've aligned the quotes, since I
didn't want to indent the bare print statements. (The code has a logically
straight left margin, if that concept has any meaning.) Enjoy!

--Tom

- - - - - - - - - - - -

Inline Patch
--- ./perl-5.8.2-orig/pod/perlmod.pod	Tue Sep 30 10:11:48 2003
+++ ./perl-5.8.2/pod/perlmod.pod	Mon Nov 10 08:56:10 2003
@@ -257,7 +257,8 @@

 Four special subroutines act as package constructors and destructors.
 These are the C<BEGIN>, C<CHECK>, C<INIT>, and C<END> routines.  The
-C<sub> is optional for these routines.
+C<sub> is optional for these routines. See the B<begincheck> program, at
+the end of this section, to see them in action.

 A C<BEGIN> subroutine is executed as soon as possible, that is, the moment
 it is completely defined, even before the rest of the containing file
@@ -300,6 +301,35 @@
 Both C<BEGIN> and C<CHECK> blocks are run when you use the B<-c>
 switch for a compile-only syntax check, although your main code
 is not.
+
+The B<begincheck> program makes it all clear, eventually:
+
+  #!/usr/bin/perl
+
+  # begincheck
+
+  print         " 8. Ordinary code runs at runtime.\n";
+
+  END { print   "14.   So this is the end of the tale.\n" }
+  INIT { print  " 5. INIT blocks run FIFO just before runtime.\n" }
+  CHECK { print " 4.   So this is the fourth line.\n" }
+
+  print         " 9.   It runs in order, of course.\n";
+
+  BEGIN { print " 1. BEGIN blocks run FIFO during compilation.\n" }
+  END { print   "13.   Read perlmod for the rest of the story.\n" }
+  CHECK { print " 3. CHECK blocks run LIFO at compilation's end.\n" }
+  INIT { print  " 6.   Run this again, using Perl's -c switch.\n" }
+
+  print         "10.   This is anti-obfuscated code.\n";
+
+  END { print   "12. END blocks run LIFO at quitting time.\n" }
+  BEGIN { print " 2.   So this line comes out second.\n" }
+  INIT { print  " 7.   You'll see the difference right away.\n" }
+
+  print         "11.   It merely _looks_ like it should be confusing.\n";
+
+  __END__

 =head2 Perl Classes

@p5pRT
Copy link
Author

p5pRT commented Nov 12, 2003

From ams@wiw.org

At 2003-11-11 15​:50​:35 -0800, rootbeer@​redcat.com wrote​:

--- ./perl-5.8.2-orig/pod/perlmod.pod Tue Sep 30 10​:11​:48 2003
+++ ./perl-5.8.2/pod/perlmod.pod Mon Nov 10 08​:56​:10 2003
@​@​ -257,7 +257,8 @​@​

Thanks, applied. (#21706)

-- ams

@p5pRT p5pRT closed this as completed Feb 29, 2004
@p5pRT
Copy link
Author

p5pRT commented Feb 29, 2004

@iabyn - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant