English 中文(简体)
原标题:How can I mock Perl s unlink function?
use strict;
use warnings;
use feature  say ;

#use subs  unlink ;
use subs  mock_unlink ;  # but do you really need it?

sub mock_unlink {
    say "Want to unlink: @_";
    #return;  # returns undef ... why?

    no warnings qw/redefine/;
    *CORE::GLOBAL::unlink = &mock_unlink;
    #use warnings;  # no need, `no warnings` is scoped to this block

unlink "some file";

  • get a reference to apoint sub (not subname)

  • use subs pragma predeclares the specified subs so one can use them Without parenthesis Even before their definition. 你们真的需要吗?

    为什么不使用<条码>各分点;? ......不知道。 很显然,在宣布拟用这个程序取代的子点之前,该子要用这个过程加以说明。 在我发现情况后,我将随时通报最新情况。

  • 。 因此,你不需要明确警告(但也不是错误)。

  • return;,载于。 这通常表明,在这方面似乎不合适。 从最后一份有回报的声明中删除了收益价值,在这种情况下,如果成功,可回归成正本的<条码>。




Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...