Monday 21 November 2022

Understanding Differences in Behavior of Process.join() in Windows 10 and Ubuntu 18.04 in Python 3.6

When it comes to multi-processing in Python, developers often run into differences in behavior between different operating systems. One such difference is in how Windows 10 and Ubuntu 18.04 handle the Process.join() function. In this article, we will explore this difference in behavior and understand what accounts for it.

Read more »

Labels: , ,

Saturday 5 October 2019

how many ways string concatenation in perl?

Method 1:

$v='a';
print "$v$v$v";


Method 2:

print "a"."string"."c";


Method 3:

$v='a';
print "a".$v."c";


Method 4:

$v='a';
print "$v".$v.$v;


Method 5:

$v='a';
print  join "", "/home/$v.txt";


Method 6:

$v='a';
print  join "", "/home/".a.".txt";


Method 7:

$v='a';
print  join "", "/home/$v.txt";


Method 8:

$v='a';
print  join "", "/home/${v}.txt";


Method 9:

print join('', 'AA',$var1, 'BB', $var2, 'CC');


Method 10:

print sprintf("%sAA%sBB%sCC%s", $var1, $var2);


Method 11:

$s .= $_ for ($v,$v,$v);
print $s;


Method 12:

@vars = ($v,$v,$v);
print join "",@vars;


Method 13:

push @str, $v, $v, $v;
print join '', @str;


Method 14:

@var = ($v,$v,$v);
$s = "@var";
print $s;


Method 15:

undef $";
print "@{[$v,$v,$v]}";


Method 16:

$v='a';
print join(' AA ',sprintf("%s%s", $v, $v),sprintf("%s%s", $v, $v),sprintf("%s%s", $v, $v));




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

Thursday 21 October 2021

write 1000 uniq perl interview questions and answers to master in perl part 2

 251. Q: In Perl, how can you find the position of a substring within a string?

1A: In Perl, you can find the position of a substring within a string by using the `index` function. Here is an example: 2 3```perl 4use strict; 5use warnings; 6 7my $string = 'Hello, World! World is beautiful.'; 8my $substring = 'World'; 9 10my $position = index $string, $substring; 11 12if ($position == -1) { 13 print "The substring was not found in the string.\n"; 14} else { 15 print "The substring was found at position: $position\n"; 16} 17``` 18 19In this example, the script finds the position of the substring `'World'` within the string `'Hello, World! World is beautiful.'` and prints the resulting position.

Read more »

Labels:

Friday 5 August 2022

Given the input string 'hello boss!,where are you?,"how, are you!",hi,"di chellam","welcome"' our objective is to design a Perl program that intelligently separates and extracts each individual word from the CSV-like structure. The complexity lies in correctly handling quoted content containing commas.

CODE:

use strict;
use warnings;
my $input_string = 'hello boss!,where are you?,"how, are you!",hi,"di chellam","welcome"';

# Initialize empty array to store extracted words
my @words = ();

# Use a while loop with a regex to extract words
while ($input_string =~ /((?:(?<=,)|^)\s*"[^"]*"\s*(?=,|$)|[^,]*),?/g) {
    my $word = $1;
    # Remove leading and trailing spaces
    $word =~ s/^\s+|\s+$//g;\
    # Check if the word is quoted

    if ($word =~ /^\"(.*)\"$/) {
        # Extract the word without the quotes
        my $quoted_word = $1;
        # Add the word to the array
        push @words, $quoted_word;
    } else {
        # Add the word to the array
        push @words, $word;
    }
}

# Print the extracted words
print join("\n", @words), "\n";
Read more »

Labels: ,

Wednesday 22 April 2020

Python code to remove blank lines and duplicate whitespaces

This Python program is a simple yet powerful code snippet that removes blank lines and duplicate whitespaces from a given text file. The program reads a file named "filename" and removes any blank lines in the file. It also removes any duplicate whitespaces that may exist in the file. The final result is written back to the same file, overwriting the original contents. This program can be extremely useful for anyone working with text files, especially when it comes to cleaning up the contents of the file for further processing or analysis.

Read more »

Labels: ,

Friday 18 June 2021

Top 5000 python programs examples with solutions - Part 3

Program 21:

How to write  a program to calculate negative numbers in a list?

list=[1,2,3,4,5,-1,-2,-3,-4,-8]
if 0 not in list:
    list.append(0)
list=sorted(list)
pos=list.index(0)
print(pos)

Read more »

Labels:

Saturday 11 February 2023

python quick guide - python tutorial - python cheat sheet


Basic syntax

  • Variables: x = 5, y = "hello"
  • Comments: # This is a comment
  • Printing output: print("hello world")
  • User input: name = input("What is your name? ")
  • If statement:

 if x > 10:

    print("x is greater than 10")

elif x == 10:

    print("x is equal to 10")

else:

    print("x is less than 10")

Read more »

Labels:

Thursday 12 October 2023

Unlock the Power of Python with These Top Learning Resources

Are you eager to learn Python but unsure where to start? Look no further! In this article, we'll guide you through some of the best resources available online to help you master Python programming. Whether you're a beginner or looking to advance your skills, we've got you covered with our carefully curated list of free and certified courses. Let's dive in!

Read more »

Labels: