1. Shlomi Fish
  2. perl-begin

Commits

Shlomi Fish  committed 0abb84f

Add more.

  • Participants
  • Parent commits 8fb7cd4
  • Branches default

Comments (0)

Files changed (1)

File src/topics/files-and-directories/index.html.wml

View file
  • Ignore whitespace
             ],
         }
     );
+
+    print $ex_gen->html_with_title(
+        {
+            title => "Line count",
+            id_base => "line_count",
+            examples =>
+            [
+                {
+                    id => "io_all",
+                    label => "IO-All",
+                    code => <<'EOF',
+use IO::All;
+
+sub count_lines
+{
+    my ($filename) = @_;
+
+    my $fh = io->file($filename);
+
+    my $count = 0;
+
+    while (my $l = <$fh>)
+    {
+        $count++;
+    }
+
+    return $count;
+}
+EOF
+
+                },
+                {
+                    id => "core",
+                    label => "Core Perl",
+                    code => <<'EOF',
+use autodie;
+
+sub count_lines
+{
+    my ($filename) = @_;
+
+    open my $fh, '<', $filename;
+
+    my $count = 0;
+    while (my $l = <$fh>)
+    {
+        $count++;
+    }
+
+    close($fh);
+
+    return $count;
+}
+EOF
+                },
+                {
+                    id => "cmd_line",
+                    label => "Command Line",
+                    no_syntax => 1,
+                    code => <<'EOF',
+$ perl -lnE 'END{say "$ARGV has $. lines";}' /path/to/myfile.txt
+EOF
+                },
+            ],
+        }
+    );
+
+
 :>