

The input value, “123456”, is valid data but an incorrect password. The input value, “fahmida,” is valid data and the correct username. The following output will appear after executing the code with the valid username but incorrect password. The input value, “secret,” is valid data and the correct password. The input value, “admin,” is invalid data. The following output will appear after executing the code with the invalid username but valid password. The input value, “1234”, is invalid data. The following output will appear after executing the code with the valid username but invalid password inputs. If ( $username eq 'fahmida' & $password eq 'secret' ) # Check the length of the $password variable # Check the length of the $username variableĭie "Password can be 6 to 12 characters long. After validating the input values, if the value of the $username is “fahmida” and the $password is “secret,” then a success message will be printed otherwise, a failure message will be printed. If the length of the $password is less than 6 and greater than 12, then the message, “Password can be 6 to 12 characters long.” will be printed. If the length of the $username is less than 6, then the message, “Username must contain 6 characters.” will be printed. The length() function has been used here to count the length of the $username and $password values. The chomp() function has been used to remove the newline from the variables. The username and the password will be taken from the user and stored in two variables, $username and $password. The following output will appear after executing the above code.Įxample-2: Count the Length of the String VariableĬreate a PERL file with the following code that will count the total number of characters of the string variable. Print "Total number of characters : $total \n" Print "The value of the scalar variable: \n" Next, the return value of the length() function has been printed. The length() function without any argument has been used to count the length of the scalar variable. The print operator has been used to print the value of the scalar variable. A string value has been stored in the scalar variable. Example-1: Count the length of the $_ variableĬreate a PERL file with the following code that will count the total number of characters of the string value stored in the scalar variable. The length() function with the argument variable will return the length of the argument variable.ĭifferent uses of the PERL script have been shown in the next part of this tutorial. The length() function without any argument will return the length of the variable, $_. The syntaxes of the length () function of PERL is given below. The uses of this function have been shown in this tutorial.” If no argument value is passed to this function, then this function will count the total characters of the scalar variable, $_. The string value is passed as the argument of the length() function, and the total number of characters is returned by this function. “The PERL length() function is used to count the total number of characters of a string.
