- or download this
>type script.bat
@echo off
...
testb=
testa=abc
testb=def
- or download this
package My::XML::Generator;
...
]),
]);
}
- or download this
use IO::Handle (); # For "flush" method.
...
}
print("crlf\n");
- or download this
use IO::Handle (); # For "flush" method.
...
STDOUT_BIN->flush();
print("crlf\n");
- or download this
>perl -v
...
-D100 L10
0B27:0100 63 72 6C 66 0D 0A 72 61-77 0A 63 72 6C 66 0D 0A crlf..raw
+.crlf..
-Q
- or download this
use strict;
use warnings;
...
for ( $min .. $max) { print(":"); <STDIN>; last; } # 2.2MB
for ( reverse $min .. $max) { print(":"); <STDIN>; last; } # 239MB
- or download this
use File::Basename qw( fileparse );
use IO::Dir qw( );
...
return "$d${n}[$max]$e";
}
- or download this
sub get_iter {
my $pass = 0;
...
while ($_ = $i->()) {
print("$_\n");
}
- or download this
sub get_iter {
my $pass = 0;
...
while ($_ = $i->()) {
print("$_\n");
}
- or download this
sub get_fibonacci_iter {
my ($x, $y) = (0, 1);
...
my $i = get_fibonacci_iter();
print($i->(), "\n")
for 1..40;
- or download this
my $mask = 0x06000003; # or whatever
...
last if not $val;
$val = ($val - 1) & $mask;
}
- or download this
0x00000000
0x00000001
...
0x06000001
0x06000002
0x06000003
- or download this
sub slice_ref {
return \@_;
...
print("After inserting into bar:\n"); # Doesn't work:
print('foo: ', join(', ', @foo), "\n"); # foo: a, 2, 3, 4, 5
print('bar: ', join(', ', @bar), "\n"); # bar: a, 6, 2, 3
- or download this
perl -M"ActivePerl::DocTools"
-e"ActivePerl::DocTools::UpdateHTML();
ActivePerl::DocTools::WriteTOC();"
- or download this
use URI ();
use File::Spec::Unix ();
...
# ------
# http://www.faqs.org/rfcs/
# http://www.server.com/
- or download this
system("... ...")
system("...", "...", "...")
...
IPC::Open3
IPC::Run
IPC::Run3
- or download this
/^(?:(?!$re).)*$/ # NOT re
/$re1|$re2/ # re1 OR re2
/^(?=.*$re1)(?=.*$re2)/ # re1 AND re2
- or download this
sub create_closure {
my $var = shift;
...
# around $var. I don't know if "closes"
# is the official terminology, but
# that's what's happening.
- or download this
sub scale_dimentions {
my ($width, $height, $max_width, $max_height) = @_;
...
printf("%d,%d$/", scale_dimentions(2272, 1704, 150, 150)); # 150,112
printf("%d,%d$/", scale_dimentions(1704, 2272, 150, 150)); # 112,150
- or download this
my @ranges = (
[ 0 .. 2 ],
...
print(join(' ', @$_), $/)
foreach @results;
- or download this
my @lists = (
[ ... ],
...
print(join(' ', @$_), $/)
foreach @results;
- or download this
# Add $value to sorted @array, if it's not already there.
my $idx = binsearch { $a <=> $b } $value, @array;
splice(@array, ~$idx, 0, $value) if $idx < 0;
- or download this
sub binsearch(&$\@;$$) {
my $compare = $_[0];
...
}
sub _unsigned_to_signed { unpack('j', pack('J', $_[0])) }
- or download this
$i = 4; print($i) while ($i--); # 3210
$i = 4; do { print($i) } while ($i--); # 43210
- or download this
$a = something; # something is executed in a scalar context.
@a = something; # something is executed in a list context.
...
print(scalar(localtime)); # Fri Oct 1 15:05:32 2004
}
# Refer to wantarray in perlfunc.
- or download this
sub nearest {
my ($num) = @_;
...
return int($num + 0.5) * $f;
}
- or download this
sub nearest {
my ($num, $digits) = @_;
...
return int($num + 0.5) * $f;
}
- or download this
$stmt = 'SELECT Field1, Field2 FROM Table';
$href = { map { @$_ } @{$dbh->selectall_arrayref($stmt)} };
...
# Row2Field1 => Row2Field2,
# ...
# };
- or download this
$stmt = 'SELECT Field1, Field2 FROM Table';
$href = $dbh->selectall_hashref($stmt, 'Field1');
...
# Row2Field1 => { Field1 => Row2Field1, Field2 => Row2Field2 },
# ...
# };
- or download this
# Serializes an array, a hash or a list which contains only
# strings and undefs. Everything else will be stringified.
...
)
} split(/\|/, $_[0]);
}
- or download this
# Untested.
...
# End HTML.
print($q->end_form());
print($q->end_html());
- or download this
sub flush {
my $h = select($_[0]); my $af=$|; $|=1; $|=$af; select($h);
}
- or download this
package MyStruct;
...
$x->Counter++; print($x->Counter, "\n"); # 5
$x->Counter += 1; print($x->Counter, "\n"); # 6
}
- or download this
# This \$var syntax of open() requires Perl 5.8.0 or higher.
use 5.8.0;
...
}
print("\$output contains:\n$output");
- or download this
Windows Registry Editor Version 5.00
...
[HKEY_CLASSES_ROOT\Drive\shell\cmd\command]
@="cmd.exe /k \"cd %L\""
- or download this
use strict;
use warnings;
...
test 3: bypassed
test 4: bypassed
test 5: bypassed
- or download this
@status = sort {
my $mtime_a = (stat("$target_dir\\$a"))[9];
my $mtime_b = (stat("$target_dir\\$b"))[9];
$mtime_a <=> $mtime_b
} @status;
- or download this
@status = (
map { $_->[0] }
...
map { [ $_, stat("$target_dir\\$_"))[9] ] }
@status
);
- or download this
use Alorithm::Loops;
...
];
}
- or download this
use strict;
use warnings;
...
my $a = $p->[0]; ## Gives no warnings!!
my $q = undef;
my $b = ${$q}[0]; ## Gives no warnings!!
- or download this
...
print("$p\n"); # ARRAY(0x1abefa0)
print("$q\n"); # ARRAY(0x1abf054)
- or download this
# Create some subroutines to find:
sub PACKAGEA::PACKAGEB::test {}
...
print(join(', ', check_for_sub('test')), $/);
# Prints "main, PACKAGEA::PACKAGEB, PACKAGED"
- or download this
# Create some packages for testing:
$PACKAGEA::ANYVAR = 1;
...
PACKAGEA exists
PACKAGEA::PACKAGEB exists
PACKAGEC doesn't exist
- or download this
# Create some packages for testing:
$PACKAGEA::ANYVAR = 1;
...
IO
CORE
main
- or download this
$color = substr($color, -6);
$color .= '0' x length(6-$color);
$color =~ s/[^0-9A-Fa-f]/0/g;
$color = hex($color);
- or download this
// K&R C:
char string[6] = "hello"; // Initializes string[] to "hello\0".
...
a1 = "Greetings"; // ERROR
a2 = "Greetings"; // OK