in reply to Re^2: Access a global variable from a subroutine when used as "for" iterator
in thread Access a global variable from a subroutine when used as "for" iterator
I suspect the author of that site may not have English as their first language either. In itself that is not any sort of issue. However the site has very worrying omissions that could cause rather unhappy days. For example the mentions of sigils ('$', '@', '%' ...) are in relation to variables, but that is misleading. Sigils are used to denote the type of a result so when they are used with variables they denote the type the of the variable in an expression. So far so good, but consider:
my @array = (1 .. 5); my $arrayRef = \@array; say "$arrayRef: @$arrayRef";
which prints for me (your result will be different):
ARRAY(0x7bc278): 1 2 3 4 5In the say @ returns the contents of the scalar variable arrayRef as an array.
The much worse omission is that context plays a vital part in understanding what many Perl statements mean. Context seems not to be mentioned at all by the site. Consider:
my @array = (1, 2, 3, 4, 5); my $count = (1, 2, 3, 4, 5); say "$count: @array";
which prints (the first three lines are warnings btw):
Useless use of a constant (2) in void context at D:\Scratch~~\PerlScra +tch\noname.pl line 6. Useless use of a constant (3) in void context at D:\Scratch~~\PerlScra +tch\noname.pl line 6. Useless use of a constant (4) in void context at D:\Scratch~~\PerlScra +tch\noname.pl line 6. 5: 1 2 3 4 5
The site is a nice light weight introduction to Perl, but it misses important concepts and is somewhat dated. For example it discusses the "given statement" which is now deprecated and will be removed in future versions of Perl. Treat the material on the site with caution!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Access a global variable from a subroutine when used as "for" iterator
by choroba (Cardinal) on Dec 22, 2023 at 16:23 UTC | |
by LanX (Saint) on Dec 22, 2023 at 17:53 UTC | |
by choroba (Cardinal) on Dec 22, 2023 at 18:11 UTC | |
by LanX (Saint) on Dec 23, 2023 at 02:02 UTC |