Pass array and scalar to a Perl subroutine [duplicate]
You need to pass it in as a reference: calc(\@array, $scalar) And then access it as: my @array = @{$_[0]};
You need to pass it in as a reference: calc(\@array, $scalar) And then access it as: my @array = @{$_[0]};
I believe the proper way to do this is to use natatime, from List::MoreUtils: from the docs: natatime BLOCK LIST Creates an array iterator, for looping over an array in chunks of $n items at a time. (n at a time, get it?). An example is probably a better explanation than I could give in … Read more
It’s normal behaviour of the language. Quoting the perlsyn manpage: The number 0, the strings ‘0’ and “”, the empty list (), and undef are all false in a boolean context. All other values are true. Negation of a true value by ! or not returns a special false value. When evaluated as a string … Read more
Install PAR::Packer from CPAN (it is free) and use pp utility.
There is no perl6, and there are many Perl 6 compilers. Perl 6 has a grammar, although it’s written in Perl 6, so as long as you can understand that, it tells you everything you need to know. I just asked Larry this question, since I’m sitting across from him at lunch at the São … Read more
The answers above are all correct, but it might come across more plainly if you understand general UNIX command line usage. It is very common to want a command to work on multiple files. E.g. ls -l *.c The command line shell (bash et al) turns this into: ls -l a.c b.c c.c … in … Read more
The __LINE__ literal is documented in the Special Literals section of the perldata man page. print “File: “, __FILE__, ” Line: “, __LINE__, “\n”; or warn(“foo”);
From ECMAScript 2018 onwards, many of JavaScript’s regex deficiencies have been fixed. It now supports lookbehind assertions, even unbounded ones. Unicode property escapes have been added. There finally is a DOTALL (/s) flag. What is still missing: JavaScript doesn’t have a way to prevent backtracking by making matches final (using possessive quantifiers ++/*+/?+ or atomic … Read more
rindex $string, $substring, 0 searches for $substring in $string at position <=0 which is only possible if $substring is a prefix of $string. Example: > rindex “abc”, “a”, 0 0 > rindex “abc”, “b”, 0 -1
require 5.013002; # or better: use Syntax::Construct qw(/r); print “bla: “, $myvar =~ s/a/b/r, “\n”; See perl5132delta: The substitution operator now supports a /r option that copies the input variable, carries out the substitution on the copy and returns the result. The original remains unmodified. my $old = ‘cat’; my $new = $old =~ s/cat/dog/r; … Read more