App-Unliner
view release on metacpan or search on metacpan
be invoked with this command:
$ unliner log-report < input.txt
You could also put a shebang line
<https://en.wikipedia.org/wiki/Shebang_(Unix)> at the top of your
script:
#!/usr/bin/env unliner
Now if you "chmod +x log-report" you can run it directly:
$ ./log-report < input.txt
Defs
The "def main { }" isn't a special type of def except that it happens to
be what is called when your program is invoked. You can create other
defs and they can be invoked by your main def and other defs, kind of
like subroutines.
For example, we could move the "awk" command into a "ip-extractor" def,
bin/unliner view on Meta::CPAN
You can run your scripts by passing them in as the first argument to C<unliner>:
unliner /path/to/myscript.unliner [args to unliner script]
Alternatively, you can put the following line at the top of your unliner script:
#!/usr/bin/env unliner
make your script executable:
chmod a+x /path/to/myscript.unliner
and then run it directly:
/path/to/myscript.unliner [args]
Lastly, you pipe an unliner script to C<unliner> on standard input:
unliner < /path/to/myscript.unliner
although now your unliner script won't have standard input available to it which your script may require.
lib/App/Unliner.pm view on Meta::CPAN
## HTTP response code is 2nd last field
print "$1\n" if /(\d\d\d) \S+$/;
}
def tally {
sort | uniq -c | sort -rn
}
Now make C<reportgen> executable:
$ chmod a+x reportgen
Now you can run C<reportgen> like a normal program:
$ ./reportgen /var/www/log/access.log
43628 200
1911 301
201 404
6 500
lib/App/Unliner/Intro.pm view on Meta::CPAN
}
If you save this in the file C<log-report> then your unliner program can be invoked with this command:
$ unliner log-report < input.txt
You could also put a L<shebang line|https://en.wikipedia.org/wiki/Shebang_(Unix)> at the top of your script:
#!/usr/bin/env unliner
Now if you C<chmod +x log-report> you can run it directly:
$ ./log-report < input.txt
=head2 Defs
The C<def main { }> isn't a special type of def except that it happens to be what is called when your program is invoked. You can create other defs and they can be invoked by your main def and other defs, kind of like subroutines.
For example, we could move the C<awk> command into a C<ip-extractor> def, and the tallying logic into a C<tally> def:
( run in 0.628 second using v1.01-cache-2.11-cpan-496ff517765 )