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 9cc7274826374fc13238c2b5752d68a43a49999b 1 parent cd8382c
ynonp authored November 14, 2011

Showing 1 changed file with 66 additions and 0 deletions. Show diff stats Hide diff stats

  1. 66  sub/intro.pl
66  sub/intro.pl
... ...
@@ -0,0 +1,66 @@
  1
+#!/usr/bin/perl 
  2
+#===============================================================================
  3
+#
  4
+#         FILE: intro.pl
  5
+#
  6
+#        USAGE: ./intro.pl  
  7
+#
  8
+#  DESCRIPTION: Introduction to subroutines
  9
+#
  10
+#       AUTHOR: Ynon Perek (), ynonperek@gmail.com
  11
+#      COMPANY: 
  12
+#      VERSION: 1.0
  13
+#      CREATED: 11/14/2011 15:12:22
  14
+#     REVISION: ---
  15
+#===============================================================================
  16
+
  17
+use strict;
  18
+use warnings;
  19
+use Carp;
  20
+
  21
+print_times();
  22
+user_details(name => 'Ynon', username=> 'test', password => 'secret');
  23
+
  24
+print_p_times(string => 'hello', count => 5);
  25
+
  26
+sub user_details {
  27
+    my %params = @_;
  28
+
  29
+    print "username = $params{username}\n";
  30
+    my $password = $params{password} || 'asdjslak2';
  31
+
  32
+    croak 'Missing username'
  33
+        if ! defined($params{username});
  34
+}
  35
+
  36
+
  37
+
  38
+sub print_times {
  39
+    my ($text, $times) = @_;
  40
+
  41
+    croak "Invalid input. Missing text"
  42
+        if ! defined($text);
  43
+
  44
+
  45
+# 5.10 and on
  46
+    $times = $times // 5;
  47
+    $times = 5 if ! defined($times);
  48
+
  49
+    print $text x $times;
  50
+}
  51
+
  52
+sub how_long {
  53
+    my ($text) = @_;
  54
+
  55
+    my $length = length($text);
  56
+    return $length;
  57
+}
  58
+
  59
+sub how_long_all {
  60
+    foreach my $word (@_) {
  61
+        how_long($word);
  62
+    }
  63
+}
  64
+
  65
+
  66
+

0 notes on commit 9cc7274

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