- Home
- Interview Questions
- Perl
The two types of data you can use in Perl are scalar data, for individual things such as numbers and strings and list data, for collective things such as arrays.
No,Its not possible. however, there is no real need to do so. If we want to perform several single steps at once,we can use the C command to skip ahead to a specified point. If we want to both step ahead and print the value of a variable,just use the
By default, the b command sets a breakpoint at the line that is about to be executed. This is the line at which C has set its one-time breakpoint.
Yes. Use the V command or the standard Perl package/variable syntax
Because files included by require can contain statements that are immediately executed, checking for a return code enables programs to determine whether code included by require generated any errors
pattern matching is the concept on Perl of writing a pattern which is then applied to a string or a set of data. Regular expressions are the language you use to write patterns.
There are many uses of pattern matching—you are limited only by your imagination.
A few of them include
a. Input validation
b. Counting the number of things in a string
c. Extracting data from a string based on certain criteria
d. Splitting a string into different elements
e. Replacing a specific pattern with some other string
f. Finding regular (or irregular) patterns in a data set
/ice\s*cream/
/\d\d\d/
/^\d+$/
/ab?c[,.:]d/
/xy|yz+/
/[\d\s]{2,3}/
/"[^"]"/
The answers are as follows:
a. This pattern matches the characters "ice" and "cream," separated by zero or
more whitespace characters.
b. This pattern matches three digits in a row
c. This pattern matches one or more digits on a line by themselves with no other
characters or whitespace.
d. This pattern matches ‘a', and optional 'b', a c, one of a comma, period, or colon,
and a 'd'. "ac.d" will match, as will "acb,d", but not "abcd"
e. This pattern will match either 'xy' or ‘y' with one or more 'z's.
f. This pattern will match either a digit or a whitespace character appearing at least
two but no more than three times.
g. This pattern matches all the characters in between opening and closing quotes
Backreferences and match variables are numbered based on opening parentheses. Parenthesized patterns can be nested inside each other.
Match variables are extremely transient; their values only stay set until the next pattern match or until the end of a block.