SlideShare uma empresa Scribd logo
1 de 83
needs that lead to the camel

                          Per l
                              1987
                            18 December




ld12 - imolug   pvb265
needs that lead to the camel LD12




                         a genda
                         . scenario
                         . canonical way
                         . faster way
                         .. perl genesis
                         .. compiler vs interpreter
                         .. basics by examples
                         .. not to do
                         . thank's Larry




ld12 - imolug   pvb265
needs that lead to the camel LD12




                         scenario




ld12 - imolug   pvb265
a genda                                                                       needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry




                               ●   our e-commerce site is slow
                               ●   we are loosing money due to slow performance
                               ●   the users experience says that the site is unusable




  ld12 - imolug     pvb265
a genda                                                                                  needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
                               ●   our e-commerce site is slow
  . thank's Larry
                               ●   we are loosing money due to slow performance
                               ●   the users experience says that the site is unusable




                                                          ●   resolve the issue
                                                          ●   do it soon




  ld12 - imolug     pvb265
a genda                                                                                  needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
                               ●   our e-commerce site is slow
  . thank's Larry
                               ●   we are loosing money due to slow performance
                               ●   the users experience says that the site is unusable




                                                          ●   resolve the issue
                                                          ●   do it soon



                                                                                             db-server




  ld12 - imolug     pvb265
a genda                                                                                   needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
                               ●   our e-commerce site is slow
  . thank's Larry
                               ●   we are loosing money due to slow performance
                               ●   the users experience says that the site is unusable




                                                          ●   resolve the issue
                                                          ●   do it soon



                                                                             app-server       db-server




  ld12 - imolug     pvb265
a genda                                                                                   needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
                               ●   our e-commerce site is slow
  . thank's Larry
                               ●   we are loosing money due to slow performance
                               ●   the users experience says that the site is unusable




                                                          ●   resolve the issue
                                                          ●   do it soon



                                                         web-server          app-server       db-server




  ld12 - imolug     pvb265
a genda                                                                                    needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
                               ●   our e-commerce site is slow
  . thank's Larry
                               ●   we are loosing money due to slow performance
                               ●   the users experience says that the site is unusable




                                                          ●   resolve the issue
                                                          ●   do it soon



                                                         web-cluster         app-cluster       db-cluster




  ld12 - imolug     pvb265
a genda                                                                                    needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
                               ●   our e-commerce site is slow
  . thank's Larry
                               ●   we are loosing money due to slow performance
                               ●   the users experience says that the site is unusable




                                                          ●   resolve the issue
                                                          ●   do it soon
                                                          ●   complexity and high reliability

                                                         web-cluster         app-cluster       db-cluster




  ld12 - imolug     pvb265
a genda                                                                                  needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
                               ●   our e-commerce site is slow
  . thank's Larry
                               ●   we are loosing money due to slow performance
                               ●   the users experience says that the site is unusable




                                                  ●   logs are our best friends



                                                        ●   logs must exists
                                                        ●   logs must be readable
                                                        ●   logs may be very large




  ld12 - imolug     pvb265
a genda                                                                                                              needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
                               ●   our e-commerce site is slow
  . thank's Larry
                               ●   we are loosing money due to slow performance
                               ●   the users experience says that the site is unusable




                                                        ●   logs are our best friends

                               MacBook-Pro-di-valerio:data valeriobalbi$ ls -l
                               total 208392
                               -rw-r--r-- 1 valeriobalbi staff 106676224 24 Set 16:57 www.imolugcommerce.com-access.log

                               MacBook-Pro-di-valerio:data valeriobalbi$ head 10 www.imolugcommerce.com-access.log
                               head: 10: No such file or directory
                               ==> www.imolugcommerce.com-access.log <==
                               109.93.188.182,-,-,[09/Apr/2012:23:59:05,+0200],0,200,8895,109.93.188.182,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB
                               109.93.188.182,-,-,[09/Apr/2012:23:59:05,+0200],0,200,5737,109.93.188.182,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB
                               109.112.65.154,-,-,[09/Apr/2012:23:59:05,+0200],0,200,19398,109.112.65.154,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TST
                               109.93.188.182,-,-,[09/Apr/2012:23:59:05,+0200],0,200,13405,109.93.188.182,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TST
                               109.121.26.105,-,-,[09/Apr/2012:23:59:04,+0200],0,200,16210,109.121.26.105,www.imolugcommerce.com,(mod_was_ap22_http.c/-2/handler),wcn
                               109.93.188.182,-,-,[09/Apr/2012:23:59:05,+0200],0,200,893,109.93.188.182,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB2
                               79.103.238.28,-,-,[09/Apr/2012:23:59:05,+0200],0,404,333,79.103.238.28,www.imolugcommerce.com,(core.c/404/handler),-,"GET,/wcsstore/TSTB2
                               109.112.65.154,-,-,[09/Apr/2012:23:59:05,+0200],0,200,4612,109.112.65.154,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB
                               109.112.65.154,-,-,[09/Apr/2012:23:59:05,+0200],0,200,1333,109.112.65.154,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB
                               109.112.65.154,-,-,[09/Apr/2012:23:59:05,+0200],0,200,1062,109.112.65.154,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB




  ld12 - imolug     pvb265
a genda                                                                                  needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
                               ●   our e-commerce site is slow
  . thank's Larry
                               ●   we are loosing money due to slow performance
                               ●   the users experience says that the site is unusable




                                                  ●   logs are our best friends


                                                  ●   response/minute
                                                  ●   return code http/minute
                                                  ●   top ten sloow response




  ld12 - imolug     pvb265
needs that lead to the camel LD12




                         canonical way




ld12 - imolug   pvb265
a genda                                   needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry




                               Bash Sed Awk


  ld12 - imolug     pvb265
a genda                                                                           needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter


                               Bash
  .. basics by examples
  .. not to do
  . thank's Larry
                                               Sed Awk

                               Brian Fox GNU Project 1989
                               command processor script
                               wildcard piping variables   Bourne-again shell

                               command($@) = $?                                                  stdOUT
                                                            stdIN   → command →
                                 command1 && command2                                            stdERR
                                 command1 || command2               command [ | command2 ... ]



                               while list; do list; done      $(command) `command`
                               until list; do list; done
                                                              $((expression))




  ld12 - imolug     pvb265
a genda                                                                         needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter


                               Bash Sed Awk
  .. basics by examples
  .. not to do
  . thank's Larry




                               stream editor Unix utility
                               parser text transformations line by line
                               1974 Lee E. McMahon
                                 sed -e 's/old/new/g' inputFileName > outputFileName
                                 cat inputFileName | sed -e 's/old/new/g'



                                                     cat inputFileName | sed   's/pattern//g'
                                 cat inputFileName | sed   '/pattern/d'

                                 's/^$/VOIDLINE/g'                    's/^[01]*a[bc]*//g'




  ld12 - imolug     pvb265
a genda                                                                                 needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter


                               Bash Sed Awk
  .. basics by examples
  .. not to do
  . thank's Larry



                               Bell Labs 1977 operations on fields
                               Alfred Aho, Peter Weinberger, Brian Kernighan all OS
                               associative arrays regular expressions line_oriented
                                 condition { action }            cat inputFileName | awk '{ print $1 $2 }'
                                                    awk '{ print $1 $2 }' inputFileName > outputFileName
                               Inline
                                  awk -F':' '{ print $1 $2 }' inputFileName
                                                                   script
                                                                      awk -f myscript.awk inputFileName

                                awk ' if ( NR > 10 ) { print $1 $2 } '      BEGIN { FS=":" }
                                                                            { print $1 }
                                                                            END { print “hello world!” }




  ld12 - imolug     pvb265
a genda                                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 #!/bin/bash
  . thank's Larry              MAXMIN=1440
                               LOGFILE=$1
                               declare -ax vect

                               echo "Inizializzazione $(date)"
                               for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done

                               echo "Analisi File $(date)"
                               IFS=","
                               while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17
                               do
                                 minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g')
                                                          awk                  sed
                                 hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g')
                                                                             sed
                                 if [ "$minute." == "." ]; then minute=0; fi
                                 if [ "$hour." == "." ]; then hour=0; fi
                                 tmp_m=$(($hour*60))
                                 minutes=$(($tmp_m+$minute))
                                 vect[$minutes]=$((${vect[$minutes]}+1))
                               done < $LOGFILE

                               echo "risultati $(date)"
                               for ( i=0 ; $i<$MAXMIN ; i++ ) ; do
                                 echo -n "$i "
                                 echo ${vect[$i]}
                               done
                               echo "fine $(date)"




  ld12 - imolug     pvb265
a genda                                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 #!/bin/bash
  . thank's Larry              MAXMIN=1440
                               LOGFILE=$1
                               declare -ax vect

                               echo "Inizializzazione $(date)"
                               for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done

                               echo "Analisi File $(date)"
                               IFS=","
                               while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17
                               do
                                 minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g')
                                                          awk                  sed
                                 hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g')
                                                                             sed
                                 if [ "$minute." == "." ]; then minute=0; fi
                                 if [ "$hour." == "." ]; then hour=0; fi
                                 tmp_m=$(($hour*60))
                                 minutes=$(($tmp_m+$minute))
                                 vect[$minutes]=$((${vect[$minutes]}+1))
                               done < $LOGFILE

                               echo "risultati $(date)"
                               for ( i=0 ; $i<$MAXMIN ; i++ ) ; do
                                 echo -n "$i "
                                 echo ${vect[$i]}
                               done
                               echo "fine $(date)"




  ld12 - imolug     pvb265
a genda                                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 #!/bin/bash
  . thank's Larry              MAXMIN=1440
                               LOGFILE=$1
                               declare -ax vect

                               echo "Inizializzazione $(date)"
                               for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done

                               echo "Analisi File $(date)"
                               IFS=","
                               while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17
                               do
                                 minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g')
                                                          awk                  sed
                                 hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g')
                                                                             sed
                                 if [ "$minute." == "." ]; then minute=0; fi
                                 if [ "$hour." == "." ]; then hour=0; fi
                                 tmp_m=$(($hour*60))
                                 minutes=$(($tmp_m+$minute))
                                 vect[$minutes]=$((${vect[$minutes]}+1))
                               done < $LOGFILE

                               echo "risultati $(date)"
                               for ( i=0 ; $i<$MAXMIN ; i++ ) ; do
                                 echo -n "$i "
                                 echo ${vect[$i]}
                               done
                               echo "fine $(date)"




  ld12 - imolug     pvb265
a genda                                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 #!/bin/bash
  . thank's Larry              MAXMIN=1440
                               LOGFILE=$1
                               declare -ax vect

                               echo "Inizializzazione $(date)"
                               for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done

                               echo "Analisi File $(date)"
                               IFS=","
                               while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17
                               do
                                 minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g')
                                                          awk                  sed
                                 hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g')
                                                                             sed
                                 if [ "$minute." == "." ]; then minute=0; fi
                                 if [ "$hour." == "." ]; then hour=0; fi
                                 tmp_m=$(($hour*60))
                                 minutes=$(($tmp_m+$minute))
                                 vect[$minutes]=$((${vect[$minutes]}+1))
                               done < $LOGFILE

                               echo "risultati $(date)"
                               for ( i=0 ; $i<$MAXMIN ; i++ ) ; do
                                 echo -n "$i "
                                 echo ${vect[$i]}
                               done
                               echo "fine $(date)"




  ld12 - imolug     pvb265
