Permalink
Browse files

sub

  • Loading branch information...
1 parent 974176f commit 8246873dfaa76c41e99d953544d23a07c270418f @ynonp committed Sep 27, 2011
View
51 re/sol1.pl
@@ -0,0 +1,51 @@
+use strict;
+use warnings;
+
+my $TWO_DIGITS = qr {
+
+ \d
+
+# some text, dunno / dont care
+ .*
+
+ \d
+
+}xms;
+
+my $ONLY_FOUR_DIGITS = qr {
+ ^ \D* \d{4} \D* $
+}xms;
+
+my $CAPITAL_ROW_5 = qr {
+ [A-Z]{5}
+}xms;
+
+my $CAPITAL_SEPARATED = qr {
+ ([A-Z][^A-Z]+){4}
+
+ [A-Z]
+}xms;
+
+my $CAPTIAL_MAYBE_SEPARATED = qr {
+ ([A-Z].*){5}
+}xms;
+
+my $STARTS_W_ENDS_DIGIT = qr {
+ ^ w
+
+ .*
+
+ \d $
+}xms;
+
+
+while (<>) {
+ print "TWO DIGITS\n" if /$TWO_DIGITS/;
+ print "ONLY_FOUR_DIGITS\n" if /$ONLY_FOUR_DIGITS/;
+ print "AT LEAST 5 CAPITALS IN A ROW\n" if /$CAPITAL_ROW_5/;
+}
+
+
+
+
+
View
BIN sub/.break.pl.swp
Binary file not shown.
View
BIN sub/.context.pl.swp
Binary file not shown.
View
BIN sub/.params.pl.swp
Binary file not shown.
View
BIN sub/.sub.pl.swp
Binary file not shown.
View
71 sub/break.pl
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+#===============================================================================
+#
+# FILE: break.pl
+#
+# USAGE: ./break.pl
+#
+# DESCRIPTION:
+#
+# OPTIONS: ---
+# REQUIREMENTS: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: Ynon Perek (), ynonperek@gmail.com
+# COMPANY:
+# VERSION: 1.0
+# CREATED: 09/27/2011 14:57:20
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+use Carp;
+
+
+sub do_something {
+ my ($num, $text, $title, $ok, $no, $yes, $blue, $color, $eye) = @_;
+}
+
+sub do_something_better {
+ my %params = @_;
+
+ my $num = $params{num} || 10;
+ my $text = $params{text} || "foo";
+}
+
+
+do_something_better(num => 7, ok => 2, yes => 'no');
+
+
+
+
+
+sub print_times {
+ my ($text, $times) = @_;
+
+ croak "Don’t know what to say"
+ if ! defined($text);
+
+ $times = 5 if ! defined($times);
+
+ print $text x $times, "\n";
+
+}
+
+
+print_times("hello", 10);
+print_times("Hello");
+print_times();
+
+
+
+print "---- END ---\n";
+
+
+
+
+
+
+
+
View
23 sub/context.pl
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+
+sub foo {
+ my ($n) = @_;
+
+ if ( $n % 2 == 0 ) {
+ return 1;
+ } else {
+ return;
+ }
+}
+
+my @ok = foo(5);
+
+if ( @ok ) {
+ print "5 is even\n";
+} else {
+ print "cool. math still works\n";
+}
+
+
+
View
36 sub/params.pl
@@ -0,0 +1,36 @@
+use strict;
+use warnings;
+
+sub sum_of_digits {
+ my ($number) = @_;
+
+ my $sum = 0;
+
+ while ($number) {
+ $sum += chop $number;
+ }
+
+ print "sum is: $sum\n";
+}
+
+sub sum {
+ my $sum = 0;
+
+ foreach my $x (@_) {
+ $sum += $x;
+ }
+}
+
+
+sum_of_digits(121);
+sum_of_digits(121, 'hello');
+sum_of_digits(122, 123, 124);
+
+my @l = (2, 2, 2, 3, 2);
+sum_of_digits(@l);
+
+
+
+
+
+
View
16 sub/sub.pl
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+
+#valid
+greet();
+
+#error
+greet;
+
+sub greet {
+ print "Hello\n";
+}
+
+
+greet;
+greet();

0 comments on commit 8246873

Please sign in to comment.