Why are there U+200B characters in the subject? o_O

On Fri, Aug 17, 2012 at 07:57:49PM +0200, Dominik Danter wrote:
> Hi,
> 
> I don't understand the following code:
> 
> task "firewall", sub {
>            iptables_clear;
>            ...
>            ...
> };

That is just a subroutine call. You don't always need the
parenthesis in Perl. In particular if Perl knows that the
bareword refers to a subroutine.

use strict;
use warnings;

# Perl needs to know about foo before we can call it without
# parenthesis. This predeclares it.
sub foo;

# Now we can call it without the parenthesis.
foo qw/bar baz bak/;

sub foo {
    print "Called foo with these arguments: @_\n";
}

The sub { ... } part is just defining an anonymous subroutine and
passing a subroutine reference into the subroutine.

use strict;
use warnings;

sub foo;

# Call foo with anonymous subroutine as second argument.
foo "firewall", sub {
    print 'Called anonymous subroutine via reference. ',
            "Arguments: @_\n";
};

# You can also pass a reference to a named subroutine.
foo "firewall", \&named_sub;

sub foo {
    my ($arg1, $sub) = @_;
    print "Called foo with these arguments: @_\n";

    # Calling the subroutine via reference.
    $sub->($arg1);
}

sub named_sub {
    print "Called named_sub with these arguments: @_\n";
}

See perldoc perlsub.

Regards,


-- 
Brandon McCaig <bamcc...@gmail.com> <bamcc...@castopulence.org>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'

Attachment: signature.asc
Description: Digital signature

Reply via email to