Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

sub

  • Loading branch information...
commit 8246873dfaa76c41e99d953544d23a07c270418f 1 parent 974176f
ynonp authored
51 re/sol1.pl
... ... @@ -0,0 +1,51 @@
  1 +use strict;
  2 +use warnings;
  3 +
  4 +my $TWO_DIGITS = qr {
  5 +
  6 + \d
  7 +
  8 +# some text, dunno / dont care
  9 + .*
  10 +
  11 + \d
  12 +
  13 +}xms;
  14 +
  15 +my $ONLY_FOUR_DIGITS = qr {
  16 + ^ \D* \d{4} \D* $
  17 +}xms;
  18 +
  19 +my $CAPITAL_ROW_5 = qr {
  20 + [A-Z]{5}
  21 +}xms;
  22 +
  23 +my $CAPITAL_SEPARATED = qr {
  24 + ([A-Z][^A-Z]+){4}
  25 +
  26 + [A-Z]
  27 +}xms;
  28 +
  29 +my $CAPTIAL_MAYBE_SEPARATED = qr {
  30 + ([A-Z].*){5}
  31 +}xms;
  32 +
  33 +my $STARTS_W_ENDS_DIGIT = qr {
  34 + ^ w
  35 +
  36 + .*
  37 +
  38 + \d $
  39 +}xms;
  40 +
  41 +
  42 +while (<>) {
  43 + print "TWO DIGITS\n" if /$TWO_DIGITS/;
  44 + print "ONLY_FOUR_DIGITS\n" if /$ONLY_FOUR_DIGITS/;
  45 + print "AT LEAST 5 CAPITALS IN A ROW\n" if /$CAPITAL_ROW_5/;
  46 +}
  47 +
  48 +
  49 +
  50 +
  51 +
BIN  sub/.break.pl.swp
Binary file not shown
BIN  sub/.context.pl.swp
Binary file not shown
BIN  sub/.params.pl.swp
Binary file not shown
BIN  sub/.sub.pl.swp
Binary file not shown
71 sub/break.pl
... ... @@ -0,0 +1,71 @@
  1 +#!/usr/bin/perl
  2 +#===============================================================================
  3 +#
  4 +# FILE: break.pl
  5 +#
  6 +# USAGE: ./break.pl
  7 +#
  8 +# DESCRIPTION:
  9 +#
  10 +# OPTIONS: ---
  11 +# REQUIREMENTS: ---
  12 +# BUGS: ---
  13 +# NOTES: ---
  14 +# AUTHOR: Ynon Perek (), ynonperek@gmail.com
  15 +# COMPANY:
  16 +# VERSION: 1.0
  17 +# CREATED: 09/27/2011 14:57:20
  18 +# REVISION: ---
  19 +#===============================================================================
  20 +
  21 +use strict;
  22 +use warnings;
  23 +use Carp;
  24 +
  25 +
  26 +sub do_something {
  27 + my ($num, $text, $title, $ok, $no, $yes, $blue, $color, $eye) = @_;
  28 +}
  29 +
  30 +sub do_something_better {
  31 + my %params = @_;
  32 +
  33 + my $num = $params{num} || 10;
  34 + my $text = $params{text} || "foo";
  35 +}
  36 +
  37 +
  38 +do_something_better(num => 7, ok => 2, yes => 'no');
  39 +
  40 +
  41 +
  42 +
  43 +
  44 +sub print_times {
  45 + my ($text, $times) = @_;
  46 +
  47 + croak "Don’t know what to say"
  48 + if ! defined($text);
  49 +
  50 + $times = 5 if ! defined($times);
  51 +
  52 + print $text x $times, "\n";
  53 +
  54 +}
  55 +
  56 +
  57 +print_times("hello", 10);
  58 +print_times("Hello");
  59 +print_times();
  60 +
  61 +
  62 +
  63 +print "---- END ---\n";
  64 +
  65 +
  66 +
  67 +
  68 +
  69 +
  70 +
  71 +
23 sub/context.pl
... ... @@ -0,0 +1,23 @@
  1 +use strict;
  2 +use warnings;
  3 +
  4 +sub foo {
  5 + my ($n) = @_;
  6 +
  7 + if ( $n % 2 == 0 ) {
  8 + return 1;
  9 + } else {
  10 + return;
  11 + }
  12 +}
  13 +
  14 +my @ok = foo(5);
  15 +
  16 +if ( @ok ) {
  17 + print "5 is even\n";
  18 +} else {
  19 + print "cool. math still works\n";
  20 +}
  21 +
  22 +
  23 +
36 sub/params.pl
... ... @@ -0,0 +1,36 @@
  1 +use strict;
  2 +use warnings;
  3 +
  4 +sub sum_of_digits {
  5 + my ($number) = @_;
  6 +
  7 + my $sum = 0;
  8 +
  9 + while ($number) {
  10 + $sum += chop $number;
  11 + }
  12 +
  13 + print "sum is: $sum\n";
  14 +}
  15 +
  16 +sub sum {
  17 + my $sum = 0;
  18 +
  19 + foreach my $x (@_) {
  20 + $sum += $x;
  21 + }
  22 +}
  23 +
  24 +
  25 +sum_of_digits(121);
  26 +sum_of_digits(121, 'hello');
  27 +sum_of_digits(122, 123, 124);
  28 +
  29 +my @l = (2, 2, 2, 3, 2);
  30 +sum_of_digits(@l);
  31 +
  32 +
  33 +
  34 +
  35 +
  36 +
16 sub/sub.pl
... ... @@ -0,0 +1,16 @@
  1 +use strict;
  2 +use warnings;
  3 +
  4 +#valid
  5 +greet();
  6 +
  7 +#error
  8 +greet;
  9 +
  10 +sub greet {
  11 + print "Hello\n";
  12 +}
  13 +
  14 +
  15 +greet;
  16 +greet();

0 comments on commit 8246873

Please sign in to comment.
Something went wrong with that request. Please try again.