dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

perl.snippets (2195B)


      1 snippet readfile "Read from a file" b
      2 open(${1:handle}, "<", "${2:filename}") or die "Couldn't open the file $2, \$!";
      3 
      4 while(my $line = <$1) {
      5   $0
      6 }
      7 close($1);
      8 endsnippet
      9 
     10 snippet functable "Function dispatch table" b
     11 my %${1:table name} = (
     12   ${2:str} => \&${3:function name},
     13   ${4:str} => \&${5:function name}
     14 );
     15 
     16 $1{${6:variable to check}} or ${7:fail function};
     17 $1{$6}->();
     18 $0
     19 endsnippet
     20 
     21 snippet parseargs "Parse commandline arguments with GetOptions" b
     22 use Getopt::Long 'GetOptions';
     23 use Pod::Usage 'pod2usage';
     24 
     25 # Documentation: https://perldoc.perl.org/Getopt/Long.html#Simple-options
     26 my ($help, $manual);
     27 my %optctl = (help => \$help, manual => \$manual, '<>' => \&${1:callback function});
     28 GetOptions(\%optctl, 'help|h', 'manual|man', '<>') or pod2usage(2);
     29 pod2usage(2) if $help;
     30 pod2usage({ -verbose => 2, -exitval => 1}) if $manual;
     31 endsnippet
     32 
     33 snippet helpdoc "Pod help document structure" b
     34 =head1 NAME
     35 
     36 name of program - short tagline.
     37 
     38 =head1 SYNOPSIS
     39 
     40   program [options] [argument] [arg_2 [arg_3 ...]]
     41 
     42   Help Options:
     43     --help, -h        Show this script's help information.
     44     --manual, -man    Read this script's manual.
     45 
     46 =cut
     47 
     48 =head1 OPTIONS
     49 
     50 =over 4
     51 
     52 =item B<--help>
     53 Show the brief help information.
     54 
     55 =item B<--manual>
     56 Read the manual, with examples.
     57 
     58 =back
     59 
     60 =cut
     61 
     62 =head1 ARGUMENTS
     63 
     64 It can include lists:
     65 
     66 =over 4
     67 
     68 =item * B<bold thing>
     69 
     70 Here's some bold text.
     71 
     72 =item * C<code>
     73 
     74 Some code.
     75 
     76 =item * I<italic stuff>
     77 
     78 It does italics.
     79 
     80 =item * And even links
     81 
     82 Like the link L<to Google|http://google.com>!
     83 
     84 =back
     85 
     86 Of course, lists don't have to be bulletted:
     87 
     88 =over 8
     89 
     90 =item cut
     91 
     92 With this keyword, you can stop parsing for pod until the next directive.
     93 So documentation can be intermingled with code.
     94 
     95 =item item
     96 
     97 This just delimits a single item in a list.
     98 
     99 =item over
    100 
    101 Begins indentation for a list.
    102 
    103 =item back
    104 
    105 Finishes off a list.
    106 
    107 =back
    108 =cut
    109 
    110 =head1 EXAMPLES
    111 
    112 The following is an example of this script:
    113 
    114   program --help
    115 
    116 =cut
    117 
    118 
    119 =head1 DESCRIPTION
    120 
    121 This is a simple demonstration program for Pod::Usage, this text will be displayed if the script is invoked with '--manual'.
    122 
    123 =cut
    124 
    125 
    126 =head1 AUTHOR
    127 
    128 
    129 Should have some info about the author here.
    130 
    131 =cut
    132 endsnippet