PERL

  1. What is perl -- The program extraction and report language.
  2. What features does perl have -- All of them. This is shell and C++ put together.
    1. Yes, this means every feature known to mankind (ha ha).
    2. Unlimited sized arrays, associative arrays.
    3. Object oriented
    4. Can write shorter but harder to read prorams in perl than any other language.
  3. Used for
    1. Writing useful little programs to gather stats
    2. Writing cgi-bin scripts
  4. Can invode from command line or as a perl shell script. Can even give arguments to perl from a shell script.
  5. Command line arguments
    1. -d run under the debugger
    2. -s Does some switch parsing ...
      enables some rudimentary switch parsing for switches on the
           command line after the script name but before any filename
           arguments (or before a `--').  Any switch found there is removed
           from `@ARGV' and sets the corresponding variable in the *perl*
           script.  The following script prints `true' if and only if the
           script is invoked with a `-xyz' switch.
      
                #!/usr/bin/perl -s
                if ($xyz) { print "true\n"; }
    3. -u core dump. Read the perl program, tokenize it, and them crash. Can use the undump command to make an executable of the resulting core file.
    4. -v Version
    5. -w prints warnings about identifiers that are mentioned only once, and scalar variables that are used before being set. Also warns about redefined subroutines, and references to undefined filehandles or filehandles opened readonly that you are attempting to write on. Also warns you if you use `==' on values that don't look like numbers, and if your subroutines recurse more than 100 deep.
  6. Four data types and three modes
    1. Data types are scalar, array, and associatve array, file handle
    2. All scalars start with "$", all arrays stary with "@", and all associative arrays start with "%".
    3. $a = 4 is a scalar, $a[4] is an array, and $a{"four"} is an associative array.
    4. Array length is stored in $#ArrayName
    5. File handles are conventionaly in all caps STDIN or STDOUT
    6. Command line args are given on $ARGV.
  7. Modes are 'want number',, 'want string', and 'want array.
  8. Expressions
    1. are just like "C", except you also get **, **=, ., .= , eq, ne, lt, gt, le, ge
    2. You also get -r readable, -w writeable, -x executable, -e exists, -f plane file, -T is_text_file, -d is_directory.
  9. Input/Output commands
    1. open(filehandle, ">output file name");
    2. open(filehandle, "<input file name";
    3. open (filehandle, "|command_to_write_from");
    4. open(filehandle, "command to read from |");
    5. close(filehandle);
    6. print "This goes to STDOUT";
    7. print OTHERHANDLE "a string to print";
    8. <FILEHANDLE> = $a // read one line from FILEHANDLE into $a.
  10. File commands
    1. chmod 0755, filenames // needs comma and a number, not a+r DAMN!!
    2. chown $uid, $gid, $filename
    3. stat SCALARVARIABLE
           Returns a 13-element array giving the statistics for a file,
           either the file opened via FILEHANDLE, or named by EXPR. 
           Typically used as follows:
      
                ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
                   $atime,$mtime,$ctime,$blksize,$blocks)
                       = stat($filename);
    4. unlink("filename");
  11. Compound statements
    1.      if (EXPR) BLOCK
           if (EXPR) BLOCK else BLOCK
           if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK
           while (EXPR) BLOCK
           while (EXPR) BLOCK continue BLOCK
           for (EXPR; EXPR; EXPR) BLOCK
           foreach VAR (ARRAY) BLOCK
           STATEMENT if (EXPR);