Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>Here is a simple example that takes an input file and removes any non-word characters.</h1> <pre><code>#! perl use strict; use warnings; use 5.010; use Getopt::Long; use Pod::Usage; use autodie; my %opts = ( infile =&gt; '-', outfile =&gt; '-', ); GetOptions ( 'encode|e' =&gt; \$opts{encode}, 'decode|d' =&gt; \$opts{decode}, 'infile|i=s' =&gt; \$opts{infile}, 'outfile|o=s' =&gt; \$opts{outfile}, 'help|h' =&gt; \&amp;help, 'man|m' =&gt; \&amp;man, ); unless( # exactly one of these should be set $opts{encode} xor $opts{decode} ){ help(); } { my $infile; if( $opts{infile} ~~ ['-', '&amp;0'] ){ $infile = *STDIN{IO}; }else{ open $infile, '&lt;', $opts{infile}; } my $outfile; if( $opts{outfile} ~~ ['-', '&amp;1'] ){ $outfile = *STDOUT{IO}; }elsif( $opts{outfile} ~~ '&amp;2' ){ $outfile = *STDERR{IO}; }else{ open $outfile, '&gt;', $opts{outfile}; } if( $opts{decode} ){ while( my $line = &lt;$infile&gt; ){ chomp $line; say {$outfile} $line; } }elsif( $opts{encode} ){ while( my $line = &lt;$infile&gt; ){ chomp $line; $line =~ s/[\W_]+/ /g; say {$outfile} $line; } }else{ die 'How did I get here?'; } } sub help{ pod2usage(); } sub man{ pod2usage(1); } __END__ =head1 NAME sample.pl - Using GetOpt::Long and Pod::Usage =head1 SYNOPSIS sample.pl [options] [file ...] Options: --help -h brief help message --man -m full documentation --encode -e encode text --decode -d decode text --infile -i input filename --outfile -o output filename =head1 OPTIONS =over 8 =item B&lt;--help&gt; Print a brief help message and exits. =item B&lt;--man&gt; Prints the manual page and exits. =item B&lt;--encode&gt; Removes any character other than /\w/. =item B&lt;--decode&gt; Just reads from one file, and writes to the other. =item B&lt;--infile&gt; Input filename. If this is '-' or '&amp;0', then read from STDIN instead. If you use '&amp;0', you must pass it in with quotes. =item B&lt;--outfile&gt; Output filename. If this is '-' or '&amp;1', then write to STDOUT instead. If this is '&amp;2', then write to STDERR instead. If you use '&amp;1' or '&amp;2', you must pass it in with quotes. =back =head1 DESCRIPTION B&lt;This program&gt; will read the given input file(s) and do something useful with the contents thereof. =cut </code></pre> <pre> echo Hello, this is, some text | perl sample.pl -e Hello this is some text </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload