Leaded

Perl Tutorial

Nov 24th, 2016
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 5.25 KB | None | 0 0
  1. #######################################################
  2. # +-------------------------------------------------+ #
  3. # |             Welcome to my perl class            | #
  4. # |                                                 | #
  5. # | I will be showing you some different codes for  | #
  6. # | perl so you can get a understanding on how it   | #
  7. # | works so you can created your own projects.     | #
  8. # | If you have any Bugs, feel free to message me   | #
  9. # | on my social media accounts!                    | #
  10. # |                                                 | #
  11. # |                [!] E N J O Y [!]                | #
  12. # +-------------------------------------------------+ #
  13. #######################################################
  14. #
  15. #   If you have any bugs with my code, feel free to  
  16. #   message me on my social media accounts!
  17. #
  18. #   Twitter : @uncombed
  19. #   Kik.... : @indurent
  20. #
  21. #######################################################
  22. #
  23. # ANSI Color Codes - http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
  24. #
  25. #######################################################
  26. # [+] Learning [+]
  27.  
  28.      #!/usr/bin/perl <-- (Define that the file is perl, put this at line "1")
  29.      
  30.      print ""; #<-- (Sends a message to the terminal)
  31.          #Example:
  32.              print "Hello and welcome new one";
  33.              print "Hi \n" #<-- '\n' breaks the line for a new line
  34.      #Print with color
  35.          #Example
  36.              print "\e[1;32m Hello";
  37.      
  38.      chomp (<string>); #<-- (This function returns Integer, number of bytes removed for all strings)
  39.          #Example:
  40.              $string1 = "This is test";
  41.              $retval  = chomp( $string1 );
  42.  
  43.              print " Chopped String is : $string1\n";
  44.              print " Number of characters removed : $retval\n";
  45.  
  46.      #Strings:
  47.          my $string #<-- (Based of defining a value to be used later on)
  48.  
  49.          #Example:
  50.             my $string2 = "Welcome";
  51.             print $string2;
  52.          
  53.  
  54. ##########################################
  55. ##########################################
  56. ##########################################
  57. # [+] Code 1 without ARGS
  58.  
  59.     #!/usr/bin/perl
  60.  
  61.     system("clear");
  62.     print " \n";
  63.     print "\e[0;36m Age re\n";
  64.  
  65.     print "\e[0;37m[\e[1;31m!\e[0;37m] Your name: ";
  66.     $name=<STDIN>;
  67.     chomp $name;
  68.  
  69.     print "\n";
  70.     print "\e[0;37m[\e[1;32m+\e[0;37m] Your age: ";
  71.     $age=<STDIN>;
  72.     chomp($age);
  73.     print "\n\n Hello $name, it's nice to see you're $age";
  74.  
  75. #-----------------------------------------
  76.  
  77.     #Commands
  78.     #Example: perl (yourscript.pl)
  79.     #Example: perl test.pl
  80.  
  81. ##########################################
  82. ##########################################
  83. ##########################################
  84. # [+] Code 1 with ARGS
  85.  
  86.     #!/usr/bin/perl
  87.  
  88.     #Defines the arguments
  89.     my $name = "$ARGV[0]";
  90.     my $age = "$ARGV[1]";
  91.  
  92.     #Defines the messages
  93.     system("clear");
  94.     print " \n";
  95.     print "\e[0;36m Age re\n";
  96.     print "\n\n Hello $name, it's nice to see you're $age";
  97. #-----------------------------------------
  98.  
  99.     #Commands
  100.     #Example: perl (yourscript.pl) <name> <age>
  101.     #Example: perl test.pl Bob 31
  102.  
  103. ##########################################
  104. ##########################################
  105. ##########################################
  106. # [+] Code 1 with GREP without ARGS for files
  107.  
  108.     #!/usr/bin/perl
  109.  
  110.     #Defines the messages
  111.     system("clear");
  112.     print " \n";
  113.     print "\e[0;36m Age re\n";
  114.     print "\e[0;37m[\e[1;31m!\e[0;37m] Your name: ";
  115.     $name=<STDIN>;
  116.     chomp $name;
  117.  
  118.     #Defines if the file exists
  119.     if ( !-e $name) {
  120.         #Otherwise end the process
  121.         die "\e[37;1m[\e[32;1m+\e[37;1m] \e[1;31;1mCRITICAL! Name file does not seem to exist : $name\e[0m\n";
  122.     }
  123.  
  124.     #Defines the messages
  125.     print "\n";
  126.     print "\e[0;37m[\e[1;32m+\e[0;37m] Your age: ";
  127.     $age=<STDIN>;
  128.     chomp($age);
  129.  
  130.     #Defines if the file exists
  131.     if ( !-e $age) {
  132.         #Otherwise end the process
  133.         die "\e[37;1m[\e[32;1m+\e[37;1m] \e[1;31;1mCRITICAL! Age file does not seem to exist : $age\e[0m\n";
  134.     }
  135.     print "\n\n Hello $name, it's nice to see you're $age";
  136.  
  137. #-----------------------------------------
  138.  
  139.     #Commands
  140.     #Example: perl test.pl
  141.  
  142. ##########################################
  143. ##########################################
  144. ##########################################
  145. # [+] Code 1 with GREP with ARGS for files
  146.  
  147.     #!/usr/bin/perl
  148.  
  149.     #Defines the arguments
  150.     my $name = "$ARGV[0]";
  151.     my $age = "$ARGV[1]";
  152.  
  153.     #Defines if the file exists
  154.     if ( !-e $name) {
  155.         #Otherwise end the process
  156.         die "\e[37;1m[\e[32;1m+\e[37;1m] \e[1;31;1mCRITICAL! Name file does not seem to exist : $name\e[0m\n";
  157.     }
  158.  
  159.     #Defines if the file exists
  160.     if ( !-e $age) {
  161.         #Otherwise end the process
  162.         die "\e[37;1m[\e[32;1m+\e[37;1m] \e[1;31;1mCRITICAL! Age file does not seem to exist : $age\e[0m\n";
  163.     }
  164.  
  165.     print "\n\n Hello $name, it's nice to see you're $age";
  166.  
  167. #-----------------------------------------
  168.  
  169.     #Commands
  170.     #Example: perl (yourscript.pl) <name(file_type)> <age(file_type)>
  171.     #Example: perl test.pl username.txt age.txt
  172.  
  173. ##########################################
  174. ##########################################
  175. ##########################################
Add Comment
Please, Sign In to add comment