Permalink
Browse files

Importing from Andy original repo

  • Loading branch information...
1 parent d197e98 commit d5f3b1bfffc5f5f7a8ceead94d19116219c7cb4c @petdance committed Apr 30, 2007
Showing with 2,509 additions and 0 deletions.
  1. +82 −0 101.pod
  2. +17 −0 Makefile
  3. +93 −0 crank
  4. +53 −0 s/advanced-functions.pod
  5. +136 −0 s/arrays.pod
  6. +136 −0 s/command-line-switches.pod
  7. +96 −0 s/community.pod
  8. +109 −0 s/constructs.pod
  9. +32 −0 s/cpan.pod
  10. +114 −0 s/debugging.pod
  11. +13 −0 s/developer-tools.pod
  12. +67 −0 s/documentation.pod
  13. +36 −0 s/external-programs.pod
  14. +45 −0 s/files.pod
  15. +129 −0 s/flow-control.pod
  16. +114 −0 s/hashes.pod
  17. +49 −0 s/how-do-i.pod
  18. +40 −0 s/how-to-get-perl.pod
  19. +40 −0 s/modules-making-your-own.pod
  20. +13 −0 s/modules.pod
  21. +27 −0 s/numbers.pod
  22. +81 −0 s/objects.pod
  23. +109 −0 s/pod.pod
  24. +40 −0 s/publications.pod
  25. +47 −0 s/random.pod
  26. +68 −0 s/references.pod
  27. +163 −0 s/regexes.pod
  28. +124 −0 s/special-variables.pod
  29. +87 −0 s/strings.pod
  30. +67 −0 s/style.pod
  31. +135 −0 s/subroutines.pod
  32. +68 −0 s/terms.pod
  33. +17 −0 s/todo.pod
  34. +54 −0 s/traps.pod
  35. +8 −0 tt/section.tt
