My Perl Notes

Usefull bits of Perl Code. I keep forgeting the syntax- hence this page..
  • Files
  • Strings
  • Associative Arrays
  • If Statement
  • Formatted Reports
  • Subroutines
  • Misc Stuff

  • Files

    Open Commands Simple Read Loop Printing to a file
    open(OUT_FILE,">output.txt");    # Open for output (create)
    print OUT_FILE "Hi There!\n";
    
    Specifying File to open for input on the command line Examining all files in a directory

    Strings

    String Concatenation
    $string1 = "Hi " . "There!";
    
    Testing if a string contains a sub string Search, and Replace on a String Change String to all upper, or lower case Finding First occurence of sub string in string Grabbing a sub-string from a string Splitting Strings by a character

    Associative Arrays

    Keeping a running count of the times a string is equal to a certain value Looping thru an Associative Array, and examining each value Looping thru an Associative Array, and assigning each key to a variable Print the keys of a Associative Array in sorted order Testing if a Associative Array has a key/value

    IF Statement

    IF statement

    Reports

    Print a formatted print line-

    Subroutines

    Calling Sub-rtn, and passing variables

    Misc Stuff

    Executing shell commands
    exec "pwd";
    
    Reading whats in STDIN Current System Date, and time
    Back to My Perl CGI Information Page