Built-in functions
Perl is an interpreted language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information.
|
See also
|
[ home ]
-
[ search ]
-
[ sitemap ]
Built-in Functions
| Reference | Title |
Sample Code |
|
R1013 | DBM - Berkeley Database |
"Runs on NT and Unix!"
use strict;
my ($key, $val, %MYDB);
dbmopen %MYDB, "mydbm", 0666;
while (($key, $val) = each %MYDB) { print $key, " = ", $val, "\n";
|
R1059 | File::Find |
#!/usr/bin/perl -w
use strict;
use File::Find;
find(\&wanted, 'd:\hersi_pu');
sub wanted { return if -d;... |
|
R1064 | How do I open a file without blocking? |
use Fcntl; sysopen(FH, "/tmp/somefile", O_WRONLY[CHR_PIPE]O_NDELAY[CHR_PIPE]O_CREAT, 0644) or die "can't open /tmp/somefile: $!";
|
|
R1063 | How to start a Perl Module? |
#!/usr/local/bin/perl -w use strict;
use XMLSimple;
my $xml = new XMLSimple (ref => 'ABC');
my $res = $xml->parse(verbose => 1, debug => 1);
print "\$res = '... |
|
R1058 | Locate a position of a substring |
my $string = 'Hello, World'; my $lookfor = 'o'; my $from = 5;
my $pos = index($string, $lookfor, $from);
print "'$lookfor' is at position $pos of string '$string'\n";
|
R1038 | Perl Form / Reporting with Perl |
|
|
R1001 | Random Numbers |
srand(); my $X = int(rand(10)+1); print $X;
Let's say you have an array of somethings - for instance sequences of letters (also known as strings). And let's also say you want to pick... |
|
R1031 | String Encryption |
$crypted = crypt("hello", 'az'); # ---> 2AuDleQw6eOSg
print "Password?\n"; $try = <STDIN>; chop $try;
if (crypt($try, '2AuDleQw6eOSg') eq '2AuDleQw6eOSg') { &n... |
|
R1031 | Timestamps of a file |
#!/usr/bin/perl -w
use strict;
my ($atime, $mtime, $ctime) = (stat('test.txt'))[8..10];
printf qq~ Accessed: %s Modified: %s Created: %s ~, get_real_t... |
|
R1051 | Usage of pack() and unpack() |
--> hex FF = 255 --> unpack(C, 'A') = 65 --> unpack(C, 'L') = 76 --> unpack(H8,'HALLO') = 48414c4c --> unpack(B8,'A') = 01000001
--> pack(cccc, 65,66,67,68) = ABCD |
| |
|