Monthly Archives: September 2011

The caller() function and $wantarray

The argument of interest is the $wantarray argument. This indicates what return value is expected of the subroutine from where it was called. The subroutine could have been called in void context meaning the return value is thrown away. Or it could have been called and the return value assigned to a scalar. Or it… Read More »

Using the caller() Function in Subroutines

The caller() function can be used in a subroutine to find out information about where the subroutine was called from and how it was called. Caller takes one argument that indicates how far back in the call stack to get its information from. For information about the current subroutine, use caller(0). # # # sub… Read More »

Implied Arguments in perl

When calling a subroutine with the “&” sigil prefix and no parenthesis, the current @_ array gets implicitely passed to the subroutine being called. This can cause subtly odd behaviour if you are not expecting it. # # # sub second_level { print Dumper @_; } sub first_level { # using ‘&’ sigil and no… Read More »

what is meant by a ‘pack’ in perl?

Pack Converts a list into a binary representation. Takes an array or list of values and packs it into a binary structure, returning the string containing the structure It takes a LIST of values and converts it into a string. The string contains a concatenation of the converted values. Typically, each converted values looks like… Read More »

Difference between ‘chomp’ and ‘chop’?

CHOP ‘chop’ function only removes the last character completely ‘from the scalar, where as ‘chomp’ function only removes the last character if it is a newline. by default, CHOMP chomp only removes what is currently defined as the $INPUT_RECORD_SEPARATOR. whenever you call ‘chomp ‘, it checks the value of a special variable ‘$/’. whatever the… Read More »