Thursday, March 22, 2012

Function prototyping in Perl

Today, I studied some old codes from year 2003. It has very weird Perl syntax which I have never seen before. I did some testing using the following code. Of course, I did try and error until I got what the $;$ means.

They are actually representing argument that is passing to the subroutine. One $ represent one argument. The ones before ; are required arguments, and the ones after the ; are optional arguments.

My colleague is smarter, she found this link online : There are a lot more to learn in Perl!

use strict;

use Data::Dumper;
$Data::Dumper::Indent = 3;

sub sub0 () {
  print Dumper(@_);

sub subA ($;$) { 
  unshift @_, 'new from a';
  print Dumper(@_);
  goto &sub0;

sub subB () {
  subA("a", "b");



No comments:

Post a Comment