Wednesday, 23 October 2019

place and plays $_ in perl?

Method 1:


while(<>)
{
    print;
}

Method 2:


for ('l','s','h','c','g')
{
   print;
   print "\n";
}

Method 3:

@a=split //,'hello';

Method 4:


$_="hello";
$_=~s/he/she/g;

print $_;

Method 5:


$_="he l lo";
for (split)
{
   print;
   print "\n";
}

Method 6:


$_='perlbot';

print if /p/;

Method 7:

foreach ('l','s','h','c','g')
{
   print;
   print "\n";
}

Method 8:


$_ = "prlbot";

print /perl/ ?'perlbot':'normalbot',"\n";

Method 9:


$_="perl";
$_=~tr/p/P/;

print $_;

Method 10:


@a=('l','s','h','c','g');

print grep $_,@a;

Method 11:


@a=('l','s','h','c','g');

print map $_,@a;

Method 12:


%hash=(1,2,7,4,9,6);

while (each %hash) {

 print "$_=$hash{$_}\n";

    }

Method 13:


opendir($_,"/tmp") || die "Can't open dir $!";

@array =readdir($_);

closedir $_;

print @array;

Method 14:

while(<>)
{
    chomp($_);
     print $_;
}

Method 15:


while(<>)
{
    chop($_);
    print $_;
}

Method 16:


while(<>)
{
   chomp($_);
   $output = eval $_;
   print $output;
}

Method 17:


$_="he l lo";

print length($_);

Method 18:


$_="he l k lo";
$v=reverse $_;

print $v;

Method 19:


$_ = 9.0;

print exp $_;

Method 20:


$_ = "10";

print hex $_;

Method 21:


$_ = "Hello Perl Bot";

print index $_, 'Perl';

Method 22:


$_="he l k lo";
$v=lc $_;

print $v;

Method 23:


$_="he l k lo";
$v=uc $_;

print $v;

Method 24:


$_="he l k lo";
$v=ucfirst $_;

print $v;

Method 25:


$_="he l k lo";
$v=lcfirst $_;

print $v;

Method 26:


$_ = "144";

print sqrt $_;

Method 27:


$_ = "Hello Perl Bot Perl";

print rindex $_, 'Perl';

Method 28:


while(($_ = getc) eq 'yes')
{
   print $_;
}

Method 29:


$_ = "Hello Perl Bot Perl";

if (defined $_) {
    print "$_ is defined";
}

Method 30:

$_ = "Hello Perl Bot Perl";

print $_;

Thursday, 31 October 2019

Perl In Line Hack - Perform Variable Assigning and Deletion in one Line

Method 1:


($_ = 'hellio') =~ s/i//;

print $_;


Method 2:


s/i// for (my $_ = 'hellio');

print $_;


Method 3:


substr(($_ = 'helloi'), index ($_, "i"), length($_),"")

print $_;


Method 4:


map $_ =~ s/i//,$_='hellio';

print $_;


Method 5:


grep $_ =~ s/i//,$_='hellio';

print $_;


Method 6:


print grep $_=~/[^i]+/,split('',$_='hellio');



Method 7:


map $_=~tr/i//d,$_="hellio";

print $_;


Method 8:


$_=~ s/i// if $_='hellio';

print $_;


Method 9:


$_ =~ tr/i//d if $_ = 'hellio';

print $_;


Method 10:


print grep $_=~/[^i]+/, @_, split '', 'hellio';


Method 11:


print grep $_=~/[^i]+/, "hellio"=~ /./g;


Method 12:


($_='hellio')=~tr/i//d;

print $_;


Method 13:


$_="hellio",$_=~tr/i//d;

print $_;


Method 14:


print @_,grep $_=~/[^i]+/, (split '', 'hellio');


Method 15:


grep $_=~tr/i//d,$_="hellio";

print $_;


kaavannan perl blogspot

Labels: , , , ,

Friday, 4 October 2019

how many types available for getting string variable length in perl?

Method 1:

my $c = map $_, $h =~ /(.)/g;


Method 2:

my $c = split '', $h;


Method 3:

my $count = () = "hello" =~ /./g;


Method 4:

print length $h;


Method 5:

$cnt = "hello" =~ tr/[a-z][A-Z][0-9]//;


Method 6:

$h='hello';
my $v=$h=~ s/[a-z]//g;


Method 7:

print  @_ = push(@_, map $_, (split '', 'hellgo'));


Method 8:

print  @_ = push(@_, grep $_, (split '', 'hellgo'));


Method 9:

print push(@_, grep $_, "hello" =~ /./g);


Method 10:

print push(@_, map $_, "hello" =~ /./g);


Method 11:

print push(@_, grep $_, reverse "hello" =~ /./g);


Method 12:

print push(@_, map $_, reverse "hello" =~ /./g);


Method 13:

print push(@_, map $_, (split '', 'hellgo'));


Method 14:


my $c = grep/./, (reverse split '', 'hello');
print $c;


Method 15:

my $c = map $_, (reverse split '', 'hello');
print $c;


Method 16:

my $c = map $_, (reverse "hello" =~ /./g);
print $c;


Method 17:

