Perl subroutine arguments

You are wary of the Perl environment because it is quite different from the languages you have come across before. The people who believe in strong typing and function prototypes will disagree here, but I believe that restrictions like that are rarely useful. Has C really caught you passing the wrong number of parameters to … Read more

Perl read line by line

If you had use strict turned on, you would have found out that $++foo doesn’t make any sense. Here’s how to do it: use strict; use warnings; my $file=”SnPmaster.txt”; open my $info, $file or die “Could not open $file: $!”; while( my $line = <$info>) { print $line; last if $. == 2; } close … Read more

Why is this program valid? I was trying to create a syntax error

Perl has a syntax called “indirect method notation”. It allows Foo->new($bar) to be written as new Foo $bar So that means Syntax error ! exit 0; is the same as error->Syntax(! exit 0); or error->Syntax(!exit(0)); Not only is it valid syntax, it doesn’t result in a run-time error because the first thing executed is exit(0).

Perl Dereferencing Syntax

Whenever you can use the name of a variable, you can use a block that evaluates to a reference instead. For example, the following are valid syntax for specifying an array: @NAME # If you have the name e.g. @array @BLOCK # If you have a reference e.g. @{ $ref } This is the “circumfix … Read more

How to pass a variable from a child process (fork by Parallel::ForkManager)?

I think you’re misunderstanding what a fork does. When you successfully fork, you’re creating a subprocess, independent from the process you started with, to continue doing work. Because it’s a separate process, it has its own memory, variables, etc., even though some of these started out as copies from the parent process. So you’re setting … Read more