3 ms·
The defaults in Perl, especially the default variable. (For those not familiar: $_ is the default variable in Perl. Many operations use this variable if you
by AnimalMuppet 8y ago
The defaults in Perl, especially the default variable.
(For those not familiar: $_ is the default variable in Perl. Many operations use this variable if you don't specify one. You can use $_ like "it" in English: "Read in a line of input. If it ends in a newline..." In most languages, you would have to deal with "Read it into where?" and "If what ends in a newline?" But in Perl, if you don't specify where to read the line to, it goes into $_, and if you don't specify what you want to see if it ends in a newline, it checks $_, and so on...)
- ramses0 8y agoThis is worth a bit of explanation, see this link and the code duplicated below: https://perlmaven.com/the-default-variable-of-perl https://perlmaven.com/the-default-variable-of-perl I agree with most everything the author says, along with the idea that you shouldn't use it that often. ---------- use strict; use warnings; use v5.10; while ($_ = <STDIN>) { chomp $_; if ($_ =~ /MATCH/) { say $_; } } ---------- use strict; use warnings; use v5.10; while (<STDIN>) { chomp; if (/MATCH/) { say; } }
- deleted 8y ago[deleted]