Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #######################################################
- # +-------------------------------------------------+ #
- # | Welcome to my perl class | #
- # | | #
- # | I will be showing you some different codes for | #
- # | perl so you can get a understanding on how it | #
- # | works so you can created your own projects. | #
- # | If you have any Bugs, feel free to message me | #
- # | on my social media accounts! | #
- # | | #
- # | [!] E N J O Y [!] | #
- # +-------------------------------------------------+ #
- #######################################################
- #
- # If you have any bugs with my code, feel free to
- # message me on my social media accounts!
- #
- # Twitter : @uncombed
- # Kik.... : @indurent
- #
- #######################################################
- #
- # ANSI Color Codes - http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
- #
- #######################################################
- # [+] Learning [+]
- #!/usr/bin/perl <-- (Define that the file is perl, put this at line "1")
- print ""; #<-- (Sends a message to the terminal)
- #Example:
- print "Hello and welcome new one";
- print "Hi \n" #<-- '\n' breaks the line for a new line
- #Print with color
- #Example
- print "\e[1;32m Hello";
- chomp (<string>); #<-- (This function returns Integer, number of bytes removed for all strings)
- #Example:
- $string1 = "This is test";
- $retval = chomp( $string1 );
- print " Chopped String is : $string1\n";
- print " Number of characters removed : $retval\n";
- #Strings:
- my $string #<-- (Based of defining a value to be used later on)
- #Example:
- my $string2 = "Welcome";
- print $string2;
- ##########################################
- ##########################################
- ##########################################
- # [+] Code 1 without ARGS
- #!/usr/bin/perl
- system("clear");
- print " \n";
- print "\e[0;36m Age re\n";
- print "\e[0;37m[\e[1;31m!\e[0;37m] Your name: ";
- $name=<STDIN>;
- chomp $name;
- print "\n";
- print "\e[0;37m[\e[1;32m+\e[0;37m] Your age: ";
- $age=<STDIN>;
- chomp($age);
- print "\n\n Hello $name, it's nice to see you're $age";
- #-----------------------------------------
- #Commands
- #Example: perl (yourscript.pl)
- #Example: perl test.pl
- ##########################################
- ##########################################
- ##########################################
- # [+] Code 1 with ARGS
- #!/usr/bin/perl
- #Defines the arguments
- my $name = "$ARGV[0]";
- my $age = "$ARGV[1]";
- #Defines the messages
- system("clear");
- print " \n";
- print "\e[0;36m Age re\n";
- print "\n\n Hello $name, it's nice to see you're $age";
- #-----------------------------------------
- #Commands
- #Example: perl (yourscript.pl) <name> <age>
- #Example: perl test.pl Bob 31
- ##########################################
- ##########################################
- ##########################################
- # [+] Code 1 with GREP without ARGS for files
- #!/usr/bin/perl
- #Defines the messages
- system("clear");
- print " \n";
- print "\e[0;36m Age re\n";
- print "\e[0;37m[\e[1;31m!\e[0;37m] Your name: ";
- $name=<STDIN>;
- chomp $name;
- #Defines if the file exists
- if ( !-e $name) {
- #Otherwise end the process
- 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";
- }
- #Defines the messages
- print "\n";
- print "\e[0;37m[\e[1;32m+\e[0;37m] Your age: ";
- $age=<STDIN>;
- chomp($age);
- #Defines if the file exists
- if ( !-e $age) {
- #Otherwise end the process
- 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";
- }
- print "\n\n Hello $name, it's nice to see you're $age";
- #-----------------------------------------
- #Commands
- #Example: perl test.pl
- ##########################################
- ##########################################
- ##########################################
- # [+] Code 1 with GREP with ARGS for files
- #!/usr/bin/perl
- #Defines the arguments
- my $name = "$ARGV[0]";
- my $age = "$ARGV[1]";
- #Defines if the file exists
- if ( !-e $name) {
- #Otherwise end the process
- 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";
- }
- #Defines if the file exists
- if ( !-e $age) {
- #Otherwise end the process
- 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";
- }
- print "\n\n Hello $name, it's nice to see you're $age";
- #-----------------------------------------
- #Commands
- #Example: perl (yourscript.pl) <name(file_type)> <age(file_type)>
- #Example: perl test.pl username.txt age.txt
- ##########################################
- ##########################################
- ##########################################
Add Comment
Please, Sign In to add comment