a genda                                                           needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 8000
  . thank's Larry              7000
                               6000
                               5000
                                           f(x) = 4.63x - 0.06
                               4000
                                                                     native
                               3000
                                                                     Linear (native)
                               2000
                               1000
                                 0
                                        123,000
                                        183,000


                                        363,000
                                        423,000
                                        483,000


                                        663,000
                                        723,000
                                        783,000


                                        963,000


                                      1,143,000
                                          3,000
                                         63,000


                                        243,000
                                        303,000



                                        543,000
                                        603,000



                                        843,000
                                        903,000

                                      1,023,000
                                      1,083,000

                                      1,203,000
                                      1,263,000
                                      1,323,000
                                      1,383,000
                                      1,443,000
                                       50 minutes for 600.000 requests


                                       still no answer you gotta fired




  ld12 - imolug     pvb265
a genda                                                                                          needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   1       #!/bin/bash
  .. basics by examples                MAXMIN=1440
  .. not to do                         LOGFILE=$1
  . thank's Larry                      declare -ax vect

                               2       echo "Inizializzazione $(date)"
                                       for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done

                               2       echo "Analisi File $(date)"
                                       IFS=","
                                       while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17
                                       do
                                   3     minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g')
                                                     echo         awk                  sed
                                   3     hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g')
                                                  echo                               sed
                                         if [ "$minute." == "." ]; then minute=0; fi
                                         if [ "$hour." == "." ]; then hour=0; fi
                                         tmp_m=$(($hour*60))
                                         minutes=$(($tmp_m+$minute))
                                         vect[$minutes]=$((${vect[$minutes]}+1))
                                       done < $LOGFILE

                               2       echo "risultati $(date)"
                                       for ( i=0 ; $i<$MAXMIN ; i++ ) ; do
                                   1     echo -n "$i "
                                   1     echo ${vect[$i]}
                                       done
                               2       echo "fine $(date)"




  ld12 - imolug     pvb265
a genda                                                                                          needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   1       #!/bin/bash
  .. basics by examples                MAXMIN=1440
  .. not to do                         LOGFILE=$1
  . thank's Larry                      declare -ax vect

                               2       echo "Inizializzazione $(date)"
                                       for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done

                               2       echo "Analisi File $(date)"
                                       IFS=","
                                       while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17
                                       do
                                         minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g')
                                                     echo         awk                  sed
                                          fork/exec → 2880+9 + 6N
                                   3
                                   3     hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g')
                                                  echo                               sed
                                         if [ "$minute." == "." ]; then minute=0; fi
                                          line read → N
                                         if [ "$hour." == "." ]; then hour=0; fi
                                         tmp_m=$(($hour*60))
                                         minutes=$(($tmp_m+$minute))
                                         vect[$minutes]=$((${vect[$minutes]}+1))
                                       done < $LOGFILE

                               2       echo "risultati $(date)" f(N)=6N+K
                                       for ( i=0 ; $i<$MAXMIN ; i++ ) ; do
                                   1     echo -n "$i "
                                   1     echo ${vect[$i]}
                                       done
                               2       echo "fine $(date)"




  ld12 - imolug     pvb265
needs that lead to the camel LD12




                         faster way




ld12 - imolug   pvb265
a genda                                               needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry




                               AngelSpot (@mod186k1) says:
                                 why don't in PERL?




  ld12 - imolug     pvb265
a genda                                                                                needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   #!/usr/bin/perl -w
  .. basics by examples
  .. not to do                 my $MAXMIN=1440;
  . thank's Larry              my $LOGFILE=shift();
                               my @vect;

                               print "Inizializzazione ".qx/'date'/;
                               for ( my $i=0 ; $i<$MAXMIN ; $i++ ) { $vect[$i]=0; }

                               print "Analisi File ".qx/'date'/;

                               open FILE, "<", $LOGFILE or die $!;
                               while (<FILE>) {
                                 my @field=split(',',$_);
                                 my ($d0, $hour, $minute, $d1)=split(':',$field[3]);
                                 my $minutes=$hour*60+$minute;
                                 $vect[$minutes]++;
                               }
                               close (FILE);



                               print "risultati ".qx/'date'/;
                               for ( my $j=0 ; $j<$MAXMIN ; $j++ ) {
                                 printf "%s %sn",$j,$vect[$j];
                               }

                               print "fine ".qx/'date'/;




  ld12 - imolug     pvb265
a genda                                                                                needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   #!/usr/bin/perl -w
  .. basics by examples
  .. not to do                 my $MAXMIN=1440;
  . thank's Larry              my $LOGFILE=shift();
                               my @vect;

                               print "Inizializzazione ".qx/'date'/;
                               for ( my $i=0 ; $i<$MAXMIN ; $i++ ) { $vect[$i]=0; }

                               print "Analisi File ".qx/'date'/;

                               open FILE, "<", $LOGFILE or die $!;
                               while (<FILE>) {
                                 my @field=split(',',$_);
                                 my ($d0, $hour, $minute, $d1)=split(':',$field[3]);
                                 my $minutes=$hour*60+$minute;
                                 $vect[$minutes]++;
                               }
                               close (FILE);



                               print "risultati ".qx/'date'/;
                               for ( my $j=0 ; $j<$MAXMIN ; $j++ ) {
                                 printf "%s %sn",$j,$vect[$j];
                               }

                               print "fine ".qx/'date'/;




  ld12 - imolug     pvb265
a genda                                                                                needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   #!/usr/bin/perl -w
  .. basics by examples
  .. not to do                 my $MAXMIN=1440;
  . thank's Larry              my $LOGFILE=shift();
                               my @vect;

                               print "Inizializzazione ".qx/'date'/;
                               for ( my $i=0 ; $i<$MAXMIN ; $i++ ) { $vect[$i]=0; }

                               print "Analisi File ".qx/'date'/;

                               open FILE, "<", $LOGFILE or die $!;
                               while (<FILE>) {
                                 my @field=split(',',$_);
                                 my ($d0, $hour, $minute, $d1)=split(':',$field[3]);
                                 my $minutes=$hour*60+$minute;
                                 $vect[$minutes]++;
                               }
                               close (FILE);



                               print "risultati ".qx/'date'/;
                               for ( my $j=0 ; $j<$MAXMIN ; $j++ ) {
                                 printf "%s %sn",$j,$vect[$j];
                               }

                               print "fine ".qx/'date'/;




  ld12 - imolug     pvb265
a genda                                                                                needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   #!/usr/bin/perl -w
  .. basics by examples
  .. not to do                 my $MAXMIN=1440;
  . thank's Larry              my $LOGFILE=shift();
                               my @vect;

                               print "Inizializzazione ".qx/'date'/;
                               for ( my $i=0 ; $i<$MAXMIN ; $i++ ) { $vect[$i]=0; }

                               print "Analisi File ".qx/'date'/;

                               open FILE, "<", $LOGFILE or die $!;
                               while (<FILE>) {
                                 my @field=split(',',$_);
                                 my ($d0, $hour, $minute, $d1)=split(':',$field[3]);
                                 my $minutes=$hour*60+$minute;
                                 $vect[$minutes]++;
                               }
                               close (FILE);



                               print "risultati ".qx/'date'/;
                               for ( my $j=0 ; $j<$MAXMIN ; $j++ ) {
                                 printf "%s %sn",$j,$vect[$j];
                               }

                               print "fine ".qx/'date'/;




  ld12 - imolug     pvb265
a genda                                                              needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry              8000
                               7000
                               6000
                               5000
                                              f(x) = 4.63x - 0.06
                               4000                                     native
                                                                        Linear (native)
                               3000
                                                                        perl
                               2000                                     Linear (perl)
                               1000            f(x) = 0.02x + 0.44
                                 0
                                         68,000
                                        132,000
                                        196,000


                                        388,000
                                        452,000
                                        516,000


                                        708,000
                                        772,000
                                        836,000


                                      1,028,000
                                      1,092,000
                                      1,156,000
                                      1,220,000
                                      1,284,000
                                      1,348,000
                                      1,412,000
                                          4,000



                                        260,000
                                        324,000



                                        580,000
                                        644,000



                                        900,000
                                        964,000
                                       only 8 seconds for 600.000 requests


                                         just in time analisys came true




  ld12 - imolug     pvb265
a genda                                                              needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry              8000
                               7000
                               6000
                               5000
                                              f(x) = 4.63x - 0.06
                               4000                                     native
                                                                        Linear (native)
                               3000
                                                                        perl
                               2000               f(x)=mx+q             Linear (perl)
                               1000            f(x) = 0.02x + 0.44
                                 0      fnative(x)=4,63x – 0,06
                                         68,000
                                        132,000
                                        196,000


                                        388,000
                                        452,000
                                        516,000


                                        708,000
                                        772,000
                                        836,000


                                      1,028,000
                                      1,092,000
                                      1,156,000
                                      1,220,000
                                      1,284,000
                                      1,348,000
                                      1,412,000
                                          4,000



                                        260,000
                                        324,000



                                        580,000
                                        644,000



                                        900,000
                                        964,000
                                        fperl(x)=0,02x – 0,44

                                          4,63/0,02=231,5
                                       only 8 seconds for 600.000 requests


                                         just in time analisys came true




  ld12 - imolug     pvb265
a genda                                                                                                      needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
                                                       Python       Ruby         Perl         C
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 Version                 1.5.2        1.4.5        5.0pl5sv3    egcs-1.1.2

  . thank's Larry
                               GC Style                RefCount     GC           RefCount     None


                               Tested-on               2000-07-19   2000-07-19   2001-04-18   2001-04-18


                               loop_test(500.000)      33.94        17.16        18.95        0.16


                               index_test(1.000.000)   17.64        26.49        23.83        1.44


                               nested_int_test(23)     43.55        84.95        27.69        0.09


                               Returntest(5.000.000)   74.31        53.02        156.24       0.42


                               Functest(5.000.000)     63.85        53.84        106.24       0.39


                               file_line_test          9.53         27.87        9.88         1.50


                               file_line_split_test    44.80        n/a          35.35        7.28


                               file_line_re_test       294.83       n/a          43.86        n/a




                                                                                    http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/




  ld12 - imolug     pvb265
a genda                                                                                                           needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
                                                       Python       Ruby         Perl         C
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 Version                 1.5.2        1.4.5        5.0pl5sv3    egcs-1.1.2

  . thank's Larry
                               GC Style                RefCount     GC           RefCount     None


                               Tested-on               2000-07-19   2000-07-19   2001-04-18   2001-04-18


                               loop_test(500.000)      33.94        17.16        18.95        0.16
                                                                                                           Perform two nested loops, the
                                                                                                           outer loop of 500.000 iterations
                               index_test(1.000.000)   17.64        26.49        23.83        1.44         and the inner of 10 iterations

                               nested_int_test(23)     43.55        84.95        27.69        0.09             Nested Loops

                               Returntest(5.000.000)   74.31        53.02        156.24       0.42


                               Functest(5.000.000)     63.85        53.84        106.24       0.39


                               file_line_test          9.53         27.87        9.88         1.50


                               file_line_split_test    44.80        n/a          35.35        7.28


                               file_line_re_test       294.83       n/a          43.86        n/a




                                                                                    http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/




  ld12 - imolug     pvb265
