How can I find the version of an installed Perl module?
Most modules (especially ones from The CPAN) have a $VERSION variable: perl -MSome::Module -le ‘print $Some::Module::VERSION’
Most modules (especially ones from The CPAN) have a $VERSION variable: perl -MSome::Module -le ‘print $Some::Module::VERSION’
ref(): Perl provides the ref() function so that you can check the reference type before dereferencing a reference… By using the ref() function you can protect program code that dereferences variables from producing errors when the wrong type of reference is used…
You can use Devel::StackTrace. use Devel::StackTrace; my $trace = Devel::StackTrace->new; print $trace->as_string; # like carp It behaves like Carp’s trace, but you can get more control over the frames. The one problem is that references are stringified and if a referenced value changes, you won’t see it. However, you could whip up some stuff with … Read more
shift() is a built in Perl subroutine that takes an array as an argument, then returns and deletes the first item in that array. It is common practice to obtain all parameters passed into a subroutine with shift calls. For example, say you have a subroutine foo that takes three arguments. One way to get … Read more
Most likely it means that the open didn’t fail. When Perl opens a file, it checks whether or not the file is a TTY (so that it can answer the -T $fh filetest operator) by issuing the TCGETS ioctl against it. If the file is a regular file and not a tty, the ioctl fails … Read more
perldoc perlvar is the first place to check for any special-named Perl variable info. Quoting: @_: Within a subroutine the array @_ contains the parameters passed to that subroutine. More details can be found in perldoc perlsub (Perl subroutines) linked from the perlvar: Any arguments passed in show up in the array @_ . Therefore, … Read more
The flip-flop operator is useful for skipping the first iteration when looping through the records (usually lines) returned by a file handle, without using a flag variable: while(<$fh>) { next if 1..1; # skip first record … } Run perldoc perlop and search for “flip-flop” for more information and examples.
Oh, I found it. You use last instead of break for my $entry (@array){ if ($string eq “text”){ last; } }
Note Code added to the question demostrates why autovivification doesn’t happen. Short Your sub takes a list (hash) which has an anonymous array as an element – and %$headers is buried in that array. It is the anon array that is the scalar aliased to, thus there is no requirement for %$headers to … Read more
Several points: You aren’t talking about typeglobs, you are talking about symbolic references. Don’t use symbolic references — they lead to hard to track down bugs. In almost any case where symbolic references seem like a good idea, using a data structure based on a hash is the best approach. Consider using Hash::Util to lock … Read more