To minimize typing overhead I install it under 5 different names (using links) and let it use its name as a parameter. The names aul, bul, cul and dul give me four standard line types, while pul takes an arbitrary line pattern as its first argument.
#!/usr/bin/perl
# aul, bul, cul, dul, pul - plaintext underline helpers
# [abcd]ul use some fixed underline character,
# pul uses its first argument as pattern
use strict;
use warnings;
use integer;
use File::Basename qw(basename);
$0 = basename($0);
my $pat =
{qw(a - b = c ~ d ^)}->{substr($0, 0, 1)} || shift;
die "usage: $0 pattern [file]...\n"
if !defined($pat) || '' eq $pat;
my $len = length($pat);
while (<>) {
print;
s/\S/x/g; # underline non-whitespace
1 while s/x (?= *x)/xx/; # and inner blanks
if (1 == $len) { # finally apply texture
s/x/$pat/g;
}
else {
s{(x+)}{substr(
$pat x (length($1)/$len+1), 0, length($1)
)}ge;
}
print;
}
I did this example that I call 'the Pine Tree' pattern...
cat <<'EOF'| perl pul.pl '/*\*'
> Kernel-disk plus a disk containing the initial ramdisk, which will be
> prompted for at boottime.
>
> If you wish to remaster the CD, please don't forget to specify
> -no-emul-boot -boot-load-size 4 -boot-info-table \
> -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat
> as option to mkisofs. Otherwise your CD won't be bootable.
> EOF
Kernel-disk plus a disk containing the initial ramdisk, which will be
/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/
prompted for at boottime.
/*\*/*\*/*\*/*\*/*\*/*\*/
If you wish to remaster the CD, please don't forget to specify
/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*
-no-emul-boot -boot-load-size 4 -boot-info-table \
/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*
-b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat
/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\
as option to mkisofs. Otherwise your CD won't be bootable.
/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*\*/*
I still can't understand the use of having different names for the same script. Where are you keeping the default patterns?
I still can't understand the use of having different names for the same script. Where are you keeping the default patterns?
The default patterns are hard coded into the script, namely:
In such an environment the Perl function exec lets you choose the name argument (which will end up as $0 in the called program) independently of the program's actual filename (using the indirect object syntax).
The easiest way to take advantage of a $0-aware script from the command line, however, is to make it accessible via appropriate different filenames. Just link (or copy) your pul.pl file to aul.pl and see what happens if you call that (N.B. without a pattern argument).
{qw(a - b = c ~ d ^)}->{substr($0, 0, 1)} || shift;
It is amazing!Linux & Perl always have a new surprise for me!
Thank you!
perlmonks.org content © perlmonks.org and chanio, martin
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03