a genda                                                                                                          needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
                                                       Python       Ruby         Perl         C
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 Version                 1.5.2        1.4.5        5.0pl5sv3    egcs-1.1.2

  . thank's Larry
                               GC Style                RefCount     GC           RefCount     None


                               Tested-on               2000-07-19   2000-07-19   2001-04-18   2001-04-18


                               loop_test(500.000)      33.94        17.16        18.95        0.16


                               index_test(1.000.000)   17.64        26.49        23.83        1.44         Write 1.000.000 elements into
                                                                                                           hash-table and read then
                               nested_int_test(23)     43.55        84.95        27.69        0.09         back

                                                                                                                Hash Table
                               Returntest(5.000.000)   74.31        53.02        156.24       0.42


                               Functest(5.000.000)     63.85        53.84        106.24       0.39


                               file_line_test          9.53         27.87        9.88         1.50


                               file_line_split_test    44.80        n/a          35.35        7.28


                               file_line_re_test       294.83       n/a          43.86        n/a




                                                                                    http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/




  ld12 - imolug     pvb265
a genda                                                                                                           needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
                                                       Python       Ruby         Perl         C
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 Version                 1.5.2        1.4.5        5.0pl5sv3    egcs-1.1.2

  . thank's Larry
                               GC Style                RefCount     GC           RefCount     None


                               Tested-on               2000-07-19   2000-07-19   2001-04-18   2001-04-18


                               loop_test(500.000)      33.94        17.16        18.95        0.16


                               index_test(1.000.000)   17.64        26.49        23.83        1.44


                               nested_int_test(23)     43.55        84.95        27.69        0.09         Five level of nested loops each of
                                                                                                           23 iteration and at each level
                                                                                                           some simple arithmetic operation
                               Returntest(5.000.000)   74.31        53.02        156.24       0.42
                                                                                                           on a local variable

                               Functest(5.000.000)     63.85        53.84        106.24       0.39
                                                                                                               Nested Loops
                                                                                                               + Arithmetics on
                               file_line_test          9.53         27.87        9.88         1.50
                                                                                                               Local Vars
                               file_line_split_test    44.80        n/a          35.35        7.28


                               file_line_re_test       294.83       n/a          43.86        n/a




                                                                                    http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/




  ld12 - imolug     pvb265
a genda                                                                                                          needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
                                                       Python       Ruby         Perl         C
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 Version                 1.5.2        1.4.5        5.0pl5sv3    egcs-1.1.2

  . thank's Larry
                               GC Style                RefCount     GC           RefCount     None


                               Tested-on               2000-07-19   2000-07-19   2001-04-18   2001-04-18


                               loop_test(500.000)      33.94        17.16        18.95        0.16


                               index_test(1.000.000)   17.64        26.49        23.83        1.44


                               nested_int_test(23)     43.55        84.95        27.69        0.09


                               Returntest(5.000.000)   74.31        53.02        156.24       0.42         Test the cost of multiple argument
                                                                                                           return by performing 5.000.000
                               Functest(5.000.000)     63.85                     106.24                    Function call which return
                                                                    53.84                     0.39
                                                                                                           Arguments unpacked into local
                                                                                                           variables
                               file_line_test          9.53         27.87        9.88         1.50
                                                                                                             Return Arguments
                               file_line_split_test    44.80        n/a          35.35        7.28


                               file_line_re_test       294.83       n/a          43.86        n/a




                                                                                    http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/




  ld12 - imolug     pvb265
a genda                                                                                                          needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
                                                       Python       Ruby         Perl         C
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 Version                 1.5.2        1.4.5        5.0pl5sv3    egcs-1.1.2

  . thank's Larry
                               GC Style                RefCount     GC           RefCount     None


                               Tested-on               2000-07-19   2000-07-19   2001-04-18   2001-04-18


                               loop_test(500.000)      33.94        17.16        18.95        0.16


                               index_test(1.000.000)   17.64        26.49        23.83        1.44


                               nested_int_test(23)     43.55        84.95        27.69        0.09


                               Returntest(5.000.000)   74.31        53.02        156.24       0.42         Test the cost of function calls by
                                                                                                           Performing 5.000.000 function calls
                               Functest(5.000.000)     63.85                     106.24                    with one integer argument which
                                                                    53.84                     0.39
                                                                                                           returns that argument

                               file_line_test          9.53         27.87        9.88         1.50
                                                                                                              Functions Calling
                               file_line_split_test    44.80        n/a          35.35        7.28


                               file_line_re_test       294.83       n/a          43.86        n/a




                                                                                    http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/




  ld12 - imolug     pvb265
a genda                                                                                                          needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
                                                       Python       Ruby         Perl         C
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 Version                 1.5.2        1.4.5        5.0pl5sv3    egcs-1.1.2

  . thank's Larry
                               GC Style                RefCount     GC           RefCount     None


                               Tested-on               2000-07-19   2000-07-19   2001-04-18   2001-04-18


                               loop_test(500.000)      33.94        17.16        18.95        0.16


                               index_test(1.000.000)   17.64        26.49        23.83        1.44


                               nested_int_test(23)     43.55        84.95        27.69        0.09


                               Returntest(5.000.000)   74.31        53.02        156.24       0.42


                               Functest(5.000.000)     63.85        53.84        106.24       0.39


                               file_line_test          9.53         27.87        9.88         1.50
                                                                                                           Time spent opening the file and
                                                                                                           reading it line by line
                               file_line_split_test    44.80        n/a          35.35        7.28
                                                                                                                Reading File
                               file_line_re_test       294.83       n/a          43.86        n/a




                                                                                    http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/




  ld12 - imolug     pvb265
a genda                                                                                                           needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
                                                       Python       Ruby         Perl         C
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 Version                 1.5.2        1.4.5        5.0pl5sv3    egcs-1.1.2

  . thank's Larry
                               GC Style                RefCount     GC           RefCount     None


                               Tested-on               2000-07-19   2000-07-19   2001-04-18   2001-04-18


                               loop_test(500.000)      33.94        17.16        18.95        0.16


                               index_test(1.000.000)   17.64        26.49        23.83        1.44


                               nested_int_test(23)     43.55        84.95        27.69        0.09


                               Returntest(5.000.000)   74.31        53.02        156.24       0.42


                               Functest(5.000.000)     63.85        53.84        106.24       0.39
                                                                                                             Reading Line by Line
                               file_line_test          9.53         27.87        9.88         1.50           and Splitting

                               file_line_split_test    44.80        n/a          35.35        7.28
                                                                                                           Time spent opening the file and
                                                                                                           reading it line by line splitting each
                               file_line_re_test       294.83       n/a          43.86        n/a          line in token vector



                                                                                    http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/




  ld12 - imolug     pvb265
a genda                                                                                                           needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
                                                       Python       Ruby         Perl         C
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 Version                 1.5.2        1.4.5        5.0pl5sv3    egcs-1.1.2

  . thank's Larry
                               GC Style                RefCount     GC           RefCount     None


                               Tested-on               2000-07-19   2000-07-19   2001-04-18   2001-04-18


                               loop_test(500.000)      33.94        17.16        18.95        0.16


                               index_test(1.000.000)   17.64        26.49        23.83        1.44


                               nested_int_test(23)     43.55        84.95        27.69        0.09


                               Returntest(5.000.000)   74.31        53.02        156.24       0.42

                                                                                                            Reading Line by Line
                               Functest(5.000.000)     63.85        53.84        106.24       0.39
                                                                                                              and Splitting +
                                                                                                           Conditional Operations
                               file_line_test          9.53         27.87        9.88         1.50

                                                                                                           Time spent opening the file and
                               file_line_split_test    44.80        n/a          35.35        7.28         reading it line by line, splitting each
                                                                                                           line in token vector with simple
                                                                                                           conditional analisys and
                               file_line_re_test       294.83       n/a          43.86        n/a
                                                                                                           assegnation to local variables


                                                                                    http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/




  ld12 - imolug     pvb265
a genda                                                                                                        needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
                                                       Python       Ruby         Perl         C
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do                 Version                 1.5.2        1.4.5        5.0pl5sv3    egcs-1.1.2

  . thank's Larry
                               GC Style                RefCount     GC           RefCount     None


                               Tested-on               2000-07-19   2000-07-19   2001-04-18   2001-04-18


                               loop_test(500.000)      33.94        17.16        18.95        0.16


                               index_test(1.000.000)   17.64        26.49        23.83        1.44


                               nested_int_test(23)     43.55        84.95        27.69        0.09

                                                                                                           reding file,
                               Returntest(5.000.000)   74.31        53.02        156.24       0.42
                                                                                                           manipulating strings,
                               Functest(5.000.000)     63.85        53.84        106.24       0.39         loops and operations
                               file_line_test          9.53         27.87        9.88         1.50


                               file_line_split_test    44.80        n/a          35.35        7.28


                               file_line_re_test       294.83       n/a          43.86        n/a




                                                                                    http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/




  ld12 - imolug     pvb265
needs that lead to the camel LD12




                         faster way
                           Perl genesis




ld12 - imolug   pvb265
a genda                                                                                   needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry




                               Larry Wall 1954 bachelor's degree in Natural and Artificial Languages
                                           Practical Extraction and Report Language
                               Pathologically Eclectic Rubbish Lister   Laziness, Impatience and Hubris
                                                                   1987
                                                                              http://www.linuxjournal.com/article/3394




  ld12 - imolug     pvb265
a genda                                                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Naming it Perl Practical Extraction and Report Language
  .. basics by examples
  .. not to do                 perl / Perl      programm/Language
  . thank's Larry              imperfect ”Perl was never designed to be perfect”
                               adaptive    “Over-specialization is only as good as your ecological niche”




                               Perl 1.0 18 december 1987 newsgroup: comp.sources.misc
                               Perl 2.0 1988 feature: better regular expression engine
                               Perl 3.0 1989 feature: binary data streams
                               Perl 4.0 1991 well documented, published Programming Perl (aka Camel Book)
                               Perl 5.000 17 october 1994 extending the language without modifying the core interpreter
                               Perl 5.001 13 march 1995
                               CPAN 26 october 1995 comprehensive perl archive network
                               Perl 5.002 29 february 1996 feature: subroutine
                               Perl 5.003 25 june 1996 security release
                               Perl 5.004 15 may 1997
                               Perl 5.005 22 july 1998
                                                                                           http://www.linuxjournal.com/article/3394




  ld12 - imolug     pvb265
a genda                                                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Naming it Perl Practical Extraction and Report Language
  .. basics by examples
  .. not to do                 perl / Perl      programm/Language
  . thank's Larry              imperfect ”Perl was never designed to be perfect”
                               adaptive    “Over-specialization is only as good as your ecological niche”




                               Perl 5.6 22 march 2000 feature: 64bit support, unicode, large file support
                               Perl 6.0 19 july 2000 first announced by Larry in “State of the Onion 2000” talk
                               Perl 5.10 18 december 2007 20th anniversary
                               Perl 5.12 now




                                                                                           http://www.linuxjournal.com/article/3394




  ld12 - imolug     pvb265
a genda                                                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Naming it Perl Practical Extraction and Report Language
  .. basics by examples
  .. not to do                 perl / Perl      programm/Language
  . thank's Larry              imperfect ”Perl was never designed to be perfect”
                               adaptive    “Over-specialization is only as good as your ecological niche”
                               Perl history realease from 1.0 to 5.12 (6.0)



                                             main characteristics
                                   text-processing language                                                 modular
                                           glues for interstices
                               UNICODE to be worldwide useful                                                      flexible




                                                                                           http://www.linuxjournal.com/article/3394




  ld12 - imolug     pvb265
