Wednesday 10 August 2022

perl selenium automation complete tutorial with code examples

First, we need to install the Selenium WebDriver for Perl, which can be done using the CPAN command:

cpan Selenium::WebDriver

Once the installation is done, you can start writing the code. Here's an example of how to use Perl Selenium to navigate to a website and perform a search:

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