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:

Tuesday 7 March 2023

Perl Code for Gmail Validator



To validate a Gmail address using regular expressions in Perl, you can use the following code:


#!/usr/bin/perl

use strict;

use warnings;

sub is_valid_gmail {

    my $email = shift;

    # Regular expression pattern for Gmail address validation

    my $pattern = qr/^[a-zA-Z0-9._%+-]+@gmail\.com$/;

    if ($email =~ $pattern) {

        return 1;  # Valid Gmail address

    } else {

        return 0;  # Invalid Gmail address

    }

}

# Testing the function

my $email1 = 'example@gmail.com';

my $email2 = 'invalid_email@gmail.com';


if (is_valid_gmail($email1)) {

    print "$email1 is a valid Gmail address\n";

} else {

    print "$email1 is not a valid Gmail address\n";

}


if (is_valid_gmail($email2)) {

    print "$email2 is a valid Gmail address\n";

} else {

    print "$email2 is not a valid Gmail address\n";

}


This code defines a Perl subroutine is_valid_gmail that takes an email address as input and checks if it is a valid Gmail address. The regular expression pattern ^[a-zA-Z0-9._%+-]+@gmail\.com$ is used to match the email address against the Gmail format.

To test the function, two email addresses are provided: example@gmail.com and invalid_email@gmail.com. The function is called for each email address, and the result is printed to the console.

Please note that this code only validates the format of the email address and checks if it ends with @gmail.com. It does not verify if the email address actually exists or is currently in use.

Labels:

Tuesday 16 January 2024

Login System using perl catalyst MVC



1.install the required Below dependencies:

cpanm --installdeps .

Read more »

Labels:

Friday 6 September 2019

How to set Default value for a subroutine argument and how many ways we can do it?

subroutines variable may have more than one number of arguments, some arguments may get missing values,  providing default values for arguments is mandatory.

Method1:

           sub add
           {
               ($v1,$v2)=@_;
               $v2 ||=1;
           }


Method2:

          sub add
          {
               ($v1,$v2)=@_;
               if(!defined $v2)
               {
                   $v2=1;
               }
          }

Method3:

         sub add
         {
               $v1=shift @_;
               if($#_  >  0){
                   $v2=@_[1];
               }
               else
               {
                   $v2=1;
               }

Tuesday 3 September 2019

How to get current subroutine name in Perl and ways to do it?



Method 1:
   
             print __LINE__;


Method 2:

     By Using caller() function:

              my $sub_name = (caller(0))[3];


Method 3:

     By Using Sub::Identify Module:
   
             print __SUB__ ;


kaavannan perl blogspot

Labels: ,

Wednesday 4 September 2019

How many ways to return values in perl subroutine?

Method1:

        sub A
        {
              ($a,$b)=@_;
              return $a+$b;
        }
$B=A(1,2);


Method 2:

       sub A
        {
              ($a,$b)=@_;
              return $a,$b;
        }
$B=A(1,2);


Method 3:

       sub A
        {
              return @_;
        }
@B=A(@a);


Method 4:

       sub A
        {
              return  %H;
        }

%Hash = A;