a genda                                                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Naming it Perl Practical Extraction and Report Language
  .. basics by examples
  .. not to do                 perl / Perl      programm/Language
  . thank's Larry              imperfect ”Perl was never designed to be perfect”
                               adaptive    “Over-specialization is only as good as your ecological niche”
                               Perl history realease from 1.0 to 5.12 (6.0)



                                             main characteristics
                                   text-processing language       modular
                                             gluesthe interstices
                                                   for only
                                     POST-MODERN flexible
                               UNICODE to be worldwide useful
                                                                    language


                                                                                           http://www.linuxjournal.com/article/3394




  ld12 - imolug     pvb265
needs that lead to the camel LD12




                           faster way
                         compiler vs interpreter




ld12 - imolug   pvb265
a genda                                                            needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry




                                   A compiler is a program that reads code
                               written in one source language and translate it
                                into the same written in a second language




  ld12 - imolug   pvb265
a genda                                                          needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
                               position := initial + rate * 60
  .. not to do
  . thank's Larry




  ld12 - imolug   pvb265
a genda                                                              needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
                                          :=
  .. not to do
  . thank's Larry              position        initial + rate * 60




  ld12 - imolug   pvb265
a genda                                                                  needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
                                          :=
  .. not to do
  . thank's Larry              position                  +
                                               initial       rate * 60




  ld12 - imolug   pvb265
a genda                                                                  needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
                                          :=
  .. not to do
  . thank's Larry              position                  +
                                               initial              *
                                                             rate       60




  ld12 - imolug   pvb265
a genda                                                                  needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
                                          :=
  .. not to do
  . thank's Larry              position                  +
                                               initial              *
                                                             rate       60




  ld12 - imolug   pvb265
a genda                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
                                            :=
  .. not to do
  . thank's Larry              position                    +
                                                 initial              *
                                                               rate       60


                               syntax check                               syntax check
                               optimization                               optimization


                               executable                                 execute




  ld12 - imolug   pvb265
a genda                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
                                            :=
  .. not to do
  . thank's Larry              position                    +
                                                 initial              *
                                                               rate       60
                               compiler                                   interpreter
                               syntax check                               syntax check
                               optimization                               optimization


                               executable                                 execute




  ld12 - imolug   pvb265
a genda                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
                                            :=
  .. not to do
  . thank's Larry              position                    +
                                                 initial              *
                                                               rate       60
                               compiler             like Java             interpreter
                               syntax check         syntax check          syntax check
                               optimization         optimization          optimization
                                                    bytecode

                               executable           VM per SO             execute


                                                    execute



  ld12 - imolug   pvb265
a genda                                                            needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry




                               compiler      C C++ Pascal PL/1
                               like Java     Java
                               interpreter   Bash Basic Lisp Javascript




  ld12 - imolug   pvb265
a genda                                                            needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry




                               compiler      C C++ Pascal PL/1
                               like Java     Java
                               interpreter          Perl
                                             Bash Basic Lisp Javascript




  ld12 - imolug   pvb265
needs that lead to the camel LD12




                          faster way
                         basics by examples




ld12 - imolug   pvb265
a genda                                                             needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry




                                   We can't condense the specifications
                               of a language in a few slides, but You can fall
                                   in love seeing some simple examples.




  ld12 - imolug     pvb265
a genda                                                          needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Data Type Data Structure
  .. basics by examples
  .. not to do                 Predefined Variable Running
  . thank's Larry
                               Loop and Condition
                               String Manipulation IO function
                               System Interaction




  ld12 - imolug     pvb265
a genda                                                            needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Data Type Data Structure
  .. basics by examples
  .. not to do                 Predefined Variable Running
  . thank's Larry
                               Loop and Condition
                               String Manipulation IO function
                               System Interaction


                                               dynamically typed
                                                 undef value


                                             my $MAXMIN=1440;
                                             my $j=0;
                                             my $name=”Valerio”;




  ld12 - imolug     pvb265
a genda                                                                  needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Data Type Data Structure
  .. basics by examples
  .. not to do                 Predefined Variable Running
  . thank's Larry
                               Loop and Condition
                               String Manipulation IO function
                               System Interaction



                                                       @array %hash


                               my @vect;                       my %vect;
                               my $vect[$i]=0;                 my %vect{'sun'}='sunday';
                                                               my %vect{'mon'}='monday';

                               foreach $element (@vect) {      foreach $key (keys %vect) {
                                 print “$elementn”;             print “$key = $vect{$key}n”;
                               }                               }
                               print scalar(@vect);




  ld12 - imolug     pvb265
a genda                                                                     needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Data Type Data Structure
  .. basics by examples
  .. not to do                 Predefined Variable Running
  . thank's Larry
                               Loop and Condition
                               String Manipulation IO function
                               System Interaction


                               $_       default input
                               $!       current error
                               $$       process number
                               $ARGV    number of parameter
                               @ARGV    parameter
                               @_       subroutine parameter


                                          open FILE, "<", $LOGFILE or die $!;
                                          my @field=split(',',$_);




  ld12 - imolug     pvb265
a genda                                                                       needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Data Type Data Structure
  .. basics by examples
  .. not to do                 Predefined Variable Running
  . thank's Larry
                               Loop and Condition
                               String Manipulation IO function
                               System Interaction

                                                        perl in line
                                                execution of an interpreter
                                                  script self interpreting

                               >perl -e “print '$$'; print 'Hi pvb265!'; ”;

                                                         >cat test2.pl
                                                         print '$$';           >cat test3.pl
                                                         print 'Hi pvb265';    #!/usr/bin/perl
                                                                               print '$$';
                                                         >perl test2.pl        print 'Hi pvb265';

                                                                               >test3.pl




  ld12 - imolug     pvb265
a genda                                                                             needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Data Type Data Structure
  .. basics by examples
  .. not to do                 Predefined Variable Running
  . thank's Larry
                               Loop and Condition
                               String Manipulation IO function
                               System Interaction


                                   if (condition) { code } elsif (condition) { code } else { code } ;
                                                for (start,condition,increment) {code};
                                                       while (condition) {code};
                                        for ( my $i=0 ; $i<$MAXMIN ; $i++ ) { $vect[$i]=0; };
                                        while (<FILE>) {
                                          print $_;
                                        }

                                        if ( $tmp /^0101/ ) { print “matched”; }

                                        print “matched” if ( $tmp /^0101/ );




  ld12 - imolug     pvb265
a genda                                                                         needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Data Type Data Structure
  .. basics by examples
  .. not to do                 Predefined Variable Running
  . thank's Larry
                               Loop and Condition
                               String Manipulation IO function
                               System Interaction


                                                 vector = split(char,string);
                                                        chomp($_);
                                                   string =~ s/old/new/g;


                                      my @field=split(',',$_);
                                      my ($d0, $hour, $minute, $d1)=split(':',$field[3]);

                                      $d0 =~ s/00/1/g;




  ld12 - imolug     pvb265
a genda                                                                                 needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter   Data Type Data Structure
  .. basics by examples
  .. not to do                 Predefined Variable Running
  . thank's Larry
                               Loop and Condition
                               String Manipulation IO function
                               System Interaction
                                                       close(filehandler);
                                                       open filehandler, mode, filename;
                               open FILE, "<", $LOGFILE or die $!;
                               while (<FILE>) {
                                 my @field=split(',',$_);
                                 my ($d0, $hour, $minute, $d1)=split(':',$field[3]);
                                 my $minutes=$hour*60+$minute;
                                 $vect[$minutes]++;
                               }                           open FILE, "<", $LOGFILE or die $!;
                               close (FILE);               @lines = <FILE>;
                                                           close (FILE);
                                                           Foreach (@lines) {
                                                             my @field=split(',',$_);
                                                             my ($d0, $hour, $minute, $d1)=split(':',$field[3]);
                                                             my $minutes=$hour*60+$minute;
                                                             $vect[$minutes]++;
                                                           }



  ld12 - imolug     pvb265
a genda                                                                           needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter    Data Type Data Structure
  .. basics by examples
  .. not to do                  Predefined Variable Running
  . thank's Larry
                                Loop and Condition
                                String Manipulation IO function
                                System Interaction
                                                   system(cmdstring);
                                                      `cmdstring`;
                                                     qx/cmdstring/;
                               my $cmd = “generatex509 pvb265”;
                               system($cmd);
                               print $?;                          my $cmd = “generatex509 pvb265”;
                                                                  @lines=`$cmd`;
                                                                  print @lines;
                                                                  print $?;
                               my $cmd = “generatex509 pvb265”;
                               @lines=qx/$cmd/;
                               print @lines;
                               print $?;




  ld12 - imolug     pvb265
needs that lead to the camel LD12




                         faster way
                           not to do




ld12 - imolug   pvb265
a genda                                                   needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry




                               never put sands in your
                                favorite diesel engine!




  ld12 - imolug     pvb265
a genda                                                                             needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry
                               also Perl may appear slow if U ...




                                 choose a slow algorithm

                                                   don't properly use structured data
                                                           Huge array of array of array...
                                                           Huge hash of array of hash...
                                                   LW 'Doing linear scans over an associative array is like
                                                     trying to club someone to death with a loaded Uzi'



                                       don't use regexps




  ld12 - imolug     pvb265
a genda                                                                                needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry
                               also Perl may appear slow if U ...
                                     choose a slow algorithm


                                                      hexadecimal → decimal
                               perl -e'print map {hex $_} "547261aa696e6720ff74796c652f6dff" =~ /(....)/g;'

                               perl -e'print unpack "n*",pack "H*", "547261aa696e6720ff74796c652f6dff";'


                                         21618 25002 26990 26400 65396 31084 25903 28159




  ld12 - imolug     pvb265
a genda                                                                                                        needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry
                                also Perl may appear slow if U ...
                                       choose a slow algorithm

                                                                hexadecimal → decimal
                               perl -e'print map {hex $_} "547261aa696e6720ff74796c652f6dff" =~ /(....)/g;'
                               valeriobalbi$ perl -MO=Terse -e'print map {hex $_} "54726164696e67207374796c652f6d61" =~ /(....)/g;'
                               LISTOP (0x102ff7e20) leave [1]
                                  OP (0x102f02f90) enter
                                  COP (0x102ff7dd0) nextstate
                                  LISTOP (0x102ffbbd0) print
                                    OP (0x102ffbc10) pushmark
                                    LOGOP (0x102ffbb60) mapwhile [3]
                                       LISTOP (0x102ffba80) mapstart
                                         OP (0x102ffbac0) pushmark
                                         UNOP (0x102ffbba0) null
                                            UNOP (0x102ff2ef0) null
                                              LISTOP (0x102f09350) scope
                                                  OP (0x102f1f020) null [181]
                                                  UNOP (0x102f09940) hex [2]
                                                    UNOP (0x102f092a0) null [15]
                                                      PADOP (0x102f02640) gvsv GV (0x7fdcf1803e28) *_
                                         PMOP (0x102f09410) match
                                            SVOP (0x102f094d0) const [4] PV (0x7fdcf1829070) "54726164696e67207374796c652f6d61"
                               -e syntax OK




  ld12 - imolug     pvb265
