- publishing free software manuals
Perl Language Reference Manual
by Larry Wall and others
Paperback (6"x9"), 724 pages
ISBN 9781906966027
RRP £29.95 ($39.95)

Sales of this book support The Perl Foundation! Get a printed copy>>>

26.1.2 Convertors

To help you convert legacy programs to Perl, we've included three conversion filters:

a2p
a2p converts awk scripts to Perl programs; for example, a2p -F: on the simple awk script {print $2} will produce a Perl program based around this code:
while (<>) {
    ($Fld1,$Fld2) = split(/[:\n]/, $_, -1);
    print $Fld2;
}
s2p and psed
Similarly, s2p converts sed scripts to Perl programs. s2p run on s/foo/bar will produce a Perl program based around this:
while (<>) {
    chomp;
    s/foo/bar/g;
    print if $printit;
}
When invoked as psed, it behaves as a sed implementation, written in Perl.
find2perl
Finally, find2perl translates find commands to Perl equivalents which use the File::Find module. As an example, find2perl . -user root -perm 4000 -print produces the following callback subroutine for File::Find:
sub wanted {
    my ($dev,$ino,$mode,$nlink,$uid,$gid);
    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    $uid == $uid{'root'}) &&
    (($mode & 0777) == 04000);
    print("$name\n");
}

As well as these filters for converting other languages, the pl2pm utility will help you convert old-style Perl 4 libraries to new-style Perl5 modules.

ISBN 9781906966027Perl Language Reference ManualSee the print edition