This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
BEGIN { | |
# alias all references to the package to A | |
*A:: = \*ThisIsAVeryLongPackageName::; | |
} | |
package ThisIsAVeryLongPackageName; | |
sub spam { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Net::LDAP; | |
my $user = $ENV{LDAP_USER}; | |
my $pass = $ENV{LDAP_PASS}; | |
my $host = $ENV{LDAP_HOST}; | |
my $ldap = Net::LDAP->new($host); | |
die "can't connect to $host $!" unless $ldap; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use Capture::Tiny qw(capture); | |
my ($stdout, $stderr, $exitcode) = capture { | |
system("ls", "/", "/nosuchdir"); | |
}; | |
print "STDOUT: $stdout\n"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Checking for STDIN in Perl | |
# Use -t to test STDIN and STDOUT: | |
sub i_am_interactive { return -t STDIN && -t STDOUT;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use Test::More; | |
use Storable qw(dclone); | |
use Data::Dumper; | |
$Data::Dumper::Indent = 1; | |
$Data::Dumper::Sortkeys = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use Data::Dumper; | |
use Test::More; | |
diag "\n>>> Run as 'prove -v $0'<<<\n"; | |
my $doc =<<EOF; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use CPAN; | |
my $file = shift @ARGV; | |
open my $fh, $file or die "Can't open $file: $!\n"; | |
my @modules = <$fh>; | |
chomp @modules; | |
close $fh; | |
my $n = scalar @modules; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Getting the base from an ActiveDirectory connection | |
use Net::LDAP; | |
my $ldap = ...; # connect to ldap | |
my $dse = $ldap->root_dse(); | |
my @contexts = $dse->get_value('namingContexts'); | |
my $base; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# | |
# You can also do this (but you don't get the versions): | |
# | |
# perl -MExtUtils::Installed -e '$e = ExtUtils::Installed->new(); print join("\n", $e->modules())' | |
# | |
use strict; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# check if a upd port is open with netcat | |
nc -v -u -z -w 3 localhost 5000 | |
# send a test packet | |
# -n - Tells the echo command to not output the trailing newline. | |
# -4u Use IPV4 addresses only. Use UDP instead of TCP. | |
# -w1 Silently close the session after 1 second of idle time. That way, we’re not stuck waiting for more data. | |
echo -n “foo” | nc -4u -w1 <host> <udp port> |