Steven's Blog

A Dream Land of Peace!

Perl中的秘密(secret) Operators和constants

Several days I met some perl one-liner like this:

1
cat $file | perl -Mautodie -MList::MoreUtils=none -ne 'chomp; push @re, $_ }{ open $fh, $ENV{CF}; @s = <$fh>; foreach $s (@s) { print $s if none { $s =~ qr/$_/ } @re };'

I have no idea what the “}{“ here means, at first I thought it maybe some typo.

Then my colleagues showed me the following page, which lists many weird perl operators.

1
http://search.cpan.org/dist/perlsecret/lib/perlsecret.pod

To have a look at how it is used in the backend:

1
$ perl -MO=Deparse -lne '}{print$.'

It will give the following code:

1
2
3
4
5
6
7
8
-e syntax OK
    BEGIN { $/ = "\n"; $\ = "\n"; }
    LINE: while (defined($_ = <ARGV>)) {
        chomp $_;
    }
    {
        print $.;
    }