Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

trivial importing example

  • Loading branch information...
commit 596555432942226c9ec0b939272a776898723c43 1 parent 78f3e2a
@moritz moritz authored
Showing with 14 additions and 2 deletions.
  1. +14 −2 src/subs-n-sigs.pod
View
16 src/subs-n-sigs.pod
@@ -93,11 +93,23 @@ C<our> also makes subroutines visible from the outside of a package or module:
=end programlisting
-# TODO: elaborate
-
You may also export a subroutine to make it available to another
scope.
+ # in file Math/Trivial.pm
+ # TODO: find a better example
+ # TODO: explain modules, search paths
+ module Math::Trivial {
+ sub double($x) is export {
+ return 2 * $x;
+ }
+ }
+
+then in a different program or module you can write
+
+ use Math::Trivial; # imports sub double
+ say double(21); # 21 is only half the truth
+
X<anonymous subroutines>
X<subroutines, anonymous>
X<subroutines, first-class>
Please sign in to comment.
Something went wrong with that request. Please try again.