Find Interview Questions for Top Companies
Ques:- Why is it hard to call this function: sub y ?
Asked In :-
Right Answer:
It is hard to call the function `sub y` because `y` is a reserved word in Perl, used for the transliteration operator, which can lead to syntax errors or unexpected behavior.
Ques:- What is difference between “Use” and “require”. In which case should “Use” be used and not “Require”?
Asked In :-
Right Answer:
In Perl, `use` is used to include modules at compile time, while `require` includes them at runtime. You should use `use` when you want to ensure that a module is available before the program starts running, and `require` when you want to load a module conditionally or later in the execution.
Ques:- What value is returned by a lone return; statement?
Asked In :-
Right Answer:
A lone `return;` statement returns `undef`.
Ques:- Why are not Perls patterns regular expressions?
Asked In :-
Right Answer:
Perl's patterns are not regular expressions because they include additional features such as backreferences, lookaheads, and lookbehinds, which go beyond the capabilities of traditional regular expressions.
Ques:- How do I do fill_in_the_blank for each file in a directory?
Asked In :-
Right Answer:
You can use the following Perl script to fill in the blank for each file in a directory:

```perl
use strict;
use warnings;
use File::Glob ':glob';

my $directory = 'path/to/directory'; # specify your directory
my $fill_in_text = 'your text here'; # specify the text to fill in

foreach my $file (bsd_glob("$directory/*")) {
open(my $fh, '>>', $file) or die "Could not open file '$file' $!";
print $fh "$fill_in_textn";
close $fh;
}
```
Ques:- Why does Perl not have overloaded functions?
Asked In :-
Right Answer:
Perl does not have overloaded functions because it relies on dynamic typing, which makes it difficult to determine which function to call based solely on argument types at compile time. Instead, Perl uses context (scalar or list) to differentiate behavior, allowing for more flexible and dynamic code execution.
Ques:- How to Connect with SqlServer from perl and how to display database table info?
Asked In :-
Right Answer:
To connect to SQL Server from Perl and display database table information, you can use the `DBI` and `DBD::ODBC` modules. Here’s a simple example:

```perl
use DBI;

# Database connection parameters
my $dsn = "dbi:ODBC:Driver={SQL Server};Server=your_server;Database=your_database;";
my $username = "your_username";
my $password = "your_password";

# Connect to the database
my $dbh = DBI->connect($dsn, $username, $password, { RaiseError => 1, PrintError => 0 });

# Prepare and execute a query to fetch table info
my $sth = $dbh->prepare("SELECT * FROM your_table");
$sth->execute();

# Display the results
while (my @row = $sth->fetchrow_array()) {
print join(", ", @row), "n";
}

# Clean up
$sth->finish();
$dbh
Ques:- What's the significance of @ISA, @EXPORT @EXPORT_OK %EXPORT_TAGS list & hashes in a perl package? With example?
Asked In :-
Right Answer:
In Perl, `@ISA`, `@EXPORT`, `@EXPORT_OK`, and `%EXPORT_TAGS` are used in packages to manage inheritance and export symbols.

- `@ISA`: This array holds the names of parent classes for inheritance. It allows a package to inherit methods from other packages.

Example:
```perl
package Child;
use Parent;
our @ISA = qw(Parent);
```

- `@EXPORT`: This array specifies which functions or variables are automatically exported to the caller's namespace when the package is used.

Example:
```perl
package MyModule;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(func1 func2);
```

- `@EXPORT_OK`: This array lists functions or variables that can be exported on request, rather than automatically.

Example:
```perl
our @EXPORT_OK = qw(func3 func4);
```

- `%
Ques:- Explain the difference between “my” and “local” variable scope declarations. ?
Asked In :-
Right Answer:
In Perl, a `my` variable is scoped to the block in which it is declared, meaning it is only accessible within that block and its nested blocks. A `local` variable, on the other hand, temporarily overrides the value of a global variable within the block it is declared and its nested blocks, but it retains its global scope outside of that block.
Ques:- How to open and read data files with Perl
Asked In :-
Right Answer:
To open and read data files in Perl, you can use the following code:

```perl
# Open the file for reading
open(my $fh, '<', 'filename.txt') or die "Could not open file: $!";

# Read the file line by line
while (my $line = <$fh>) {
print $line; # Process the line (e.g., print it)
}

# Close the file
close($fh);
```


PERL, which stands for “Practical Extraction and Reporting Language,” is a powerful and highly versatile programming language that was initially developed for text processing and reporting. Created by Larry Wall in 1987, it has evolved into a general-purpose, interpreted language used across a wide range of applications, from system administration to web development. Despite the emergence of newer languages, PERL remains a robust and enduring tool, particularly for tasks that require rapid development and powerful text-handling capabilities.

The core strength of PERL lies in its exceptional text manipulation engine. It has a rich and highly integrated set of features for regular expressions, making it an ideal choice for tasks like parsing log files, extracting data from unstructured text, and generating reports. Its syntax is C-like, which makes it familiar to many programmers, but it also boasts unique features that allow for concise and expressive code. PERL supports both procedural and object-oriented programming paradigms, providing developers with the flexibility to choose the most suitable style for their projects.

A key feature that distinguishes PERL is the Comprehensive Perl Archive Network (CPAN). This vast repository of over 250,000 open-source modules allows developers to easily extend the language’s functionality, with modules available for virtually every task, from database connectivity and web frameworks to complex data analysis. This extensive library ecosystem has cemented PERL’s reputation as a “glue language” capable of connecting disparate systems and automating complex workflows. PERL’s applications are diverse, spanning from its traditional use in system administration and network management to its role in web development and scientific computing, making it a valuable tool for programmers and engineers in many different fields.

AmbitionBox Logo

What makes Takluu valuable for interview preparation?

1 Lakh+
Companies
6 Lakh+
Interview Questions
50K+
Job Profiles
20K+
Users