a genda                                                                                                      needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do
  . thank's Larry
                                also Perl may appear slow if U ...
                                       choose a slow algorithm

                                                              hexadecimal → decimal
                               perl -e'print unpack "n*",pack "H*", "547261aa696e6720ff74796c652f6dff";'
                               valeriobalbi$ perl -MO=Terse -e'print unpack "n*",pack "H*", "547261aa696e6720ff74796c652f6dff";'
                               LISTOP (0x7fd692cfbab0) leave [1]
                                  OP (0x7fd692c02f90) enter
                                  COP (0x7fd692c1f040) nextstate
                                  LISTOP (0x7fd692c09430) print
                                    OP (0x7fd692cfba80) pushmark
                                    LISTOP (0x7fd692c093c0) unpack
                                       OP (0x7fd692c09400) null [3]
                                       SVOP (0x7fd692c02640) const [2] PV (0x7fd693029058) "n*"
                                       LISTOP (0x7fd692c094d0) pack [1]
                                         OP (0x7fd692cf2ef0) pushmark
                                         SVOP (0x7fd692c092a0) const [3] PV (0x7fd693029070) "H*"
                                         SVOP (0x7fd692c09350) const [4] PV (0x7fd693029088) "547261aa696e6720ff74796c652f6dff"
                               -e syntax OK




  ld12 - imolug     pvb265
needs that lead to the camel LD12




                         thank's Lar r y
                         thank's Angel
                           I'm not fired!




ld12 - imolug   pvb265
a genda
                                                                                . scenario




                                                                                .. not to do
                                                                                . faster way




ld12 - imolug
                                                                                .. perl genesis



                                                                                . thank's Larry
                                                                                . canonical way



                                                                                .. basics by examples
                                                                                .. compiler vs interpreter




pvb265
                           0
                               500
                                     1000
                                                  1500
                                                         2000
                                                                2500
                                                                       3000




                00.02.00
                00.44.00
                01.26.00
                02.08.00
                02.50.00
                03.32.00
                04.14.00
                04.56.00
                05.38.00
                06.20.00
                07.02.00
                07.44.00
                08.26.00
                09.08.00
                09.50.00
                10.32.00
                11.14.00
                11.56.00
                12.38.00
                13.20.00
                14.02.00
                14.44.00
                15.26.00
                16.08.00
                16.50.00
                17.32.00
                18.14.00
                18.56.00
                                                                                    ….back to the original problem




                19.38.00
                20.20.00
                21.02.00
                21.44.00
                22.26.00
                23.08.00
                23.50.00
                                            req
                                                                                                                     needs that lead to the camel LD12
a genda
                                                                                . scenario




                                                                                .. not to do
                                                                                . faster way




ld12 - imolug
                                                                                .. perl genesis



                                                                                . thank's Larry
                                                                                . canonical way



                                                                                .. basics by examples
                                                                                .. compiler vs interpreter




pvb265
                           0
                               500
                                     1000
                                                  1500
                                                         2000
                                                                2500
                                                                       3000




                00.02.00
                00.44.00
                01.26.00
                02.08.00
                02.50.00
                03.32.00
                04.14.00
                04.56.00
                05.38.00
                06.20.00
                07.02.00
                07.44.00
                08.26.00
                09.08.00
                09.50.00
                10.32.00
                11.14.00
                11.56.00
                12.38.00
                13.20.00
                14.02.00
                14.44.00
                15.26.00
                16.08.00
                16.50.00
                17.32.00
                18.14.00
                18.56.00
                                                                                    ….back to the original problem




                19.38.00
                20.20.00
                21.02.00
                21.44.00
                22.26.00
                23.08.00
                23.50.00
                                            req
                                                                                                                     needs that lead to the camel LD12
a genda                                                        needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
                               ggi-reporter is more than a project in Perl
  .. not to do
  . thank's Larry




  ld12 - imolug     pvb265
a genda                                                                 needs that lead to the camel LD12
  . scenario
  . canonical way
  . faster way
  .. perl genesis
  .. compiler vs interpreter
  .. basics by examples
  .. not to do


                                       Question Time
  . thank's Larry




                               Valerio Balbi   @pvb265 http://www.valeriobalbi.eu
                                                   skype:pvb265 valerio.balbi@gmail.com


                               Bologna - scienze dell'Informazione 1998
                               Coofounder ImoLUG senior sysadm
                               sysadm security banking e-commerce




  ld12 - imolug     pvb265

Mais conteúdo relacionado

Destaque

Bash in theory and in practice - part one
Bash in theory and in practice - part oneBash in theory and in practice - part one
Bash in theory and in practice - part oneValerio Balbi
 
Eco Philosophy 20-09-2007
Eco Philosophy 20-09-2007Eco Philosophy 20-09-2007
Eco Philosophy 20-09-2007Valerio Balbi
 
FreeLix: Semplicità & Controllo
FreeLix: Semplicità & ControlloFreeLix: Semplicità & Controllo
FreeLix: Semplicità & ControlloValerio Balbi
 
Bash in theory and in practice - part two
Bash in theory and in practice - part twoBash in theory and in practice - part two
Bash in theory and in practice - part twoValerio Balbi
 

Destaque (7)

Bash in theory and in practice - part one
Bash in theory and in practice - part oneBash in theory and in practice - part one
Bash in theory and in practice - part one
 
Eco Philosophy 20-09-2007
Eco Philosophy 20-09-2007Eco Philosophy 20-09-2007
Eco Philosophy 20-09-2007
 
Bash 4
Bash 4Bash 4
Bash 4
 
Bash Geekcamp
Bash GeekcampBash Geekcamp
Bash Geekcamp
 
FreeLix: Semplicità & Controllo
FreeLix: Semplicità & ControlloFreeLix: Semplicità & Controllo
FreeLix: Semplicità & Controllo
 
Bash in theory and in practice - part two
Bash in theory and in practice - part twoBash in theory and in practice - part two
Bash in theory and in practice - part two
 
bash
bashbash
bash
 