View
82 101.pod
@@ -0,0 +1,82 @@
+=head1 How to get Perl
+
+How to get it, download it, and install it.
+
+=head1 Terms
+
+Talk about Perl like you know your Perl.
+
+=head1 Documentation
+
+Documentation for Perl abounds. Here's where to find it.
+
+=head1 Strings
+
+=head1 Numbers
+
+=head1 Arrays
+
+=head1 Hashes
+
+=head1 Regexes
+
+=head1 Flow Control
+
+=head1 Subroutines
+
+=head1 POD
+
+POD is Perl's documentation format, and will change the way you write code.
+
+=head1 Files
+
+=head1 Debugging
+
+=head1 Modules
+
+=head1 Modules: Making your own
+
+=head1 External programs
+
+=head1 CPAN
+
+=head1 Constructs
+
+=head1 References
+
+=head1 Objects
+
+=head1 Special Variables
+
+=head1 Command-line Switches
+
+=head1 Advanced Functions
+
+=head1 Style
+
+=head1 Traps
+
+=head1 How do I...?
+
+=head1 Developer Tools
+
+=head1 Publications
+
+Crucial books and magazines for the Perl programmer.
+
+=head1 Community
+
+Perl folks around the world working together.
+
+=head1 Random
+
+A mixed bag of stuff we haven't written yet, or need to move somewhere else.
+
+=head1 TODO
+
+=head1 Thanks
+
+Thanks to the following folks for their contributions:
+Elliot Shank,
+Mike O'Regan,
+and Pete Krawczyk
View
@@ -0,0 +1,17 @@
+.PHONY: \
+ crank \
+
+default: crank
+
+crank:
+ rm -fr 101/*.html
+ mkdir 101/ || true > /dev/null 2>&1
+ perl crank 101.pod
+ rsync -azu --delete \
+ --exclude=.svn --exclude='*~' \
+ s/ 101/s/
+
+# This is only useful for Andy
+rsync:
+ rsync -azu -e ssh --delete \
+ 101/ petdance@midhae.pair.com:~/p/
View
93 crank
@@ -0,0 +1,93 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use Pod::Simple::HTMLBatch 3.02;
+use CGI qw( :standard );
+
+use File::Slurp qw( write_file );
+
+$/ = "";
+
+my @sections;
+while ( my $para = <> ) {
+ chomp $para;
+
+ $para =~ s/=head1 // or next;
+
+ push( @sections, $para );
+}
+
+my $batch= Pod::Simple::HTMLBatch->new;
+$batch->batch_convert( ['s/'] , '101/' );
+
+my @toplinks;
+for my $section ( @sections ) {
+ my $section_file = make_filename( $section );
+ if ( -s "s/$section.pod" ) {
+ push( @toplinks, qq{<a href="$section_file.html">$section</a><br>\n} );
+ }
+}
+
+my $header = <<'EOF';
+<html>
+ <head>
+ <title>101 Things Every Perl Programmer Should Know</title>
+ </head>
+ <body bgcolor="white">
+ <h1>101 Things Every Perl Programmer Should Know</h1>
+EOF
+
+my $footer = <<'EOF';
+ </body>
+</html>
+EOF
+
+write_file( '101/index.html', $header, @toplinks, feedback( 'index.html' ), $footer );
+
+sub feedback {
+ my $source_page = shift;
+
+ my $form = join( '',
+ start_form( -method => 'POST', -action => '/cgi-sys/formmail.pl' ),
+ hidden( 'subject' => "Feedback: $source_page" ),
+ hidden( 'recipient' => 'andy@petdance.com' ),
+ hidden( 'return_link_url' => 'http://perl101.org/' ),
+ hidden( 'return_link_title' => 'Return to Perl 101' ),
+ table(
+ Tr(
+ th( {align=>'right'}, 'Your name' ),
+ td( textfield( 'realname' ) ),
+ ),
+ Tr(
+ th( {align=>'right'}, 'Your email' ),
+ td( textfield( 'email' ) ),
+ ),
+ Tr( {valign=>'top'},
+ th( {align=>'right'}, 'Your comment' ),
+ td(
+ textarea( 'text', '', 10, 70 ), br(),
+ submit( -value => 'Send' ),
+ ),
+ ),
+ ), # table
+ end_form(),
+ );
+ return <<"EOF";
+ <hr>
+ <h3>We want your feedback</h3>
+ If we can improve perl101.org in any way, please let us know with this form.
+ <p>
+ $form
+EOF
+}
+
+sub make_filename {
+ my $name = lc shift;
+
+ $name =~ s/[^-a-z]+/-/g;
+ $name =~ s/^-//;
+ $name =~ s/-$//;
+
+ return $name;
+}
View
@@ -0,0 +1,53 @@
+=head1 "Advanced" functions
+
+=head2 context and wantarray
+
+Perl has three contexts: void, scalar and list.
+
+ func(); # void
+ my $ret = func(); # scalar
+ my ($ret) = func(); # list
+ my @ret = func(); # list
+
+If you're in a subroutine or L<eval|perlfunc/eval> block, you can use
+L<wantarray|perlfunc/wantarray> to determine which is
+wanted.
+
+An example of where context affects return values is
+in dealing with regular expressions:
+
+ my $str = 'Perl 101 Perl Context Demo';
+ my @ret = $str =~ /Perl/g; # @ret = ('Perl','Perl');
+ my $ret = $str =~ /Perl/g; # $ret is true
+
+=head2 .. and ...
+
+These are called the L<range operators|perlfunc/Range Operators>, and
+they can help with code that deals with ranges of integers or characters.
+
+In the previous example, C<@array> was filled by hand. But these are
+equivalent:
+
+ my @array = ( 0, 1, 2, 3, 4, 5 );
+ my @array = 0..5;
+
+Oddly enough, it works with characters, too. If you want to get a
+list of letters from C<a> to C<z>, you can do:
+
+ my @array = 'a'..'z';
+
+When used in this way, C<..> and C<...> are equivalent
+
+The range operators only increment. This will produce a zero-size
+list:
+
+ my @array = 10..1; # @array is empty
+
+If you want the reverse, ask for it.
+
+ my @array = reverse 1..10; # @array descends from 10 to 1
+
+You can also use the range operator in a scalar context, but that
+is outside the scope of this presentation. Check the man page for
+more details.
+
View
@@ -0,0 +1,136 @@
+=head1 Arrays & Lists
+
+=head2 Arrays of words are easily created
+
+The C<qw> operator makes creating arrays easy. It means "quote on
+whitespace into a list":
+
+ my @stooges = qw( Larry Curly Moe Iggy );
+
+ my @stooges = qw(
+ Larry
+ Curly
+ Moe
+ Iggy
+ );
+
+The elements do not interpolate, so:
+
+ my @array = qw( $100,000 );
+
+The one element is '$100,000'.
+
+=head2 The length of a list is its scalar value
+
+ my $stooge_count = scalar @stooges;
+
+ my $stooge_count = @stooges;
+
+Some people like the explicit C<scalar>. Some don't.
+
+=head2 Arrays have no boundaries
+
+Arrays don't have any finite size, and don't have to be predeclared.
+Arrays change in size as necessary.
+
+Arrays are also not sparse. This code makes a 10,000-element array.
+
+ my @array = ();
+ $array[10000] = 'x';
+
+C<@array> is now 10,001 elements long (0-10,000), of which only one
+is populated. The other 10,000 are C<undef>.
+
+=head2 Arrays flatten out and do not nest
+
+Unlike PHP, arrays flatten into one big list when combined:
+
+ my @sandwich = ( 'PB', 'J' );
+ my @other_sandwich = ( 'B', 'L', 'T' );
+ my @ingredients = ( @other_sandwich, @sandwich );
+ # ( 'B', 'L', 'T', 'PB', 'J' )
+
+This means you can't have an array "contain" another array, or a
+hash. To do that, you need references.
+
+=head2 Lists can have extra commas
+
+One of the greatest features of Perl is the ability to have an extra
+comma at the end of a list.
+
+ my @array = (
+ 'This thing',
+ 'That thing',
+ );
+
+Then when you add another thing
+
+ my @array = (
+ 'This thing',
+ 'That thing',
+ 'The other thing',
+ );
+
+=head2 Use arrays like queues and stacks
+
+C<shift> removes from the beginning of the array:
+
+ my $next_customer = shift @customers;
+
+C<unshift> adds to the beginning of an array:
+
+ unshift @customers, $line_jumper;
+
+C<push> adds to the end of an array:
+
+ push @customers, $dio; # The last in line
+
+C<pop> removes from the end of an array:
+
+ my $went_home = pop @customers;
+
+=head2 XXX Explain array slices
+
+=head2 Process arrays easily with C<map>
+
+C<map> is essentially a C<foreach> loop that returns a list.
+
+You can use it to convert an array into a hash:
+
+ my @array = ( 1, 2, 3, 4, 5 );
+ my %hash = map { $_ => $_ * 9 } @array;
+ # %hash = ( 1 => 9, 2 => 18, 3 => 27, 4 => 36, 5 => 45 )
+
+or to transform a list:
+
+ my @array = ( 'ReD', 'bLue', 'GrEEN' );
+ my @fixed_array = map(ucfirst, map(lc, @array));
+ # @fixed_array = ( 'Red', 'Blue', 'Green' )
+
+Watch out, though: If you modify C<$_>, you will modify the
+source data. This means the above might be changed to:
+
+ my @array = ( 'ReD', 'bLue', 'GrEEN' );
+ map { $_ = ucfirst lc $_ } @array;
+ # @array = ( 'Red', 'Blue', 'Green' )
+
+if you don't care about C<@array>.
+
+=head2 Select items out of an array with C<grep>
+
+C<grep> is essentially a foreach loop that returns a list, but
+unlike C<grep>, will only return elements that cause the condition
+to return true.
+
+ my @array = ( 0, 1, 2, 3, 4, 5 );
+ my @new_array = grep { $_ * 9 } @array;
+ # @new_array = ( 1, 2, 3, 4, 5 );
+
+It will modify the source data the same way as C<map>, however:
+
+ my @array = ( 0, 1, 2, 3, 4, 5 );
+ my @new_array = grep { $_ *= 9 } @array;
+ # @array = ( 0, 9, 18, 27, 36, 45 );
+ # @new_array = ( 9, 18, 27, 36, 45 );
+
+XXX Put an example about regexes
Oops, something went wrong.

0 comments on commit d5f3b1b

Please sign in to comment.