Updated April 4, 2023
Introduction to Perl qw
The Perl qw is defined as one of the operators is used to extract the datas that are the user input for each set of elements. It should be the string formats, and it is stored as the array in the memory like an array of elements with using some notations like single-quote notation. If we used this notation in the script, then the given user input as the defined and equivalent to each set of words in the string characters before that, the input may be the set of the sentence, and it goes to some lines, but when we use this operator, the sentence may be converted into each set of strings.
Syntax
The Perl has some default set of operators that are being used for a set of operations to be performed after the script code execution. Likewise, the qw() is the operator and the function which has been used to split the sentence into each string by using some delimiters like single quotes, parentheses, etc. Mainly it returns the array of the elements as the list values.
@array = qw(some sentences based on the users input);
Loop used for to iterate the values $variable (@array)
{
--some script codes logics---
}
The above codes are the basic syntax for utilizing the qw() operators in the script. We can use any set of delimiters while we are passing the inputs to the method.
How does qw function in Perl?
The qw operator in Perl used to split the sentences that the user inputs may be the n number of lines they giving the input to the script. So it’s difficult to perform the operations in the script for storing and retrieving the datas from memory. Using delimiters, we can split the strings in various ways, but the string characters are split and equivalent to the corresponding user input values. The qw is the quote word that is related to the other operators like qq and q.
The user input datas are stored as the elements of the array because the list is the ordered set of collections using scalar type input variables and values, and the arrays are the variables that held to the lists in the Perl codes. We can extract every array element in the string datatype values; it may be out of scope in the list using some delimiters like space, commas, quotes, backslash, forward slash, etc. These are some default delimiters available in the Perl scripts. For each Perl script functions, the operators are assigned to the variable values using some default loops; the values are iterated and displayed on the output screens.
The user input as sometimes list formats the list is the set of sequence scalar values it can be used and delimiters the datas using parenthesis and comma operators. By using these operators, the list is to be constructed and also each value of the list is known as the list elements; these elements are to be some sorting type of ordered with indexed values. These values are to be set and allotted with some storage positions in the memory. Quote function uses the embedded type of whitespaces. If we use non-alphanumeric characters in the strings, we use the q/ and q// operators as delimiters; the list is any type which they have used in the elements.
Each set of list elements are stored at a specific position in the memory list. The range set of operators is performed using these functions not only for the strings; by using the qw; we can avoid the quote marks. We entered the datas less in the list we use a punctuation set of characters as the delimiters in the array variables. Whenever the delimiters used, the opening and closing parenthesis are must be the same in the array elements.
Examples of Perl qw
Here are the following examples mention below
Example #1
Code:
#!/usr/bin/perl
use warnings;
use strict;
my @months = qw(Dec Nov Oct Aug July June May Apr Mar Feb Jan);
$months[0] = 'June';
@months[1..6] = qw(December November October August July June May April March February January);
print("@months","\n");
my @var = qw(dacNovdjbnmOctsndmAugdjcnJulyjsbcJunsdbcnmdjkscmn873Madsy5sdsf4Aprdc349Mar8457FebjfdbvJan);
my @var1 = sort @var;
print("@var1","\n");
my @first = qw(Welcome To My DOmain kdjhv hkdsjbjkfw qwdkhefj90898 iwidhfkjbdfkdh qwdjehfkdbj o qhkwdbjfqwljdk qwhkdbjvjn wqdljkhfjb qwkjefdb qwjkdhbf qwkdhfjbdf wqihkewfj 2oiewhlfkj iwqehwfgkjdb eihwfjfb ewihfugejdv owhefb oiewhkbd qwdhksjb qiowhew);
my @second = sort @first;
print("@second","\n");
Output:
Example #2
Code:
#!/usr/bin/perl
use warnings;
use strict;
my @expn=();
@expn = ('12', '763', '127344', '73784','629387867', '23784', '82347', '346c', '73', '387', '83', '8374r', '83', '467', '837', '874', '93897', '3748', '784', '93');
@expn = qw/12 763 127344 73784 629387867 23784 82347 346c 73 387 83 8374r 83 467 837 874 93897 3748 784 93/;
my %vars = ();
%vars = qw(54 ghsd shd shadv 75 jgsdh wdusjh 7365 2983675 923867r 293867 gewkjd 239874 isudgh2 293874 sdg 2937846 2398 sdfjgh 238974 sdfygh);
while (my ($keys, $values) = each %vars) {
print "Your values are iterated using these formats $keys=>$values\n"
}
Output:
Example #3
Code:
#!/usr/local/bin/perl
use strict;
use warnings;
my %example = ();
%example = qw(
1 718253
6253 welcome To My Domain kjagdsvj j kqwdbvwjkdfd lwjekfjwekjlfwekljf helfkjvwekjfhkwerhrfj kwejf kehgf wekrjg ewkhrjgh ewiiurh erjh 298 98 9028 928 cguh 2983
2763 jqwhevg 728365 28937 wdghe 298376 sdhgc 2837we sjdhg 3847 siudy 23847re6 sdedf 237eyr wdjh 23847r ewuy23 3847 weduf233 384 sjd qiwh 987 kjh 978 kjwqegh 786
);
foreach my $var (sort keys %example) {
print " have a nice day users $var=>$example{$var}\n";
}
Output:
In the above three examples, we used the qw() operator with different scenarios; we can use the operator using some methods like sorting, unsorting, slicing the elements in the both array and list of the script.
Conclusion
In Perl scripts, we used different operators, keywords, variables, and functions to create the applications using text manipulations, data securities, other IT, System-related issues, Web development, and network programming concepts. In that programming concept, this operator is must be concatenated and split the huge datas using some delimiters technique.
Recommended Articles
This is a guide to Perl qw. Here we discuss How does qw function in Perl and Examples along with the codes and outputs. You may also have a look at the following articles to learn more –