my $c = grep/./, (reverse "hello" =~ /./g);
print $c;


Method 18:

my $c = map $_, (reverse split '', 'hello');
print $c;


Method 19:

my $c = grep/./, (reverse split '', 'hello');
print $c;


Method 20:

print scalar map $_, 'hello' =~ /(.)/g;


Method 21:

print scalar grep/./,'helloh' =~ /(.)/g;


Method 22:

print scalar  map $_, (reverse "hello" =~ /./g);


Method 23:

print scalar  map $_, (reverse split '', 'hello');


Method 24:

print scalar  map $_, (split '', 'hello');


Method 25:

print $r = @_= map $_, (split '', 'hello');


Method 26:

print $r = @_= grep $_, (split '', 'hello');


Method 27:

print $r = @_= grep $_, (reverse "hello" =~ /./g);


Method 28:

print $r = @_= grep/./,'helloh' =~ /(.)/g


Method 29:

print $r = @_= map  $_, (reverse "hello" =~ /./g);


Method 30:

print $r = @_= map/./,'helloh' =~ /(.)/g


Method 31:

print $r = @_= map $_, (split '', 'hello');


Method 32:

print $r = @_= grep $_, (split '', 'hello');


Method 33:

print $r = @_= grep $_, (reverse "hello" =~ /./g);


Method 34:

print $r = @_= grep/./,'helloh' =~ /(.)/g


Method 35:

print $r = @_= map  $_, (reverse "hello" =~ /./g);


Method 36:

print $r = @_= map/./,'helloh' =~ /(.)/g


Method 37:

print scalar  map $_, (reverse split '', 'hello');


Method 38:

print length reverse  grep/./,'helloh' =~ /(.)/g;


Method 39:

print length reverse  map $_,'helloh' =~ /(.)/g;


Method 40:

print grep/./, (reverse "hello" =~ tr/[a-z][A-Z][0-9]//);


Method 41:

print map $_, (reverse "hello" =~ tr/[a-z][A-Z][0-9]// );




For More Methods Reach Me:@ letscrackperlinterviewblogspot@gmail.com  

Labels: , , , , ,

Thursday, 3 July 2025

Detecting Request Type in PHP (GET, POST, PUT, or DELETE)

When building web applications, it’s important to handle different types of HTTP requests—such as GET, POST, PUT, and DELETE. These methods are used for different operations: retrieving data, submitting forms, updating records, or deleting them. In PHP, detecting the request type is a common task, especially when creating RESTful APIs or handling complex form submissions.

Here’s a post detailing how to detect the request type in PHP and how to handle it in different ways.

1. Using $_SERVER['REQUEST_METHOD']

The most straightforward way to detect the request method in PHP is by using the $_SERVER superglobal. This variable contains server and execution environment information, including the request method.

Read more »

Labels: , , ,

Sunday, 24 November 2019

Perl - without reverse function reverse a string

Perl Reverse:
perl reverse function reverses the string which will be very useful for creating or while writing the large code. it saves the time from writing new custom functions for reverse.


Without Perl Reverse Function we can write our custom functions in Perl as below

Read more »

Labels: ,

Tuesday, 20 August 2024

Understanding the Impact of <<>> on @ARGV in Perl

You might have encountered a puzzling issue while working with Perl where you expected a deep copy of an array to be preserved, but found that modifications to @ARGV using the <<>> operator affected the original array. Here’s a breakdown of why this happens and how you can avoid such pitfalls.

Read more »

Labels:

Friday, 1 November 2019

perl - find missing numbers in array

Method 1:

@a = (1,3,4,6); @c = map $a[$_-1]+1..$a[$_]-1, 1..@a-1; print join(" ", @c);




Read more »

Labels:

Wednesday, 11 September 2019

How to print the elements of single hash in Perl without using sort builtin function in many methods?


Method 1:
                           %final=(9,2,1,4,7,6);
                           print "@{[%final]}";

Method  2:
                          %final=(9,2,1,4,7,6);
                          print %final,"\n";

Method  3:
                           %final=(9,2,1,4,7,6);
                           print "$_ $final{$_}\n" for (keys %final);

Method  4:
                           %final=(9,2,1,4,7,6);
                           while (my ($k,$v)=each %final){print "$k $v\n"}

Method  5:
                           %final=(9,2,1,4,7,6);
                           print "$_ => $final{$_}\n" for (sort keys %final);

Method  6:
                     
                          %final=(9,2,1,4,7,6);
                          @d=%final;
                           print @d;

Method  7:
                          %final=(9,2,1,4,7,6);
                          print map { "$_ $final{$_}\n" } keys %final;

Method  8:
                           %final=(9,2,1,4,7,6);
                           print map {$_ . " "} %final, "\n";

Method  9:

                           %final=(9,2,1,4,7,6);
                           foreach(keys %final) { print "$_   $final{$_}\n"; }

Method  10:
                           %final=(9,2,1,4,7,6);
                           map {print "$_  $final{$_}\n"; } keys %final;

Method 11:
                           %final=(9,2,1,4,7,6);
                           print "$_ $final{$_}\n" for keys %final;

kaavannan perl blogspot

Labels: , , , , ,