Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[basics] start to updated description of the new first example
  • Loading branch information
moritz committed May 12, 2011
1 parent 0281365 commit 346ed6a
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/basics.pod
Expand Up @@ -133,7 +133,7 @@ the argument provided to C<open>.

=begin programlisting

my @names = $file.get.split(' ');
my @names = $file.get.words;

=end programlisting

Expand All @@ -143,26 +143,17 @@ X<invocant>

The right-hand side calls a I<method> --a named group of behavior-- named C<get>
on the file handle stored in C<$file>. The C<get> method reads and returns
one line from the file, removing the line ending. C<split> is also a method,
called on the string returned from C<get>. C<split>'s single argument is
a string containing a space character. C<split> decomposes its
I<invocant>--the string on which it operates--into a list of strings.
one line from the file, removing the line ending. C<words> is also a method,
called on the string returned from C<get>. C<words> decomposes its
I<invocant>--the string on which it operates--into a list of words, which
here means strings without whitespace.
It turns the single string C<'Beth Ana Charlie Dave'> into the list of
strings C<'Beth', 'Ana', 'Charlie', 'Dave'>. Finally, this list gets
strings C<'Beth', 'Ana', 'Charlie', 'Dave'>.

Finally, this list gets
stored in the array C<@names>. The C<@> sigil marks the declared variable as
an C<Array>. Arrays store ordered lists.

=begin sidebar

Splitting on a single blank is not very robust, and breaks the code when
spaces are at the end of a line, or more than one blank in a row, or even an empty
line in the input file. You will learn a more robust method for data
extraction in the chapter about regexes.

TODO: proper cross-link

=end sidebar

=begin programlisting

my %matches;
Expand Down

0 comments on commit 346ed6a

Please sign in to comment.