How can I get a call stack listing in Perl?

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

What does shift() do in Perl?

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

“inappropriate ioctl for device”

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

What is the meaning of @_ in Perl?

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

Hidden features of Perl?

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.

How do I use symbolic references in Perl?

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