pearls of Perl

  • 1. needs that lead to the camel Per l 1987 18 December ld12 - imolug pvb265
  • 2. needs that lead to the camel LD12 a genda . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry ld12 - imolug pvb265
  • 3. needs that lead to the camel LD12 scenario ld12 - imolug pvb265
  • 4. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry ● our e-commerce site is slow ● we are loosing money due to slow performance ● the users experience says that the site is unusable ld12 - imolug pvb265
  • 5. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do ● our e-commerce site is slow . thank's Larry ● we are loosing money due to slow performance ● the users experience says that the site is unusable ● resolve the issue ● do it soon ld12 - imolug pvb265
  • 6. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do ● our e-commerce site is slow . thank's Larry ● we are loosing money due to slow performance ● the users experience says that the site is unusable ● resolve the issue ● do it soon db-server ld12 - imolug pvb265
  • 7. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do ● our e-commerce site is slow . thank's Larry ● we are loosing money due to slow performance ● the users experience says that the site is unusable ● resolve the issue ● do it soon app-server db-server ld12 - imolug pvb265
  • 8. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do ● our e-commerce site is slow . thank's Larry ● we are loosing money due to slow performance ● the users experience says that the site is unusable ● resolve the issue ● do it soon web-server app-server db-server ld12 - imolug pvb265
  • 9. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do ● our e-commerce site is slow . thank's Larry ● we are loosing money due to slow performance ● the users experience says that the site is unusable ● resolve the issue ● do it soon web-cluster app-cluster db-cluster ld12 - imolug pvb265
  • 10. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do ● our e-commerce site is slow . thank's Larry ● we are loosing money due to slow performance ● the users experience says that the site is unusable ● resolve the issue ● do it soon ● complexity and high reliability web-cluster app-cluster db-cluster ld12 - imolug pvb265
  • 11. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do ● our e-commerce site is slow . thank's Larry ● we are loosing money due to slow performance ● the users experience says that the site is unusable ● logs are our best friends ● logs must exists ● logs must be readable ● logs may be very large ld12 - imolug pvb265
  • 12. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do ● our e-commerce site is slow . thank's Larry ● we are loosing money due to slow performance ● the users experience says that the site is unusable ● logs are our best friends MacBook-Pro-di-valerio:data valeriobalbi$ ls -l total 208392 -rw-r--r-- 1 valeriobalbi staff 106676224 24 Set 16:57 www.imolugcommerce.com-access.log MacBook-Pro-di-valerio:data valeriobalbi$ head 10 www.imolugcommerce.com-access.log head: 10: No such file or directory ==> www.imolugcommerce.com-access.log <== 109.93.188.182,-,-,[09/Apr/2012:23:59:05,+0200],0,200,8895,109.93.188.182,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB 109.93.188.182,-,-,[09/Apr/2012:23:59:05,+0200],0,200,5737,109.93.188.182,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB 109.112.65.154,-,-,[09/Apr/2012:23:59:05,+0200],0,200,19398,109.112.65.154,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TST 109.93.188.182,-,-,[09/Apr/2012:23:59:05,+0200],0,200,13405,109.93.188.182,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TST 109.121.26.105,-,-,[09/Apr/2012:23:59:04,+0200],0,200,16210,109.121.26.105,www.imolugcommerce.com,(mod_was_ap22_http.c/-2/handler),wcn 109.93.188.182,-,-,[09/Apr/2012:23:59:05,+0200],0,200,893,109.93.188.182,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB2 79.103.238.28,-,-,[09/Apr/2012:23:59:05,+0200],0,404,333,79.103.238.28,www.imolugcommerce.com,(core.c/404/handler),-,"GET,/wcsstore/TSTB2 109.112.65.154,-,-,[09/Apr/2012:23:59:05,+0200],0,200,4612,109.112.65.154,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB 109.112.65.154,-,-,[09/Apr/2012:23:59:05,+0200],0,200,1333,109.112.65.154,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB 109.112.65.154,-,-,[09/Apr/2012:23:59:05,+0200],0,200,1062,109.112.65.154,www.imolugcommerce.com,(core.c/0/handler),-,"GET,/wcsstore/TSTB ld12 - imolug pvb265
  • 13. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do ● our e-commerce site is slow . thank's Larry ● we are loosing money due to slow performance ● the users experience says that the site is unusable ● logs are our best friends ● response/minute ● return code http/minute ● top ten sloow response ld12 - imolug pvb265
  • 14. needs that lead to the camel LD12 canonical way ld12 - imolug pvb265
  • 15. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry Bash Sed Awk ld12 - imolug pvb265
  • 16. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Bash .. basics by examples .. not to do . thank's Larry Sed Awk Brian Fox GNU Project 1989 command processor script wildcard piping variables Bourne-again shell command($@) = $? stdOUT stdIN → command → command1 && command2 stdERR command1 || command2 command [ | command2 ... ] while list; do list; done $(command) `command` until list; do list; done $((expression)) ld12 - imolug pvb265
  • 17. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Bash Sed Awk .. basics by examples .. not to do . thank's Larry stream editor Unix utility parser text transformations line by line 1974 Lee E. McMahon sed -e 's/old/new/g' inputFileName > outputFileName cat inputFileName | sed -e 's/old/new/g' cat inputFileName | sed 's/pattern//g' cat inputFileName | sed '/pattern/d' 's/^$/VOIDLINE/g' 's/^[01]*a[bc]*//g' ld12 - imolug pvb265
  • 18. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Bash Sed Awk .. basics by examples .. not to do . thank's Larry Bell Labs 1977 operations on fields Alfred Aho, Peter Weinberger, Brian Kernighan all OS associative arrays regular expressions line_oriented condition { action } cat inputFileName | awk '{ print $1 $2 }' awk '{ print $1 $2 }' inputFileName > outputFileName Inline awk -F':' '{ print $1 $2 }' inputFileName script awk -f myscript.awk inputFileName awk ' if ( NR > 10 ) { print $1 $2 } ' BEGIN { FS=":" } { print $1 } END { print “hello world!” } ld12 - imolug pvb265
  • 19. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do #!/bin/bash . thank's Larry MAXMIN=1440 LOGFILE=$1 declare -ax vect echo "Inizializzazione $(date)" for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done echo "Analisi File $(date)" IFS="," while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 do minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g') awk sed hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g') sed if [ "$minute." == "." ]; then minute=0; fi if [ "$hour." == "." ]; then hour=0; fi tmp_m=$(($hour*60)) minutes=$(($tmp_m+$minute)) vect[$minutes]=$((${vect[$minutes]}+1)) done < $LOGFILE echo "risultati $(date)" for ( i=0 ; $i<$MAXMIN ; i++ ) ; do echo -n "$i " echo ${vect[$i]} done echo "fine $(date)" ld12 - imolug pvb265
  • 20. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do #!/bin/bash . thank's Larry MAXMIN=1440 LOGFILE=$1 declare -ax vect echo "Inizializzazione $(date)" for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done echo "Analisi File $(date)" IFS="," while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 do minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g') awk sed hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g') sed if [ "$minute." == "." ]; then minute=0; fi if [ "$hour." == "." ]; then hour=0; fi tmp_m=$(($hour*60)) minutes=$(($tmp_m+$minute)) vect[$minutes]=$((${vect[$minutes]}+1)) done < $LOGFILE echo "risultati $(date)" for ( i=0 ; $i<$MAXMIN ; i++ ) ; do echo -n "$i " echo ${vect[$i]} done echo "fine $(date)" ld12 - imolug pvb265
  • 21. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do #!/bin/bash . thank's Larry MAXMIN=1440 LOGFILE=$1 declare -ax vect echo "Inizializzazione $(date)" for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done echo "Analisi File $(date)" IFS="," while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 do minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g') awk sed hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g') sed if [ "$minute." == "." ]; then minute=0; fi if [ "$hour." == "." ]; then hour=0; fi tmp_m=$(($hour*60)) minutes=$(($tmp_m+$minute)) vect[$minutes]=$((${vect[$minutes]}+1)) done < $LOGFILE echo "risultati $(date)" for ( i=0 ; $i<$MAXMIN ; i++ ) ; do echo -n "$i " echo ${vect[$i]} done echo "fine $(date)" ld12 - imolug pvb265
  • 22. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do #!/bin/bash . thank's Larry MAXMIN=1440 LOGFILE=$1 declare -ax vect echo "Inizializzazione $(date)" for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done echo "Analisi File $(date)" IFS="," while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 do minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g') awk sed hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g') sed if [ "$minute." == "." ]; then minute=0; fi if [ "$hour." == "." ]; then hour=0; fi tmp_m=$(($hour*60)) minutes=$(($tmp_m+$minute)) vect[$minutes]=$((${vect[$minutes]}+1)) done < $LOGFILE echo "risultati $(date)" for ( i=0 ; $i<$MAXMIN ; i++ ) ; do echo -n "$i " echo ${vect[$i]} done echo "fine $(date)" ld12 - imolug pvb265
  • 23. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do 8000 . thank's Larry 7000 6000 5000 f(x) = 4.63x - 0.06 4000 native 3000 Linear (native) 2000 1000 0 123,000 183,000 363,000 423,000 483,000 663,000 723,000 783,000 963,000 1,143,000 3,000 63,000 243,000 303,000 543,000 603,000 843,000 903,000 1,023,000 1,083,000 1,203,000 1,263,000 1,323,000 1,383,000 1,443,000 50 minutes for 600.000 requests still no answer you gotta fired ld12 - imolug pvb265
  • 24. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter 1 #!/bin/bash .. basics by examples MAXMIN=1440 .. not to do LOGFILE=$1 . thank's Larry declare -ax vect 2 echo "Inizializzazione $(date)" for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done 2 echo "Analisi File $(date)" IFS="," while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 do 3 minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g') echo awk sed 3 hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g') echo sed if [ "$minute." == "." ]; then minute=0; fi if [ "$hour." == "." ]; then hour=0; fi tmp_m=$(($hour*60)) minutes=$(($tmp_m+$minute)) vect[$minutes]=$((${vect[$minutes]}+1)) done < $LOGFILE 2 echo "risultati $(date)" for ( i=0 ; $i<$MAXMIN ; i++ ) ; do 1 echo -n "$i " 1 echo ${vect[$i]} done 2 echo "fine $(date)" ld12 - imolug pvb265
  • 25. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter 1 #!/bin/bash .. basics by examples MAXMIN=1440 .. not to do LOGFILE=$1 . thank's Larry declare -ax vect 2 echo "Inizializzazione $(date)" for (( i=0 ; $i<$MAXMIN ; i++ )) ; do vect[$i]=0 ; done 2 echo "Analisi File $(date)" IFS="," while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 do minute=$(echo $a4|awk -F':' ' { print $3} '|sed 's/^0*//g') echo awk sed fork/exec → 2880+9 + 6N 3 3 hour=$(echo $a4|awk -F':' ' { print $2} '|sed 's/^0*//g') echo sed if [ "$minute." == "." ]; then minute=0; fi line read → N if [ "$hour." == "." ]; then hour=0; fi tmp_m=$(($hour*60)) minutes=$(($tmp_m+$minute)) vect[$minutes]=$((${vect[$minutes]}+1)) done < $LOGFILE 2 echo "risultati $(date)" f(N)=6N+K for ( i=0 ; $i<$MAXMIN ; i++ ) ; do 1 echo -n "$i " 1 echo ${vect[$i]} done 2 echo "fine $(date)" ld12 - imolug pvb265
  • 26. needs that lead to the camel LD12 faster way ld12 - imolug pvb265
  • 27. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry AngelSpot (@mod186k1) says: why don't in PERL? ld12 - imolug pvb265
  • 28. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter #!/usr/bin/perl -w .. basics by examples .. not to do my $MAXMIN=1440; . thank's Larry my $LOGFILE=shift(); my @vect; print "Inizializzazione ".qx/'date'/; for ( my $i=0 ; $i<$MAXMIN ; $i++ ) { $vect[$i]=0; } print "Analisi File ".qx/'date'/; open FILE, "<", $LOGFILE or die $!; while (<FILE>) { my @field=split(',',$_); my ($d0, $hour, $minute, $d1)=split(':',$field[3]); my $minutes=$hour*60+$minute; $vect[$minutes]++; } close (FILE); print "risultati ".qx/'date'/; for ( my $j=0 ; $j<$MAXMIN ; $j++ ) { printf "%s %sn",$j,$vect[$j]; } print "fine ".qx/'date'/; ld12 - imolug pvb265
  • 29. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter #!/usr/bin/perl -w .. basics by examples .. not to do my $MAXMIN=1440; . thank's Larry my $LOGFILE=shift(); my @vect; print "Inizializzazione ".qx/'date'/; for ( my $i=0 ; $i<$MAXMIN ; $i++ ) { $vect[$i]=0; } print "Analisi File ".qx/'date'/; open FILE, "<", $LOGFILE or die $!; while (<FILE>) { my @field=split(',',$_); my ($d0, $hour, $minute, $d1)=split(':',$field[3]); my $minutes=$hour*60+$minute; $vect[$minutes]++; } close (FILE); print "risultati ".qx/'date'/; for ( my $j=0 ; $j<$MAXMIN ; $j++ ) { printf "%s %sn",$j,$vect[$j]; } print "fine ".qx/'date'/; ld12 - imolug pvb265
  • 30. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter #!/usr/bin/perl -w .. basics by examples .. not to do my $MAXMIN=1440; . thank's Larry my $LOGFILE=shift(); my @vect; print "Inizializzazione ".qx/'date'/; for ( my $i=0 ; $i<$MAXMIN ; $i++ ) { $vect[$i]=0; } print "Analisi File ".qx/'date'/; open FILE, "<", $LOGFILE or die $!; while (<FILE>) { my @field=split(',',$_); my ($d0, $hour, $minute, $d1)=split(':',$field[3]); my $minutes=$hour*60+$minute; $vect[$minutes]++; } close (FILE); print "risultati ".qx/'date'/; for ( my $j=0 ; $j<$MAXMIN ; $j++ ) { printf "%s %sn",$j,$vect[$j]; } print "fine ".qx/'date'/; ld12 - imolug pvb265
  • 31. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter #!/usr/bin/perl -w .. basics by examples .. not to do my $MAXMIN=1440; . thank's Larry my $LOGFILE=shift(); my @vect; print "Inizializzazione ".qx/'date'/; for ( my $i=0 ; $i<$MAXMIN ; $i++ ) { $vect[$i]=0; } print "Analisi File ".qx/'date'/; open FILE, "<", $LOGFILE or die $!; while (<FILE>) { my @field=split(',',$_); my ($d0, $hour, $minute, $d1)=split(':',$field[3]); my $minutes=$hour*60+$minute; $vect[$minutes]++; } close (FILE); print "risultati ".qx/'date'/; for ( my $j=0 ; $j<$MAXMIN ; $j++ ) { printf "%s %sn",$j,$vect[$j]; } print "fine ".qx/'date'/; ld12 - imolug pvb265
  • 32. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry 8000 7000 6000 5000 f(x) = 4.63x - 0.06 4000 native Linear (native) 3000 perl 2000 Linear (perl) 1000 f(x) = 0.02x + 0.44 0 68,000 132,000 196,000 388,000 452,000 516,000 708,000 772,000 836,000 1,028,000 1,092,000 1,156,000 1,220,000 1,284,000 1,348,000 1,412,000 4,000 260,000 324,000 580,000 644,000 900,000 964,000 only 8 seconds for 600.000 requests just in time analisys came true ld12 - imolug pvb265
  • 33. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry 8000 7000 6000 5000 f(x) = 4.63x - 0.06 4000 native Linear (native) 3000 perl 2000 f(x)=mx+q Linear (perl) 1000 f(x) = 0.02x + 0.44 0 fnative(x)=4,63x – 0,06 68,000 132,000 196,000 388,000 452,000 516,000 708,000 772,000 836,000 1,028,000 1,092,000 1,156,000 1,220,000 1,284,000 1,348,000 1,412,000 4,000 260,000 324,000 580,000 644,000 900,000 964,000 fperl(x)=0,02x – 0,44 4,63/0,02=231,5 only 8 seconds for 600.000 requests just in time analisys came true ld12 - imolug pvb265
  • 34. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way Python Ruby Perl C .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do Version 1.5.2 1.4.5 5.0pl5sv3 egcs-1.1.2 . thank's Larry GC Style RefCount GC RefCount None Tested-on 2000-07-19 2000-07-19 2001-04-18 2001-04-18 loop_test(500.000) 33.94 17.16 18.95 0.16 index_test(1.000.000) 17.64 26.49 23.83 1.44 nested_int_test(23) 43.55 84.95 27.69 0.09 Returntest(5.000.000) 74.31 53.02 156.24 0.42 Functest(5.000.000) 63.85 53.84 106.24 0.39 file_line_test 9.53 27.87 9.88 1.50 file_line_split_test 44.80 n/a 35.35 7.28 file_line_re_test 294.83 n/a 43.86 n/a http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/ ld12 - imolug pvb265
  • 35. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way Python Ruby Perl C .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do Version 1.5.2 1.4.5 5.0pl5sv3 egcs-1.1.2 . thank's Larry GC Style RefCount GC RefCount None Tested-on 2000-07-19 2000-07-19 2001-04-18 2001-04-18 loop_test(500.000) 33.94 17.16 18.95 0.16 Perform two nested loops, the outer loop of 500.000 iterations index_test(1.000.000) 17.64 26.49 23.83 1.44 and the inner of 10 iterations nested_int_test(23) 43.55 84.95 27.69 0.09 Nested Loops Returntest(5.000.000) 74.31 53.02 156.24 0.42 Functest(5.000.000) 63.85 53.84 106.24 0.39 file_line_test 9.53 27.87 9.88 1.50 file_line_split_test 44.80 n/a 35.35 7.28 file_line_re_test 294.83 n/a 43.86 n/a http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/ ld12 - imolug pvb265
  • 36. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way Python Ruby Perl C .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do Version 1.5.2 1.4.5 5.0pl5sv3 egcs-1.1.2 . thank's Larry GC Style RefCount GC RefCount None Tested-on 2000-07-19 2000-07-19 2001-04-18 2001-04-18 loop_test(500.000) 33.94 17.16 18.95 0.16 index_test(1.000.000) 17.64 26.49 23.83 1.44 Write 1.000.000 elements into hash-table and read then nested_int_test(23) 43.55 84.95 27.69 0.09 back Hash Table Returntest(5.000.000) 74.31 53.02 156.24 0.42 Functest(5.000.000) 63.85 53.84 106.24 0.39 file_line_test 9.53 27.87 9.88 1.50 file_line_split_test 44.80 n/a 35.35 7.28 file_line_re_test 294.83 n/a 43.86 n/a http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/ ld12 - imolug pvb265
  • 37. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way Python Ruby Perl C .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do Version 1.5.2 1.4.5 5.0pl5sv3 egcs-1.1.2 . thank's Larry GC Style RefCount GC RefCount None Tested-on 2000-07-19 2000-07-19 2001-04-18 2001-04-18 loop_test(500.000) 33.94 17.16 18.95 0.16 index_test(1.000.000) 17.64 26.49 23.83 1.44 nested_int_test(23) 43.55 84.95 27.69 0.09 Five level of nested loops each of 23 iteration and at each level some simple arithmetic operation Returntest(5.000.000) 74.31 53.02 156.24 0.42 on a local variable Functest(5.000.000) 63.85 53.84 106.24 0.39 Nested Loops + Arithmetics on file_line_test 9.53 27.87 9.88 1.50 Local Vars file_line_split_test 44.80 n/a 35.35 7.28 file_line_re_test 294.83 n/a 43.86 n/a http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/ ld12 - imolug pvb265
  • 38. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way Python Ruby Perl C .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do Version 1.5.2 1.4.5 5.0pl5sv3 egcs-1.1.2 . thank's Larry GC Style RefCount GC RefCount None Tested-on 2000-07-19 2000-07-19 2001-04-18 2001-04-18 loop_test(500.000) 33.94 17.16 18.95 0.16 index_test(1.000.000) 17.64 26.49 23.83 1.44 nested_int_test(23) 43.55 84.95 27.69 0.09 Returntest(5.000.000) 74.31 53.02 156.24 0.42 Test the cost of multiple argument return by performing 5.000.000 Functest(5.000.000) 63.85 106.24 Function call which return 53.84 0.39 Arguments unpacked into local variables file_line_test 9.53 27.87 9.88 1.50 Return Arguments file_line_split_test 44.80 n/a 35.35 7.28 file_line_re_test 294.83 n/a 43.86 n/a http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/ ld12 - imolug pvb265
  • 39. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way Python Ruby Perl C .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do Version 1.5.2 1.4.5 5.0pl5sv3 egcs-1.1.2 . thank's Larry GC Style RefCount GC RefCount None Tested-on 2000-07-19 2000-07-19 2001-04-18 2001-04-18 loop_test(500.000) 33.94 17.16 18.95 0.16 index_test(1.000.000) 17.64 26.49 23.83 1.44 nested_int_test(23) 43.55 84.95 27.69 0.09 Returntest(5.000.000) 74.31 53.02 156.24 0.42 Test the cost of function calls by Performing 5.000.000 function calls Functest(5.000.000) 63.85 106.24 with one integer argument which 53.84 0.39 returns that argument file_line_test 9.53 27.87 9.88 1.50 Functions Calling file_line_split_test 44.80 n/a 35.35 7.28 file_line_re_test 294.83 n/a 43.86 n/a http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/ ld12 - imolug pvb265
  • 40. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way Python Ruby Perl C .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do Version 1.5.2 1.4.5 5.0pl5sv3 egcs-1.1.2 . thank's Larry GC Style RefCount GC RefCount None Tested-on 2000-07-19 2000-07-19 2001-04-18 2001-04-18 loop_test(500.000) 33.94 17.16 18.95 0.16 index_test(1.000.000) 17.64 26.49 23.83 1.44 nested_int_test(23) 43.55 84.95 27.69 0.09 Returntest(5.000.000) 74.31 53.02 156.24 0.42 Functest(5.000.000) 63.85 53.84 106.24 0.39 file_line_test 9.53 27.87 9.88 1.50 Time spent opening the file and reading it line by line file_line_split_test 44.80 n/a 35.35 7.28 Reading File file_line_re_test 294.83 n/a 43.86 n/a http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/ ld12 - imolug pvb265
  • 41. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way Python Ruby Perl C .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do Version 1.5.2 1.4.5 5.0pl5sv3 egcs-1.1.2 . thank's Larry GC Style RefCount GC RefCount None Tested-on 2000-07-19 2000-07-19 2001-04-18 2001-04-18 loop_test(500.000) 33.94 17.16 18.95 0.16 index_test(1.000.000) 17.64 26.49 23.83 1.44 nested_int_test(23) 43.55 84.95 27.69 0.09 Returntest(5.000.000) 74.31 53.02 156.24 0.42 Functest(5.000.000) 63.85 53.84 106.24 0.39 Reading Line by Line file_line_test 9.53 27.87 9.88 1.50 and Splitting file_line_split_test 44.80 n/a 35.35 7.28 Time spent opening the file and reading it line by line splitting each file_line_re_test 294.83 n/a 43.86 n/a line in token vector http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/ ld12 - imolug pvb265
  • 42. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way Python Ruby Perl C .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do Version 1.5.2 1.4.5 5.0pl5sv3 egcs-1.1.2 . thank's Larry GC Style RefCount GC RefCount None Tested-on 2000-07-19 2000-07-19 2001-04-18 2001-04-18 loop_test(500.000) 33.94 17.16 18.95 0.16 index_test(1.000.000) 17.64 26.49 23.83 1.44 nested_int_test(23) 43.55 84.95 27.69 0.09 Returntest(5.000.000) 74.31 53.02 156.24 0.42 Reading Line by Line Functest(5.000.000) 63.85 53.84 106.24 0.39 and Splitting + Conditional Operations file_line_test 9.53 27.87 9.88 1.50 Time spent opening the file and file_line_split_test 44.80 n/a 35.35 7.28 reading it line by line, splitting each line in token vector with simple conditional analisys and file_line_re_test 294.83 n/a 43.86 n/a assegnation to local variables http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/ ld12 - imolug pvb265
  • 43. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way Python Ruby Perl C .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do Version 1.5.2 1.4.5 5.0pl5sv3 egcs-1.1.2 . thank's Larry GC Style RefCount GC RefCount None Tested-on 2000-07-19 2000-07-19 2001-04-18 2001-04-18 loop_test(500.000) 33.94 17.16 18.95 0.16 index_test(1.000.000) 17.64 26.49 23.83 1.44 nested_int_test(23) 43.55 84.95 27.69 0.09 reding file, Returntest(5.000.000) 74.31 53.02 156.24 0.42 manipulating strings, Functest(5.000.000) 63.85 53.84 106.24 0.39 loops and operations file_line_test 9.53 27.87 9.88 1.50 file_line_split_test 44.80 n/a 35.35 7.28 file_line_re_test 294.83 n/a 43.86 n/a http://dj1.willowmail.com/~jeske/Projects/ScriptPerf/ ld12 - imolug pvb265
  • 44. needs that lead to the camel LD12 faster way Perl genesis ld12 - imolug pvb265
  • 45. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry Larry Wall 1954 bachelor's degree in Natural and Artificial Languages Practical Extraction and Report Language Pathologically Eclectic Rubbish Lister Laziness, Impatience and Hubris 1987 http://www.linuxjournal.com/article/3394 ld12 - imolug pvb265
  • 46. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Naming it Perl Practical Extraction and Report Language .. basics by examples .. not to do perl / Perl programm/Language . thank's Larry imperfect ”Perl was never designed to be perfect” adaptive “Over-specialization is only as good as your ecological niche” Perl 1.0 18 december 1987 newsgroup: comp.sources.misc Perl 2.0 1988 feature: better regular expression engine Perl 3.0 1989 feature: binary data streams Perl 4.0 1991 well documented, published Programming Perl (aka Camel Book) Perl 5.000 17 october 1994 extending the language without modifying the core interpreter Perl 5.001 13 march 1995 CPAN 26 october 1995 comprehensive perl archive network Perl 5.002 29 february 1996 feature: subroutine Perl 5.003 25 june 1996 security release Perl 5.004 15 may 1997 Perl 5.005 22 july 1998 http://www.linuxjournal.com/article/3394 ld12 - imolug pvb265
  • 47. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Naming it Perl Practical Extraction and Report Language .. basics by examples .. not to do perl / Perl programm/Language . thank's Larry imperfect ”Perl was never designed to be perfect” adaptive “Over-specialization is only as good as your ecological niche” Perl 5.6 22 march 2000 feature: 64bit support, unicode, large file support Perl 6.0 19 july 2000 first announced by Larry in “State of the Onion 2000” talk Perl 5.10 18 december 2007 20th anniversary Perl 5.12 now http://www.linuxjournal.com/article/3394 ld12 - imolug pvb265
  • 48. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Naming it Perl Practical Extraction and Report Language .. basics by examples .. not to do perl / Perl programm/Language . thank's Larry imperfect ”Perl was never designed to be perfect” adaptive “Over-specialization is only as good as your ecological niche” Perl history realease from 1.0 to 5.12 (6.0) main characteristics text-processing language modular glues for interstices UNICODE to be worldwide useful flexible http://www.linuxjournal.com/article/3394 ld12 - imolug pvb265
  • 49. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Naming it Perl Practical Extraction and Report Language .. basics by examples .. not to do perl / Perl programm/Language . thank's Larry imperfect ”Perl was never designed to be perfect” adaptive “Over-specialization is only as good as your ecological niche” Perl history realease from 1.0 to 5.12 (6.0) main characteristics text-processing language modular gluesthe interstices for only POST-MODERN flexible UNICODE to be worldwide useful language http://www.linuxjournal.com/article/3394 ld12 - imolug pvb265
  • 50. needs that lead to the camel LD12 faster way compiler vs interpreter ld12 - imolug pvb265
  • 51. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry A compiler is a program that reads code written in one source language and translate it into the same written in a second language ld12 - imolug pvb265
  • 52. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples position := initial + rate * 60 .. not to do . thank's Larry ld12 - imolug pvb265
  • 53. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples := .. not to do . thank's Larry position initial + rate * 60 ld12 - imolug pvb265
  • 54. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples := .. not to do . thank's Larry position + initial rate * 60 ld12 - imolug pvb265
  • 55. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples := .. not to do . thank's Larry position + initial * rate 60 ld12 - imolug pvb265
  • 56. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples := .. not to do . thank's Larry position + initial * rate 60 ld12 - imolug pvb265
  • 57. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples := .. not to do . thank's Larry position + initial * rate 60 syntax check syntax check optimization optimization executable execute ld12 - imolug pvb265
  • 58. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples := .. not to do . thank's Larry position + initial * rate 60 compiler interpreter syntax check syntax check optimization optimization executable execute ld12 - imolug pvb265
  • 59. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples := .. not to do . thank's Larry position + initial * rate 60 compiler like Java interpreter syntax check syntax check syntax check optimization optimization optimization bytecode executable VM per SO execute execute ld12 - imolug pvb265
  • 60. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry compiler C C++ Pascal PL/1 like Java Java interpreter Bash Basic Lisp Javascript ld12 - imolug pvb265
  • 61. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry compiler C C++ Pascal PL/1 like Java Java interpreter Perl Bash Basic Lisp Javascript ld12 - imolug pvb265
  • 62. needs that lead to the camel LD12 faster way basics by examples ld12 - imolug pvb265
  • 63. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry We can't condense the specifications of a language in a few slides, but You can fall in love seeing some simple examples. ld12 - imolug pvb265
  • 64. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Data Type Data Structure .. basics by examples .. not to do Predefined Variable Running . thank's Larry Loop and Condition String Manipulation IO function System Interaction ld12 - imolug pvb265
  • 65. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Data Type Data Structure .. basics by examples .. not to do Predefined Variable Running . thank's Larry Loop and Condition String Manipulation IO function System Interaction dynamically typed undef value my $MAXMIN=1440; my $j=0; my $name=”Valerio”; ld12 - imolug pvb265
  • 66. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Data Type Data Structure .. basics by examples .. not to do Predefined Variable Running . thank's Larry Loop and Condition String Manipulation IO function System Interaction @array %hash my @vect; my %vect; my $vect[$i]=0; my %vect{'sun'}='sunday'; my %vect{'mon'}='monday'; foreach $element (@vect) { foreach $key (keys %vect) { print “$elementn”; print “$key = $vect{$key}n”; } } print scalar(@vect); ld12 - imolug pvb265
  • 67. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Data Type Data Structure .. basics by examples .. not to do Predefined Variable Running . thank's Larry Loop and Condition String Manipulation IO function System Interaction $_ default input $! current error $$ process number $ARGV number of parameter @ARGV parameter @_ subroutine parameter open FILE, "<", $LOGFILE or die $!; my @field=split(',',$_); ld12 - imolug pvb265
  • 68. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Data Type Data Structure .. basics by examples .. not to do Predefined Variable Running . thank's Larry Loop and Condition String Manipulation IO function System Interaction perl in line execution of an interpreter script self interpreting >perl -e “print '$$'; print 'Hi pvb265!'; ”; >cat test2.pl print '$$'; >cat test3.pl print 'Hi pvb265'; #!/usr/bin/perl print '$$'; >perl test2.pl print 'Hi pvb265'; >test3.pl ld12 - imolug pvb265
  • 69. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Data Type Data Structure .. basics by examples .. not to do Predefined Variable Running . thank's Larry Loop and Condition String Manipulation IO function System Interaction if (condition) { code } elsif (condition) { code } else { code } ; for (start,condition,increment) {code}; while (condition) {code}; for ( my $i=0 ; $i<$MAXMIN ; $i++ ) { $vect[$i]=0; }; while (<FILE>) { print $_; } if ( $tmp /^0101/ ) { print “matched”; } print “matched” if ( $tmp /^0101/ ); ld12 - imolug pvb265
  • 70. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Data Type Data Structure .. basics by examples .. not to do Predefined Variable Running . thank's Larry Loop and Condition String Manipulation IO function System Interaction vector = split(char,string); chomp($_); string =~ s/old/new/g; my @field=split(',',$_); my ($d0, $hour, $minute, $d1)=split(':',$field[3]); $d0 =~ s/00/1/g; ld12 - imolug pvb265
  • 71. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Data Type Data Structure .. basics by examples .. not to do Predefined Variable Running . thank's Larry Loop and Condition String Manipulation IO function System Interaction close(filehandler); open filehandler, mode, filename; open FILE, "<", $LOGFILE or die $!; while (<FILE>) { my @field=split(',',$_); my ($d0, $hour, $minute, $d1)=split(':',$field[3]); my $minutes=$hour*60+$minute; $vect[$minutes]++; } open FILE, "<", $LOGFILE or die $!; close (FILE); @lines = <FILE>; close (FILE); Foreach (@lines) { my @field=split(',',$_); my ($d0, $hour, $minute, $d1)=split(':',$field[3]); my $minutes=$hour*60+$minute; $vect[$minutes]++; } ld12 - imolug pvb265
  • 72. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter Data Type Data Structure .. basics by examples .. not to do Predefined Variable Running . thank's Larry Loop and Condition String Manipulation IO function System Interaction system(cmdstring); `cmdstring`; qx/cmdstring/; my $cmd = “generatex509 pvb265”; system($cmd); print $?; my $cmd = “generatex509 pvb265”; @lines=`$cmd`; print @lines; print $?; my $cmd = “generatex509 pvb265”; @lines=qx/$cmd/; print @lines; print $?; ld12 - imolug pvb265
  • 73. needs that lead to the camel LD12 faster way not to do ld12 - imolug pvb265
  • 74. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry never put sands in your favorite diesel engine! ld12 - imolug pvb265
  • 75. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry also Perl may appear slow if U ... choose a slow algorithm don't properly use structured data Huge array of array of array... Huge hash of array of hash... LW 'Doing linear scans over an associative array is like trying to club someone to death with a loaded Uzi' don't use regexps ld12 - imolug pvb265
  • 76. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry also Perl may appear slow if U ... choose a slow algorithm hexadecimal → decimal perl -e'print map {hex $_} "547261aa696e6720ff74796c652f6dff" =~ /(....)/g;' perl -e'print unpack "n*",pack "H*", "547261aa696e6720ff74796c652f6dff";' 21618 25002 26990 26400 65396 31084 25903 28159 ld12 - imolug pvb265
  • 77. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry also Perl may appear slow if U ... choose a slow algorithm hexadecimal → decimal perl -e'print map {hex $_} "547261aa696e6720ff74796c652f6dff" =~ /(....)/g;' valeriobalbi$ perl -MO=Terse -e'print map {hex $_} "54726164696e67207374796c652f6d61" =~ /(....)/g;' LISTOP (0x102ff7e20) leave [1] OP (0x102f02f90) enter COP (0x102ff7dd0) nextstate LISTOP (0x102ffbbd0) print OP (0x102ffbc10) pushmark LOGOP (0x102ffbb60) mapwhile [3] LISTOP (0x102ffba80) mapstart OP (0x102ffbac0) pushmark UNOP (0x102ffbba0) null UNOP (0x102ff2ef0) null LISTOP (0x102f09350) scope OP (0x102f1f020) null [181] UNOP (0x102f09940) hex [2] UNOP (0x102f092a0) null [15] PADOP (0x102f02640) gvsv GV (0x7fdcf1803e28) *_ PMOP (0x102f09410) match SVOP (0x102f094d0) const [4] PV (0x7fdcf1829070) "54726164696e67207374796c652f6d61" -e syntax OK ld12 - imolug pvb265
  • 78. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do . thank's Larry also Perl may appear slow if U ... choose a slow algorithm hexadecimal → decimal perl -e'print unpack "n*",pack "H*", "547261aa696e6720ff74796c652f6dff";' valeriobalbi$ perl -MO=Terse -e'print unpack "n*",pack "H*", "547261aa696e6720ff74796c652f6dff";' LISTOP (0x7fd692cfbab0) leave [1] OP (0x7fd692c02f90) enter COP (0x7fd692c1f040) nextstate LISTOP (0x7fd692c09430) print OP (0x7fd692cfba80) pushmark LISTOP (0x7fd692c093c0) unpack OP (0x7fd692c09400) null [3] SVOP (0x7fd692c02640) const [2] PV (0x7fd693029058) "n*" LISTOP (0x7fd692c094d0) pack [1] OP (0x7fd692cf2ef0) pushmark SVOP (0x7fd692c092a0) const [3] PV (0x7fd693029070) "H*" SVOP (0x7fd692c09350) const [4] PV (0x7fd693029088) "547261aa696e6720ff74796c652f6dff" -e syntax OK ld12 - imolug pvb265
  • 79. needs that lead to the camel LD12 thank's Lar r y thank's Angel I'm not fired! ld12 - imolug pvb265
  • 80. a genda . scenario .. not to do . faster way ld12 - imolug .. perl genesis . thank's Larry . canonical way .. basics by examples .. compiler vs interpreter pvb265 0 500 1000 1500 2000 2500 3000 00.02.00 00.44.00 01.26.00 02.08.00 02.50.00 03.32.00 04.14.00 04.56.00 05.38.00 06.20.00 07.02.00 07.44.00 08.26.00 09.08.00 09.50.00 10.32.00 11.14.00 11.56.00 12.38.00 13.20.00 14.02.00 14.44.00 15.26.00 16.08.00 16.50.00 17.32.00 18.14.00 18.56.00 ….back to the original problem 19.38.00 20.20.00 21.02.00 21.44.00 22.26.00 23.08.00 23.50.00 req needs that lead to the camel LD12
  • 81. a genda . scenario .. not to do . faster way ld12 - imolug .. perl genesis . thank's Larry . canonical way .. basics by examples .. compiler vs interpreter pvb265 0 500 1000 1500 2000 2500 3000 00.02.00 00.44.00 01.26.00 02.08.00 02.50.00 03.32.00 04.14.00 04.56.00 05.38.00 06.20.00 07.02.00 07.44.00 08.26.00 09.08.00 09.50.00 10.32.00 11.14.00 11.56.00 12.38.00 13.20.00 14.02.00 14.44.00 15.26.00 16.08.00 16.50.00 17.32.00 18.14.00 18.56.00 ….back to the original problem 19.38.00 20.20.00 21.02.00 21.44.00 22.26.00 23.08.00 23.50.00 req needs that lead to the camel LD12
  • 82. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples ggi-reporter is more than a project in Perl .. not to do . thank's Larry ld12 - imolug pvb265
  • 83. a genda needs that lead to the camel LD12 . scenario . canonical way . faster way .. perl genesis .. compiler vs interpreter .. basics by examples .. not to do Question Time . thank's Larry Valerio Balbi @pvb265 http://www.valeriobalbi.eu skype:pvb265 valerio.balbi@gmail.com Bologna - scienze dell'Informazione 1998 Coofounder ImoLUG senior sysadm sysadm security banking e-commerce ld12 - imolug pvb265