Sunday 8 May 2022

python private methods, how it differs with public methods best practices

In Python, private methods are methods that are intended to be used only within the class in which they are defined. Private methods are defined by prefixing the method name with two underscores (__) at the beginning of the method name.

Here is an example of a private method in Python:

class MyClass:

    def __init__(self, value):

        self.__value = value


    def __private_method(self):

        print("This is a private method.")


    def public_method(self):

        self.__private_method()


Read more »

Labels: , ,

Saturday 11 March 2023

How to Build an Authentication API with JWT Token in Perl

Hi, In many web applications, user authentication is a critical feature that allows users to securely log in and access their data. One common approach to implementing authentication is to use JSON Web Tokens (JWT), which are a type of token-based authentication that can be used across multiple domains and platforms.

In this tutorial, we will show you how to build an authentication API with JWT token in Perl. We will be using the Mojolicious web framework, which is a powerful and flexible framework that makes it easy to build web applications in Perl.

Read more »

Labels: , , ,

Wednesday 9 March 2022

what are python private variables its best practices?

Python, private variables are variables that are meant to be used only within the class in which they are defined. Private variables are defined by prefixing the variable name with two underscores (__) at the beginning of the variable name.

For example, if you have a class called Person and you want to define a private variable called __age, you would write:

class Person: def __init__(self, name, age): self.name = name self.__age = age


Read more »

Labels: , ,

Monday 13 June 2022

python @ decorators, how it differs with generators its best practices

Decorators and generators are both powerful features in Python, but they serve different purposes.

A decorator is a function that takes another function as input and returns a new function that usually modifies the behavior of the original function in some way. Decorators are commonly used for adding functionality to existing functions, such as caching, logging, or authentication.

Read more »

Labels: , ,

Friday 2 October 2020

write 1000 uniq perl interview questions and answers to master in perl - part1

  1. Q: In Perl, what does the sigil $_ represent?

    A: In Perl, the sigil $_ represents the default argument to a subroutine. It is a global variable that is set automatically by Perl whenever a subroutine is called.

  2. Q: In Perl, what does the backslash \ do in front of a variable name?

    A: In Perl, the backslash \ in front of a variable name is used to force a string interpretation of the variable, rather than a numeric interpretation. This can be useful when working with non-numeric variables, or when you want to avoid potential side effects caused by Perl's built-in operations on numbers

Read more »

Labels:

Thursday 5 September 2019

How many ways to verify Perl scalar variable is initialized or defined?


 Method1:

          if !(defined $a)
         {

         }       

Method2:

         $a = defined $a? $a : {  };

Method3:
     
          $a = "Hi" unless defined $a;          

Method4: 
         
          $a = $a || "Hi";   
          
Method5:
     
           $a ||= "Hi";     

Method6:

            if ( length( $a || '' ))
            {

             }

kaavannan perl blogspot

Labels: , , , , , ,

Wednesday 9 September 2020

perl GetOptions tutorial

Getopt::Long module in Perl to parse command line options and arguments.

Getopt::Long is a Perl module that provides a way to parse command line options and arguments in a flexible and powerful way. It supports both short and long options, as well as optional and mandatory arguments.

Here is an example code snippet that demonstrates how to use Getopt::Long:

use strict;

use warnings;

use Getopt::Long;


my $name;

my $age;

my $verbose;


GetOptions(

    "name=s"    => \$name,     # string option

    "age=i"     => \$age,      # integer option

    "verbose"   => \$verbose,  # flag option

) or die "Error in command line arguments\n";

if ($verbose) {

    print "Name: $name\n" if defined $name;

    print "Age: $age\n" if defined $age;

}


In this example, we first declare three variables $name, $age, and $verbose to hold the values of the options we will parse. We then call the GetOptions() function to parse the command line options.

The first argument to GetOptions() is an anonymous hash that defines the options we want to parse. The key is the option name, and the value is a reference to the variable that will hold the option value.

For example, the "name=s" option specifies a string option named name. The =s part tells GetOptions() to expect a string argument after the name option. The => operator assigns the value of the option to the $name variable.

Similarly, the "age=i" option specifies an integer option named age. The =i part tells GetOptions() to expect an integer argument after the age option.

The "verbose" option specifies a flag option, which does not take any argument. If the --verbose option is present on the command line, the $verbose variable will be set to a true value.

Finally, we use the $verbose variable to determine whether to print the parsed options. If $verbose is true, we print the values of $name and $age if they are defined.

The GetOptions() function returns a true value if it successfully parses the options, or false if there is an error. In this example, we use the or die syntax to print an error message and exit the script if there is an error in the command line arguments.

Example 2:


use Getopt::Long;

my $name;
my $age;

GetOptions("name=s" => \$name, "age=i" => \$age);

print "Name: $name\n";
print "Age: $age\n";

In this example, we are using GetOptions to parse command line arguments. The Getopt::Long module provides the GetOptions function which takes a list of option specifications and a reference to a hash or a variable where the options and their values will be stored.

In this example, we define two variables $name and $age that will hold the values of the name and age options respectively. We then call GetOptions with two option specifications: "name=s" and "age=i". The s and i indicate that the name option is a string and the age option is an integer.

The backslash (\) before the variables tells GetOptions to store the values in those variables. If we didn't provide the backslash, GetOptions would print the values to STDOUT and exit the script.

We can run the script with the following command:

$ perl script.pl --name "John Doe" --age 30

This will output:

Name: John Doe 
Age: 30

Note that the order of the options doesn't matter. We could have provided the --age option before the --name option and it would still work the same way.

Labels:

Tuesday 16 January 2024

Login System using perl catalyst MVC



1.install the required Below dependencies:

cpanm --installdeps .

Read more »

Labels: