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:

Thursday 28 October 2021

Top 500 unique perl programming interview questions and answers to master in perl regular expression programs - part1

 

  1. How can I remove leading and trailing white spaces from a string in Perl?
perl
1$str = " Hello World! "; 2$str =~ s/^\s+|\s+$//g; 3print $str; # Output: "Hello World!"
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:

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: ,

Saturday 14 January 2023

Perl Interview Questions and Answers - March 2023 Updated

John","Smith", 9999 9999, "42,  some street, some area", "bangalore",560038

in above strings "9999 9999" should be single string and "42,  some street, some area" should be single string and 560038 should be single string remaining separate variables write perl program in multiple methods

Sure, here are three different methods to accomplish the task:

Read more »

Labels:

Sunday 9 January 2022

Perl - secure web services using Output encoding

Output encoding is an important security measure that helps prevent cross-site scripting (XSS) attacks by encoding special characters in output data before it is sent to the client. Here's an example code snippet that demonstrates how to implement output encoding in Perl using the HTML::Entities module:

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 17 March 2022

how to atomically update values in a ConcurrentHashMap in Java using Compute and ComputeIfAbsent methods?

Hi,  ConcurrentHashMap is a thread-safe implementation of the Java Map interface, designed to be used in multi-threaded environments. It allows multiple threads to access and modify the map simultaneously without causing data corruption or race conditions.

One of the key features of ConcurrentHashMap is that it provides atomic operations to update its elements. Atomic operations are operations that are performed as a single, indivisible unit of work, which means they are guaranteed to be executed completely or not at all. This is important in multi-threaded environments where multiple threads may try to modify the same element at the same time.

Read more »

Labels: , ,