Skip to content

Commit a3bacc7

Browse files
adrianfuscoeshack94
authored andcommitted
Add new Perl questions (bregman-arie#184)
* New questions and spell check (bregman-arie#181) Added new questions related with KVM, Libvirt and DNF * New Perl questions * Change postition of topic in the table Put the perl topic at the end of the table to correct the table size
1 parent 3760057 commit a3bacc7

File tree

2 files changed

+289
-0
lines changed

2 files changed

+289
-0
lines changed

README.md

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<td align="center"><a href="#puppet"><img src="images/puppet.png" width="75px;" height="75px;" alt="puppet"/><br /><b>Puppet</b></a></td>
7575
<td align="center"><a href="#distributed"><img src="images/distributed.png" width="110px;" height="75px;" alt="Distributed"/><br /><b>Distributed</b></a></td>
7676
<td align="center"><a href="#questions-you-ask"><img src="images/you.png" width="90px;" height="75px;" alt="you"/><br /><b>Questions you can ask</b></a></td>
77+
<td align="center"><a href="#perl"><img src="images/perl.png" width="75px;" height="75px;" alt="perl"/><br /><b>Perl</b></a></td>
7778
</tr>
7879
</table>
7980
</center>
@@ -5033,6 +5034,294 @@ Output: 3
50335034
[Golang container/heap package](https://golang.org/pkg/container/heap/)
50345035
</b></details>
50355036

5037+
## Perl
5038+
5039+
### Perl Self Assessment
5040+
5041+
<details>
5042+
<summary>What is Perl?</summary><br><b>
5043+
5044+
From the official [docs](https://perldoc.perl.org/):
5045+
5046+
"Perl officially stands for Practical Extraction and Report Language, except when it doesn't."
5047+
5048+
It's a general purpose programming language developed for manipulating texts mainly. It has been used to perform system administration tasks, networking, building websites and more.
5049+
</b></details>
5050+
5051+
<details>
5052+
<summary>What data types Perl has? And how can we define it?</summary><br><b>
5053+
5054+
- Scalar: This is a simple variable that stores single data items. It can be a string, number or reference.
5055+
5056+
```
5057+
my $number = 5;
5058+
```
5059+
5060+
- Arrays: This is a list of scalars.
5061+
5062+
```
5063+
my @numbers = (1, 2, 3, 4, 5);
5064+
# or using the `qw` keyword (quote word):
5065+
my @numbers = qw/1 2 3 4 5/;
5066+
# '/' can be another symbol, e.g qw@1 2 3 4 5@
5067+
```
5068+
5069+
- Hashes (or associative arrays): This is an unordered collection of key-value pairs. We can access to a hash using the keys.
5070+
5071+
```
5072+
my %numbers = (
5073+
First => '1',
5074+
Second => '2',
5075+
Third => '3'
5076+
);
5077+
```
5078+
5079+
</b></details>
5080+
5081+
<details>
5082+
<summary>How can you access to a hash value, add and delete a key/value pair and modify a hash?</summary><br><b>
5083+
5084+
my %numbers = (
5085+
'First' => '1',
5086+
'Second' => '2',
5087+
'Third' => '3'
5088+
);
5089+
5090+
- Access:
5091+
print($numbers{'First'});
5092+
- Add:
5093+
$numbers{'Fourth'} = 4;
5094+
- Delete:
5095+
delete $numbers{'Third'};
5096+
- Modify:
5097+
$numbers{'Fifth'} = 6;
5098+
5099+
$numbers{'Fifth'} = 5;
5100+
5101+
</b></details>
5102+
5103+
<details>
5104+
<summary>How can you iterate an array? And a hash?</summary><br><b>
5105+
5106+
- Array:
5107+
5108+
```
5109+
my @numbers = qw/1 2 3 4 5/;
5110+
5111+
# Using `$_` that represents the current iteration in a loop. It starts from index array 0 until the last index.
5112+
foreach (@numbers) {
5113+
print($_);
5114+
}
5115+
# Output: 12345
5116+
5117+
5118+
# "$#" returns the max index of an array. That's the reason because we can iterate accesing to the array from the index 0 to the max index.
5119+
for my $i (0..$#numbers) {
5120+
print($numbers[$i]);
5121+
}
5122+
# Output: 12345
5123+
5124+
5125+
# Using the `map` keyword:
5126+
print map {$_} @numbers;
5127+
# Output: 12345
5128+
5129+
# Using `while`. We should take care with this option. When we use `shift` we're deleting the first element of the array and assigning it to the `element` variable.
5130+
# After this `loop` the `numbers` array will not have elements.
5131+
while (my $element = shift(@numbers)) {
5132+
print($element);
5133+
}
5134+
# Output: 12345
5135+
```
5136+
5137+
- Hashes:
5138+
5139+
```
5140+
my %capital_cities = (
5141+
'Madrid' => 'Spain',
5142+
'Rome' => 'Italy',
5143+
'Berlin' => 'Germany'
5144+
);
5145+
5146+
# Iterate and get the `keys`:
5147+
foreach my $city (keys %capital_cities) {
5148+
print($city . "\n");
5149+
}
5150+
# Iterate and get the `values`:
5151+
foreach my $country (values %capital_cities) {
5152+
print($country . "\n");
5153+
}
5154+
5155+
# Iterate and get the values and keys (first option):
5156+
foreach my $city (keys %capital_cities) {
5157+
print("City: $city - Country: $capital_cities{$city}" . "\n");
5158+
}
5159+
5160+
# Iterate and get the values and keys (first option):
5161+
while(my ($city, $country) = each %capital_cities) {
5162+
print("City: $city - Country: $capital_cities{$city}" . "\n");
5163+
}
5164+
```
5165+
5166+
</b></details>
5167+
5168+
<details>
5169+
<summary>What is a Perl subroutine? How to define it?</summary><br><b>
5170+
5171+
It's the perl model for user defined functions (this is also called function like other programming languages). We can define a subroute with the keyword `sub`.
5172+
5173+
```
5174+
sub hello {
5175+
print "hello";
5176+
}
5177+
```
5178+
5179+
</b></details>
5180+
5181+
<details>
5182+
<summary>Describe the different ways to receive parameters in a subroutine</summary><br><b>
5183+
5184+
- List assignment: Using the `@_` array. It's a list with the elements that are being passed as parameters.
5185+
5186+
```
5187+
sub power {
5188+
my ($b, $e) = @_;
5189+
return $b ** $e;
5190+
}
5191+
5192+
&power(2, 3);
5193+
```
5194+
5195+
- Individual assigment: We should access to every element of the `@_` array. It starts from zero.
5196+
5197+
```
5198+
sub power {
5199+
my $b = $_[0];
5200+
my $e = $_[1];
5201+
return $b ** $e;
5202+
}
5203+
5204+
&power(2, 3);
5205+
```
5206+
5207+
- Using `shift` keyword: It's used to remove the first value of an array and it's returned.
5208+
5209+
```
5210+
sub power {
5211+
my $b = shift;
5212+
my $3 = shift;
5213+
return $b ** $e;
5214+
}
5215+
5216+
&power(2, 3);
5217+
```
5218+
5219+
5220+
[Source](https://stackoverflow.com/a/21465275/12771230)
5221+
5222+
We can also read the best way in the same S.O answer.
5223+
5224+
</b></details>
5225+
5226+
<details>
5227+
<summary>What is lexical and dynamic scoping?</summary><br><b>
5228+
</b></details>
5229+
5230+
<details>
5231+
<summary>How to apply referencing and dereferencing?</summary><br><b>
5232+
</b></details>
5233+
5234+
<details>
5235+
<summary>Does Perl have conventions?</summary><br><b>
5236+
5237+
You can check [perlstyle](https://perldoc.perl.org/perlstyle)
5238+
5239+
</b></details>
5240+
5241+
<details>
5242+
<summary>What is Perl POD? Can you code an example?</summary><br><b>
5243+
5244+
From the official [docs](https://perldoc.perl.org/perlpod):
5245+
5246+
"Pod is a simple-to-use markup language used for writing documentation for Perl, Perl programs, and Perl modules."
5247+
5248+
```
5249+
=item
5250+
This function returns the factorial of a number.
5251+
Input: $n (number you wanna calculate).
5252+
Output: number factorial.
5253+
=cut
5254+
sub factorial {
5255+
my ($i, $result, $n) = (1, 1, shift);
5256+
$result = $result *= $i && $i++ while $i <= $n;
5257+
return $result;
5258+
}
5259+
```
5260+
5261+
</b></details>
5262+
5263+
### Perl Regex
5264+
5265+
<details>
5266+
<summary>How do you perform regular expresions in Perl?</summary><br><b>
5267+
</b></details>
5268+
5269+
### Perl Files Handle
5270+
5271+
<details>
5272+
<summary>How to write into a file?</summary><br><b>
5273+
</b></details>
5274+
5275+
### Perl OOP
5276+
5277+
<details>
5278+
<summary>Does Perl have support for OOP?</summary><br><b>
5279+
5280+
From the official [docs](https://perldoc.perl.org/perlootut):
5281+
5282+
"By default, Perl's built-in OO system is very minimal, leaving you to do most of the work."
5283+
5284+
</b></details>
5285+
5286+
<details>
5287+
<summary>What is the purpose of the bless function?</summary><br><b>
5288+
5289+
The function os the `bless` function is used to turning a plain data structure into an object.
5290+
5291+
</b></details>
5292+
5293+
<details>
5294+
<summary>Does Perl have inheritance?</summary><br><b>
5295+
</b></details>
5296+
5297+
<details>
5298+
<summary>Does Perl have polymorphism? What is method overriding?</summary><br><b>
5299+
</b></details>
5300+
5301+
### Perl OS
5302+
5303+
<details>
5304+
<summary>What is Perl Open3?</summary><br><b>
5305+
</b></details>
5306+
5307+
### Perl Packages & Modules
5308+
5309+
<details>
5310+
<summary>What is a Perl package? And a module?</summary><br><b>
5311+
</b></details>
5312+
5313+
<details>
5314+
<summary>What is the difference between .pl and .pm extensions?</summary><br><b>
5315+
</b></details>
5316+
5317+
<details>
5318+
<summary>What is cpan? And cpanm?</summary><br><b>
5319+
</b></details>
5320+
5321+
<details>
5322+
<summary>How can you install a Perl module?</summary><br><b>
5323+
</b></details>
5324+
50365325
## Mongo
50375326

50385327
<details>

images/perl.png

33.3 KB
Loading

0 commit comments

Comments
 (0)