You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1
Original file line number
Diff line number
Diff line change
@@ -3253,6 +3253,7 @@ False
3253
3253
3254
3254
<details>
3255
3255
<summary>Explain what is GIL</summary><br><b>
3256
+
Python Global Interpreter Lock (GIL) is a type of process lock which is used by python whenever it deals with processes. Generally, Python only uses only one thread to execute the set of written statements. This means that in python only one thread will be executed at a time
Copy file name to clipboardExpand all lines: exercises/perl/README.md
+96
Original file line number
Diff line number
Diff line change
@@ -486,20 +486,116 @@ $b->printA();
486
486
```
487
487
</b></details>
488
488
489
+
### Perl Exception Handling
490
+
491
+
<details>
492
+
<summary>How can we evaluate and capture an exception in Perl?</summary><br><b>
493
+
494
+
From the official [eval docs](https://perldoc.perl.org/functions/eval):
495
+
496
+
"`eval` in all its forms is used to execute a little Perl program, trapping any errors encountered so they don't crash the calling program.".
497
+
498
+
e.g:
499
+
500
+
```
501
+
eval {
502
+
die;
503
+
};
504
+
if ($@) {
505
+
print "Error. Details: $@";
506
+
}
507
+
```
508
+
509
+
If we execute this we get the next output:
510
+
511
+
```
512
+
Error. Details: Died at eval.pl line 2.
513
+
```
514
+
515
+
The `eval` (`try` in another programming languages) is trying to execute a code. This code fails (it's a die), and then the code continues into the `if` condition that evaluates `$@` error variable have something stored. This is like a `catch` in another programming languages. At this way we can handle errors.
516
+
517
+
</b></details>
518
+
489
519
### Perl OS
490
520
491
521
<details>
492
522
<summary>What is Perl Open3?</summary><br><b>
523
+
524
+
From the official [IPC::Open3 docs](https://perldoc.perl.org/IPC::Open3):
525
+
526
+
"IPC::Open3 - open a process for reading, writing, and error handling using open3()".
527
+
528
+
With `open3` we can have the full control of the STDIN, STDOUT, STDERR. It's usually used to execute commands.
529
+
</b></details>
530
+
531
+
<details>
532
+
<summary>Using Open3: Create a file with the size of 15MB and check it's created successfully</summary><br><b>
my $result = &execute_command('stat', '-c', '%s', $file_name);
556
+
print Dumper(<$result>);
557
+
```
558
+
559
+
- Result:
560
+
561
+
```
562
+
$ -> perl command.pl
563
+
$VAR1 = '15728640
564
+
';
565
+
```
566
+
493
567
</b></details>
494
568
495
569
### Perl Packages & Modules
496
570
497
571
<details>
498
572
<summary>What is a Perl package? And a module?</summary><br><b>
573
+
574
+
With a Perl package we are defining a namespace.
575
+
A Perl module in one simple word can be defined as a `class`. When we create a `class` in Perl we use the `package` keyword. A module can be used with the `use` keyword.
499
576
</b></details>
500
577
501
578
<details>
502
579
<summary>What is the difference between .pl and .pm extensions?</summary><br><b>
580
+
581
+
There's no a real difference between a `.pm` and `.pl` extensions. Perl use `.pm` extensions just to difference it as a perl module (a class). `.pl` extensions are usually named for perl scripts without OOP classes.
582
+
583
+
</b></details>
584
+
585
+
<details>
586
+
<summary>Why a Perl class (or module) should return something at the end of the file? Check the example.</summary><br><b>
587
+
588
+
If we want to `use` a Perl module (`import` a class), this module should end in a value different than 0. This is necessary because if we try to import the class and it has a false value, we will not be able to use it.
0 commit comments