Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change


by Discipulus (Prior)
on Jun 13, 2002 at 08:04 UTC ( #174111=user: print w/replies, xml ) Need Help??

In the picture you can see my wonderful historical kawasaki motorbikes of serie GPZ Unitrack (1986 and 1984).

starting learning Perl as a game in a hot summer one year ago (ie 2001) on my linux system and now..
2003..trying to avoid learning vb administrating win32 with Perl..
2007..trying to avoid learning C# administrating win32 with Perl..
2013..trying to avoid learning powershell to manage w2k8r2 using Perl...
riding my Kawasaki GPZ 550
...April 12 2012: riding my Kawasaki GPZ 750..
29 July 2014 Discipulus became 668th in Saints in our Book

full page chat and last hour of cb

throttling something with ularm
threads a parallel search dirdirectory walk in windows
marto on audio video editing ffmpeg and openshot
afoken: newline gory details BrowserUk newlines on windows
zentara about reinventing the wheel "You never really know how a wheel works, until you tear it apart. I bet you now know more than most about the http protocol, now that you built your own. I think building your own webserver is a great educational exercise, because it exposes you to all the problems involved, and also makes you appreciate the pre-made wheels that are given to us."
'0 but true' encyclopedic by Athanasius

Re: Re: How to capture screen under Win32? (old to be tested)

lot of links about Perl and Sharepoint (to be verified)
seems old but usefull Perl Design patterns
one time only s‎crip‎t: Sys::RunAlone and links

an old flame?
Marpa and binary trees Marpa example by choroba on validate quoted string Marpa example by choroba on nested sums of weighted integers a toy language in Perl
erase a disk on Linux
Task::Kensho to choice useful modules
Win32::Daemon leak memory - examples
monumental list about API and interface
me about prototypes and my wisest post :=) Adjacent number
Perl secure coding standards Open Web Application Security Project (OWASP)

examining Perl code: stripping POD, comments, reordering subs..
cant happen or check for impossible events
shrink an array use more memory?
CISCO dump router config
bustrophedon distribution
onliner to concatenate files with filter view Anonymous and mine.
web scraping the state of perl art and web scraping HTML::TreeBuilder::XPath web scraping

typical s‎crip‎t template (exit this way) points to old useful tye example

Win32::SerialPort and Arduino
send UDP packets - ppc by vinsworldcom

defending eval string! "Perl was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. Plus nobody can stop you from doing stupid things." found at $^P=0x100 shows eval line in file eval $@ and other considerations meditation about eval error stack
BrowserUk on GD image format GraphicsMagick instead of ImageMagick

how GZIP compression works

spotted on cavac's homenode BrowserUk and flexvault wonderful examples on threaded server Programming languages for multicore computers and gentle introduction to MCE and MCE by marioroy and also interesting thread started by karlgoethbier MCE on perltricks

Threads From Hell #1 Threads From Hell #2 Threads From Hell #3

multiple threads to STDOUT threads and signals threads and signals on windows joining threads and order of things matter share data between threads

Threaded read from files comparison BrowserUk and marioroy examples

SIGNALS: Corion attempt to implement signals via named pipe on win32 BrowserUk about signals on Win32 again win32 signals signals and strawberry signals vs windows signal and CTRL-C ms docs about signals?? win32.c source code

%SIG hash localized %SIG and XS et alia

odometer oneliner
seek speed

DBIx::PreQL aims is to simplify the horrendous task of maintaining dynamically generated SQL.
interesting info on stat file using the lonely underscore.

@_ and alias behaviour - many interisting things
autoincrement autodecrement explanation and history

about learning process

LWP check if Request was redirected LWP::UserAgent sending file with POST

Spped up suggestion poit to the incredible MCE module
interesting thread about object oriented Perl that points to this subthread and to a very deep discussion about Perl object OO and Moose OOP how to (not) loose encapsulation About object and basics tobyink about Stop Creating Mutable Objects Arunbear a bird view on Object Oriented Perl OO and lazy setter/getter tobyink about Moose and Moo

Perl on RaspberryPi related to RaspberryPi Raspeberry Pi 1,2,3 Displaying my PM post count and XP on an LCD with RPi::WiringPi Raspberry Pi wiringPi API wrapper released
to valuable for a new Perl job by YourMother
good thread about test testing and habits. change a s‎crip‎t to be testable, caller info Tux abou refactoring code and Test driven design Testing methodology, best practices and a pig in a hut. by BrowserUk who point to Effective Automated Testing the sorry state of Perl unit testing framework CPAN test s‎crip‎ts, "run" directory, and test data files good advice form stevieb and jeffa at testing perl Automate and dispatch unit test runs across perl/berrybrew on remote Windows and Unix Writing tests when you don't know what the output should be Re: Devel::Cover for with different command-line input arguments
About windows inode here BrowserUk and others inodes found via gnuwin32 seems more recent of unxutils

about context and other links too If you believe in Lists in Scalar Context, Clap your Hands

about rounding integers here and BrowserUk's random cross platform. floating point addition and About Floating-Point Arithmetic and 1+1 != 2 and Humans have too many fingers Decimal Floating Point can arrive soon. rounding numbers afoken enciclopedic about random session IDs
perl.exe vs wperl.exe here and wperl.exe and about temporary files on windows and SIDs or Unaltered child return code on Windows and win32 exit code after a crash guide
Multiplexing log output: Log4perl of the poors is mine prof of concepts to mimicry Log4Perl. Interstings also Loops's attempt found at Output to STDOUT and print last line to console and use modules IO::Tee Tie::STDOUT examples at Split output to STDOUT as well as a file log4perl selective output
Optimising large files processing Recommendations for efficient data reduction/substitution application Using indexing for faster lookup in large file reading large file where foreach my $line (<$readHandle>) { is list context and while (defined( my $line= <$readHandle>)) { is scalar context by Corion reading char bytes faster
about closures Merlyn column and Why closures where tye sythetize 4 types of progrmming, Corion pointed me to Kingdom of Nouns unrelated but quite related Why I like functional programming Functional programming and monads How A Function Becomes Higher Order and Real life examples of closures and also Closures Explained also tobyink on closures
switch to ssl for free p5-ssl-tools
mass editi in Perl
Unicode utf-8 codepoints and graphemes and also The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) also when i will be able to understand all this post about Unicode i'll be happy in the new millennium Why am I having so much trouble and pain with UTF-8 in perl? UTF8 DB and web windows problem with UTF8 pathnames Mixed Unicode and ANSI string comparisons? Perl on Windows: file names with accented characters, UTF-8 and -e Re: Convert special characters in UTF8 (layers) -- Devel::Peek unicode Perl bug unicode issues in Perl replicate dev env
Passing an open handle to another process on win and about system 1 and system detached many interesting comments in and salva's question and tye's answer about Windows and pipes that don't close.. quoting BrowserUk from hereOn Windows, parameters are passed to executables as a single string, so the list forms of system & open etc., join the list into a single string before calling CreateProcess(). Passing arguments to programs on Unix and Windows by afoken arguments to be protected from shell spawning windows children (revisted) String::Interpolate suggested by choroba open in memory file - open to a reference - be aware of.. open a filehandle from an HERE doc ambrus default schema to use GetOpt::Long GetOpt::Long POD::Usage dynamic duo system commands in parallel on windows Win32::RunAsAdmin UAC of win7

an interesting reading Exploring Programming Language Architecture in Perl found at Writing a Programming Language in Perl another intersting by Dominus
about threads on windows and an ufo Q module. and Adding parallel processing to a working Perl s‎crip‎t also see zentara words and links also another example here zentara's on IPC::Shareable and Parallel::ForkManager and Handling error on threads and ikegami's monitor child exit threads on Gtk problems and another Gtk threaded application Threads::Queue example threads and memory threads shared example Tk and forks links BrowserUk threads to search in a bi file neat fork example GUI programming Perl panorama RFC: Compiling Gtk+ stack on windows with strawberry perl Tk MainWindow and another TopLevel spawn order when I discovred also by zentara
just for fun (please do not feel offended, humor is humor..): if programming laguages were religions or cars other cars or car pictures or women or boats or drinks or bands or philosophers or natural language? humor geek hist
Fudge means a sweet.. but here you have a very detailed error reporting sub. using Log4perl instead of debugger About error handling IPC Open3 Catching errors by Ikegami
Tricks with DBI very old but usefull and GMAX DBI tutorial GMAX The fine art of database programming also Databases made easy by GrandFather DBI placeholders wit multiple values handling dbi error good example
web programming for beginners and also the w3 validator or the web perfomance analyzer and why frames are not good (very ancient article) SWAT introduction - testing web applications HTTP cross origin resource sharing
Re: How to understand chapter 6 of Higher Order Perl?
One Zero variants_without_repetition combinatory calculus in aregex in the oha's answer.
Custom Sort An AoA intersting serie of replies about costum double sort. A Fresh Look at Efficient Perl Sorting
colorized output Ack beyond grep
the x !! operator combo . found in conditional statements in list constructors ..but better is tye's ! $test ? () : ( ... )
Perl object memory overhead view the interesting replies.
Re: Ask for STDIN but don't pause for it
pack unpack tutorial and perl.pack.unpack.printf.cheat.sheet unpack is not so obviously the opposite of pack (padding) pack little endian big endian numbers
array and hash and other speed comparison Fast Way to find one array in second array by Browseruk Weighted frequency of characters in an array of strings -- explained
load module in BEGIN block ikegami's explaination of BEGIN sequence
The early history of Perlmonks
about app packaging and kirsle blog too an some good link here too decrypt a packed perl program Par pp and link to pp -x par pp executable TK and change the icon PAR pp checklist depends.exe example usage and objdump.exe dependences walker PAR pp and included files, just to remember Problem pp PAR on strawberrry ppsimple simple packer!! how Anonymonks understand portable perls change icon to a PAR exe or exe in general
The Dynamic Duo --or-- Holy Getopt::Long, Pod::UsageMan!
maze generator thanks fo funny to ambrus and choroba
Recursive Directory print view especially Laurent_R's answers.
Joel on software - The Process of Designing a Product
old but useful: behind the gui lives the shell
IP and subnets in given range
Perlmonks's World Map gently hosted by moritz
performance tunning of a lamp installation mysql swappiness problem YourMother about high traffic webserver
old utility to show ascii code
about our
lot of link about Tk in comments by monks ... but discovered Prima! and PerlQt Tkzink and zentara's commentary about tkzink Tk::scale and TK::Spinbox to validate entries
Re^3: Perl compiler request - flogging the dead horse! very interesting explanation of perl compile complexity compiletime vs runtime compiletime and runtime again another compiletime runtime ikegami on compile vs runtime again aboutcompiletime and runtime
interesting bench about splitting long lines bench index -linear - regex on strings
Mojolicious::Lite +and jQuery +AJAX + Mojo::Template Bootstrap Angularjs Perl some hints
Re: Pointers for building Perl off of Strawberry Perl. compiling a Perl under win
Perl was given to light ligther side of Perl search
check your s‎crip‎t against this
Damian Conway's ten rules for when to use OO
flip flop operator Perl Idioms Explained.. and Hidden features of Perl and also other flip flop considerations and links
Teaching perl: Re: How to teach perl to novice programer and Re: What is the best way to master perl (do your homework)
About new modules: perlnewmod that links also to this one... Create a ppd module distribution and also Corion's answer a lot of links about naming and new modules and about installed modules About Packages and modules namespaces Writing Solid CPAN Modules require "" with use strict; points to Include subs from different perl file A brief question about testing/best practices testable code - S‎crip‎tor and Programmers skimmable code José's Guide for creating Perl modules

Exporter and Exporting-Without-Inheriting-from-Exporter point to that contains zentara's package/module tutorial

advice on new module points to CPAN tutorials and How to make a CPAN Module Distribution and What are the files in a CPAN distribution? modules and reusable code Dont repeat... your module VERSION or more modern VERSION section in POD cpanm track modules installed (fore reinstall later) Template to create modules

poem on strict... The strictures, according to Seuss Levels of strictness and compatibility when use -w or use warnings module related and very interesting
Plack Dancer Dancer2 et alia: Understanding benefits of Plack PSGI, Plack and also Dancer2 sessions under Plack and also Beginner's guide to Dancer Dancer calendar 2010 2011 2012 2013 few things on Dancer2 SawyerX speacks about Dancer2 and CGI must die! larsen writes about plack mojolicious https redirect Dancer2 sessions under Plack About sessions and modules to do it How to make ajax requests in Dancer2 Write a Filehandle w/Dancer2 Dancer2 - How to loop over a ref to a HoH Dancer & Plackup - Redirect not refreshing page data Bizarre Dancer encoding behavior Need tipps for identifying utf-8 problems with Dancer and MySQL Beginner's guide for Perl Dancer contains internet introduction too Current Dancer route Your Mother about recicling an existing CGI in plack free Dancer Hosting (not tested) and psgi links and plack ones by Miyagawa and tobyink on deploying strategies of psgi app and Plack and multiple domains which point to this one and mount_multiple_apps_with_plack part one two and 3 and last also about session signed cookies with Plack form from CGI to Dancer and Template Toolkit some links about basic internet Jeffa Dancer example Plack debugger infos Twiggy is a lightweight and fast HTTP server by Miyagawa [href://|Solved Testing Dancer2 - simulating requests from different IP addresses] YourMother encurage uWSGI over Starman see Corion uses Dancer and twiggy Dancer2 and JQuery -- opinion on web framework

Plack modperl FASTCGI etc also link to plack for beginners

Multiple plack apps and deployment Mojolicious::Lite slides

Web Apps - small examples and guidance

Catalyst client server interaction - Template and javas‎crip‎t Understanding Catalyst - YourMother words separating html and logic - old but interesting catalyst refresh

good Perl web panorama in late 2015: PSGI mod_perl where my process runs?

CGI alternatives BIS lot of links Simple http server one-liner for some static files

How can I visualize my complex data structure?good post about dumping complex datastructure, and comparison on Perl serialization options also GrandFather note

Note that $, % and @ don't tell you what type variables are, they tell you what type of thing an expression returns. So $ref returns a scalar which may be a reference to an array or a hash. @$ref and @{$ref} return arrays (they are equivalent) by dereferencing $ref. The {} version is much clearer (and often required) when the expression used to get the reference is complicated.

afoken describes Data::Dumper JSON Storable YAML differences
SOAP, WSDL, XML service/clientgood post (seems) on WSDL links about soap and wsdl
How do I mix up Perl and jQuery (for beginners) lot of examples Perl + jQuery
XML "If you need to deal with XML, first, we’re very sorry." b d foy and and and speed comparison mirod schratchpad and Re: Another simple XML Twig question and ambrus's Do not reinvent the wheel: real-world example using XML::Twig and also and choroba about XML parse an infinite strem with XML::Twig and LWP -- complete example with server too XML::Simple has to go! XML::Twig to exctrat from PDF

Davido's precious regex tester is now here also onther testing site suggested by Eily also, anonimously suggested, rxrx and this one and this other one and also VRegExp or 7stages of a regexes user and and and Using Look-ahead and Look-behind 7 Stages of a Regex User two-dimension regex special array @- $-\0\, $+\0\ example more than 32k match regex limits perlretut -- dissection of a regex -- lazy quantifier huge list of links -- view kcott reply regex to check a sequence of characters
lot of links about debugging Perl code and Use strict warnings and diagnostics How to perldebug a Term::ReadLine application hard to debug windows memory error

Tartaglia's Pascal's Triangle: mine Pascal Triangle Pascal's triangle... where you can find perl -e "while((@_=(1,map$_[$_-1]+$_[$_],1..@_))<=$ARGV[0]){print qq(@_\n)}" Binomial Expansion and another interesting page see also The Oldest Plays the Piano Explain one liner for fibonacci and Explain Fibonacci one-liner ?? also test of primality Another primality a quasi sieve My big tk program about Tartaglia's triangle choroba fastest prime check Sieve of Erathostenes obfu

big integer 64bit caveats
SSH2 demo twesti ssh connection on windows - socket Re: Net SSH2 auth_publickey not working in Windows
ooh, oh, ohh is still alive!
Should i come back to Perl? where YourMother resume best Perl improvements.
Most well-known Perl-powered product

speed comparison 2012 and choroba mentioned TIOBE in chat; never eard.

refactoring CGI appsRe: Refactor CGI::Application and supporting scrits difference between library and framework Re: What does Mojolicious do exactly and is it right for me? IIS 7.5 Re: can Perl-CGI run persistently on Windows 2008 with IIS 7.5? how? Activestate and iis7.5 Perl on IIS 7 and win2k8 header examples: Need help in translating the following php code to perl a lot of links about CGI and web related stuffs Perl and CSS (boostrap perlcritic.css and other) Strawberry Perl on IIS 6 no more doublequote for IIS 8 perl %s %s

MOdern replace of SSI Re^3: A modern Perl repalcement for Apache Server Side Includes?
afoken explain DOS and CMD.exe shell, very well (interesting thread about IPC::Open3 on win32) Re: Writing portable code writing portable code OS independent perl s‎crip‎t and Re: Command line arguments not passed in Win7 ( regqueryperl.bat ) and Question on Strawberry's Portable .bat file and also variables substitution in cmd.exe and Re^2: Dangerous Characters for system calls also relocate Perl 5.20. Also see the /D switch of cmd.exe that point here Portable win32 perl application without PAR::Packer where anonymous point explain portability of ActiveState Perl and here about win file system redirection 32 64bit madness me about filesystem redirection me about registry redirection strawberry space and ampersand in PATH 64bit perl caveats? some test of mines about Permission denied writing to Windows 10
mar 2013 - About BEGIN blocks: Re: Returning information from BEGIN Re^3: BEGIN and compile-time Never lock $0 inside of a BEGIN block Re: Perl templating/macro creating using 'BEGIN'... Re: BEGIN block and prototyped subroutines Re: BEGIN vs initialization __DATA__ used in BEGIN and Is this BEGIN construct supposed to work? and about UNITCHECK in my check modules used by a s‎crip‎t and their version module caller Who called Perl $0 in @INC
Re: console adventure game to html mod_perl version about gaming

Using the DATA file handle for ARGV DATA, ARGV and typglob trick very well written intro and the recent Why does Perl have typeglobs? and not useful but intersting magic used by $^T in this post. tye explain that * is the sygil for FH Re: Why don't file handles have sigils? (*) Removing CODE slot in typeglob typeglobs IO with or w/o DATA typeglob to aliasing a method call symbol table by dada (italian) ysth about symbol table the same doubt i had page 130 typeglob/symbolic reference question perl-iterate-over-a-typeglob pad walker example symbol table manipulation Perl Internals - references and symbol table get the list of methods and variables in a package Devel::Symdump and symbol table woes Dominus about scope

my question about symbol table, typeglob.. where Lanx point to dumping lexical filehandles inspect packages to spot datastructure definition by AnomalousMonk filehandle windows default layer Finding file level lexical variables PadWalker example

evil memory addresses usages: How to access the contents of a specific memory address? tobyink point to How do I find out the RAM memory address of a var in a program running on WIN ?

Perl White Magic and one liners and A gentle introduction about Perl command line flag and a column by Merlyn at stonehenge and which oneliners monks use Perl oneliners explained

perl idioms

stolen from busunsl's homenode
  • slurp a file:  my $contents = do { local (@ARGV, $/) = $filename; <> };
  • set even elements of @list to 'bla':  $_ % 2 or $list[$_] = 'bla' for 0..$#list;
  • getting indices sorted by value: my @indices = sort { $a[$a] <=> $a[$b] } 0..$#a;
  • initialize hash elements: @hash{@array} = (1) x @array
  • assign empty string defaults: $_ = '' for grep ! defined ( $foo, $bar, $baz );
  • blank padding: $str = pack('A40',$str);

some cool use of Perl

Posts by Discipulus
Activate your perl programs by touch with! in Cool Uses for Perl
2 direct replies — Read more / Contribute
by Discipulus
on Apr 01, 2016 at 03:09 is not yet published, but perlmonks deserves a preview
    Just by including this incredibly simple module
    you can prevent unwanted access to
    your perl programs and
    protect your compiled application from
    unintended double clicks. Here the code and example usage
    #!/usr/bin/perl use strict; use warnings; package Touchable; exit 0 unless (stat ($0))[9] && (($^T - (stat ($0))[9] ) < 3);

    Example of usage:
    # consuming script: use strict; use warnings; use Touchable; print "here $0\n"; # usage example perl # works only if touch activated.. touch & perl here

    Have a nice 1st of April!

    Have fun!


    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Modules as configuration files in Cool Uses for Perl
1 direct reply — Read more / Contribute
by Discipulus
on Oct 28, 2015 at 08:59
    Ok is not so cool nor elaborate but i find it useful..
    Nowadays i end writing programs with a lot of options and I'm happy using Getopts::Long to grab them all. During testing but even during normal usage of such programs I hate tought to have a long command line, spwaning two or more lines of my terminal screen. As happens with long arguments list given to the find program.

    Along many other faults, i tend to write programs with core only modules, and no modules for configuration files are in the core.

    Even if minimalist a configuration file can contain comments and indentation..

    The basic idea of Perl module come in the rescue. Infact a module can be conviently imported even before any program you wrote by simply adding -M as in perl -MModuleName and as long the module resides in the current directory, no other Perl's switches are needed.
    Even more: since @ARGV is global by nature, the module can modify @ARGV before Getopts::Long starts his wonderful work inside the main program.

    The results is a short module like this:
    use strict; use warnings; unshift @ARGV,$_ for reverse map {s/\s*#.*$|^\s*#.*$//; (split ' ',$_,2)} split /\n/, <<'EOCONF' --put here -your --list of arguments and #any #indented --comment #comments --too EOCONF ; print "@ARGV" unless caller; 1;
    Unshifting them let an option specified in the module to be overwritten by the same option in the command line. For example if the module contains --verbosity 3 you can call the program perl -MConfigDefault --verbosity 0 and have the right behaviour.
    Please note that split as the LIMIT specified, so in the above exapmle --list has as value of arguments and ie only two arguments are created for each line. This is the desired behaviour.
    The final result seems like:
    perl -MConfigDefault --verbosity 0
    The print "@ARGV" unless caller; is inspired by the Modulino idea: when the program is invoked as program he build up the list and also print them. This way the module can contains configuration also for non Perl programs and receive them via xargs.
    For example if you have a long find configuration in you can invoke find this way:
    perl | xargs find
    i hope you'll find it useful


    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
CPAN Namespace Navigator in Cool Uses for Perl
1 direct reply — Read more / Contribute
by Discipulus
on Nov 25, 2014 at 06:23
    CPAN Namespace Navigator is an interactive program that let you to navigate all namespaces on CPAN.
    The idea born when i read that before upload something to CPAN is better to explore existing modules, but when i asked here in the chat how to browse it i discovered that ther is not a real exploration program to do it.

    So the challenge was to hack directly the fomous file 02packages.details.txt that we receive (gzipped) when we search some module with some CPAN client. I used Term::ReadLine not without some headache.

    I decided (unwisely) to eval directly the data received to build up a big HoH with the whole hierarchy of CPAN modules and reletad infos. As suggested (wisely) by ambrus and yitzchak i looked at tye's Data::Diver and on my own at an ancient and unmaintained Data::Walker one.

    I was not able to bind Data::Diver at my will to add to the structure others infos like parent namespace or version, so i reinvented that wheel evaluating everything by myself.

    Surprisingly it worked.

    This is the usage and the navigation commands available during the navigation:
    USAGE: [02packages.details.txt] NAVIGATION: . simple list of contained namespaces .. move one level up + detailed list of contained namespaces * read the readme file of current namespace ** download the current namespace's package ? print this help TAB completion enabled on all sub namespaces by Discipulus as found at
    And here you have the code, finally crafted after 37 steps of development.


    update: take a look also at Re: Autocomplete in perl console application
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Tk Tartaglia's triangle fun - Pascal's triangle fun in Cool Uses for Perl
2 direct replies — Read more / Contribute
by Discipulus
on Jun 17, 2014 at 12:56
           Dedicated to my father who studied the other Tartaglia
    After more then one month of sparetime works and 35 subversion i'm very happy to present you:

    16 fun experiments with the Tartaglia's triangle

    This is a Perl Tk program that shows many of the properties of such incredible triangle: you can modify the aspect of the triangle itself and of the output window and of the help pages too.

    In Italy the name of the arithmetic triangle is dedicated Tartaglia so I want to present with this name.

    I'm not a mathematician and the math used in the code is something late Middle Age, but works.

    If someone wish to improve this program i will be very happy: inernal math used, better explication in output windows, or even typos spot(i'm not english native, as you can guess) or suggestion are welcome. In fact i wish this program to be used in educational context.

    Have fun!


    Update 1/07/2014: commented lines 188-190 and 555 (printing debug info for windows dimensions and positioning).


    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Tk image resizer in Cool Uses for Perl
1 direct reply — Read more / Contribute
by Discipulus
on May 05, 2014 at 07:08
    Hello monks,

    was a rainy saturday and i need some resized images for a new website (a Dancer2 one).. but i'm digressing.
    This script globs all jpg images in the current directory and creates one or more resized ones with new names. EXIF data are cleaned in new images whilst you can view some of them, for your convenience, in the preview of the original image.

    Only argouments accepted are string in the form width x heigth x descr as in 1204x768xBig
    You can specify more then one format passing, for example: 1204x768xBig 640x480xMed 200x100xMin
    The description in the string is optional: if not present is used the given ratio: 1204x768 wil be appended to the file name given.

    Using Image::Resize the ratio is maintained for the original photo, ie only the width will be used, while the height will be adjusted as needed.

    The code is redundant and somehow ugly, but Perl does not complains about this..


    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
check modules used by a script and their version in Cool Uses for Perl
2 direct replies — Read more / Contribute
by Discipulus
on Apr 03, 2014 at 06:26
    another CUFP or better WICDWMBP (what i can do with my baby Perl)..
    Reading this post i'm started wondering if there was a way to wrap an existing script and grab modules it uses without exucuting it.
    Obviously the answer or part of it was in the monastery: here
    I very liked the
    perl -d:Modlist=options perl -MDevel::Modlist=options # equivalent
    part but, unfortunately it executes the
    Also liked the tachyon-II hack, but you have to edit the and i'm too lazy.
    No hope to use $^C = 1 as pointed wisely by shmem

    The UNITCHECK do the trick! Never known it seems quite usefull for this task: read about it

    #!perl #use strict; #commented to not pollute %INC #use warnings;#commented to not pollute %INC my $file = $ARGV[0]; my $content = do { open my $fh, '<', $file or die $!; local $/; <$fh> +}; my $begin =<<'THEEND'; UNITCHECK { no strict; # access $VERSION by symbolic reference no warnings qw (uninitialized); print map { s!/!::!g; s!.pm$!!; sprintf "%-20s %s\n", $_, ${"${_}::VERSION"} } sort keys %INC; exit; }; THEEND eval $begin.$content; print $@ if $@;
    Enjoy the results!

    UPDATE 9 april 2014: BE CAREFULL, as stated by davido and also by LanX in other post, BEGIN blocks are executed anyway. In fact BEGIN blocks come first, in order of definition, then come UNITCHECK blocks and, being that block prepended to the original code in the above program, it will be executed just after the last BEGIN block and just before any UNITCHECK defined in the original program passed in via @ARGV. In the case of perl -c -d:TraceUse all the BEGIN UNITCHECK CHECK blocks are executed.

    Here two examples to demonstrate where the -c ends his operations (a simplified version of 16 pillars of wisdom):
    perl -c -e "BEGIN{print qq(1-begin\n)}; UNITCHECK {print qq(2-unitcheck\n)}; CHECK {print qq(3-check\n)}; INIT {print qq(4-init\n)}; print qq(5-main\n); END{print qq(6-end\n)}" __OUTPUT__ 1-begin 2-unitcheck 3-check -e syntax OK # the same code without -c __OUTPUT__ 1-begin 2-unitcheck 3-check 4-init 5-main 6-end
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Automatic chrome extension generator in Cool Uses for Perl
No replies — Read more | Post response
by Discipulus
on Mar 25, 2014 at 17:27
    Well, I needed to add few extensions to the browser and i ended with this...
    It generates a working chrome extension with only a context menu that acts as 'Search with <your search engine>'.

    You'll call the script with only 2 args: a_description and a partial URL
    as in Cpan_search
    Then you point chrome to chrome://extensions/, check 'Developer Mode' and choose 'Load an unpacked extension' and browse to early created folder containing the extension.

    Here is the code:
    #!/usr/bin/perl use strict; use warnings; my $folder = $ARGV[0]; my $url = $ARGV[1]; (my $descr = $folder) =~ s/_+/ /g; my $longname = 'Perl genarated extension - '.$descr; mkdir $folder or die "Cannot create $folder: $!"; chdir $folder or die "Cannot enter $folder: $!"; # the manifest open MANIF, '>', 'manifest.json' or die "Cannot open a file to write i +n: $!"; my $manifest = '{ "manifest_version": 2, "description": "'.$descr.'", "background": { "scripts": ["background.js"]}, "name": "'.$longname.'", "permissions": [ "contextMenus", "tabs" ], "version": "1.0" }'; print MANIF $manifest; close MANIF; # the jscript open JSCRIPT, '>', 'background.js' or die "Cannot open a file to write + in: $!"; my $background ='function customfunc(info) { var searchstring = info.selectionText; chrome.tabs.create({url: "'.$url.'" + searchstring}) } chrome.contextMenus.create({title: "'.$descr.'", contexts:["selection" +], onclick: customfunc});'; print JSCRIPT $background; close JSCRIPT;
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Multiplexing log output: Log4perl of the poors in Cool Uses for Perl
No replies — Read more | Post response
by Discipulus
on Oct 21, 2013 at 03:03
    The 'Cool users for Perl' is a little intimidating for this snippet..
    I was writing a program with the strictly use of core modules only and i was thinking to add the log functionality.

    I looked at Log4Perl and wow... what a suit of features!I decided to try replicate some features: first the multiplexing of the output.

    To use this you need to declare two hashes: the first is for handlers. It contains as key as you wont. Every key contains a three elements array: the glob of an already opened filehandle, the error level for this handler, and an anounymous sub to compose the final logline for this handler. Theese subs will receive two elements: the level and the message (ERROR, 'Cannot read').

    The second hash is a dispatch table that merely filter unwanted message for a particular handler.

    The small sub do an ugly cut on the incoming message and call some code for each handler defined.

    As good side note you can change the level of an handler at runtime.

    Comments and improvement welcome.

    #!perl use strict; use warnings; $|++; # open some FH you'll use, handler 0 now is the already opened STDOUT open (LOG, '>','log-multiple-output.log') || die; open (BIGLOG, '>>','biglog.log') || die; # handlers: GLOB, LEVEL, COMPOSITION SUB receiving $lvl, $msg my %loghdl = ( 0 => [ *STDOUT, 'ERROR', sub{ return $_[0]."> $_[1]\n"}, ], 1 => [ *LOG, 'INFO', sub{my(undef, undef, $line) = caller(2); return $_[0].">".(scalar localtime(time)).' "'.$_[1].'" lin +e '.$line."\n"}], 2 => [ *BIGLOG, 'ERROR', sub{my(undef, undef, $line) = caller(2); return $_[0].">".(scalar localtime(time)).' "'.$_[1].'" lin +e '.$line."\n"}], ); # the filters declaration my %wanted =( DEBUG => sub { my ($to,$dbglvl,$action) = (shift,shift,s +hift); grep (/$dbglvl/,qw(DEBUG)) ? print $to $ac +tion->(@_) : 0; }, INFO => sub { my ($to,$dbglvl,$action) = (shift,shift,sh +ift); grep (/$dbglvl/,qw(DEBUG INFO)) ? print $t +o $action->(@_) : 0; }, WARNING => sub { my ($to,$dbglvl,$action) = (shift,shift,sh +ift); grep (/$dbglvl/,qw(DEBUG INFO WARNING)) ? +print $to $action->(@_) : 0; }, ERROR => sub { my ($to,$dbglvl,$action) = (shift,shift,s +hift); grep (/$dbglvl/,qw(DEBUG INFO WARNING ERRO +R)) ? print $to $action->(@_) : 0; }, FATAL => sub { my ($to,$dbglvl,$action) = (shift,shift,s +hift); grep (/$dbglvl/,qw(DEBUG INFO WARNING ERRO +R FATAL)) ? print $to $action->(@_) : 0; }, ); ## the sub cut the head of the incoming string sub ulog { my $msg = shift; chomp $msg; (my $cmd = $msg)=~s/\s+.*//g; $msg=~s/^$cmd\s+//; $cmd = uc $cmd; foreach my $hdl (sort keys %loghdl) { exists $wanted{$cmd} ? $wanted{$cmd}->( @{$loghdl{$hdl}},$cmd,$msg) : print {$loghdl{$hdl}->[0]} 'Unknown logevel>'.lc ($cmd).' '.( +lc ($cmd) eq $msg ? '' : $msg)."\n"; } } #EXAMPLE of use ulog 'Eccolo qui'; ulog ('DEBUG debbuuuugga'); ulog ('Debug debbuuuugga'); ulog ('INFO infohere'); ulog ('WARNING warn!! you are not authorized'); ulog ('ERROR unable to read'); ulog ('FATAL cannot find Perl..'); print "\nchanging lvl to debug..\n\n"; $loghdl{0}->[1]='DEBUG'; ulog 'eccolo qui'; ulog ('DEBUG debbuuuugga'); ulog ('debug debbuuuugga'); ulog ('INFO infohere'); ulog ('WARNING warn!! you are not authorized'); ulog ('ERROR unable to read'); ulog ('FATAL cannot find Perl..');
    I hope someone can find this useful.

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Tartaglia's triangle in Cool Uses for Perl
3 direct replies — Read more / Contribute
by Discipulus
on Apr 02, 2013 at 08:02
    ok hdb have burned me on time..

    This is my first math script. Any math or Perl suggestion welcome!
    #!/usr/bin/perl use strict; use warnings; { my @tartaglia ; sub tartaglia { my ($x,$y) = @_; if ($x == 0 or $y == 0) { $tartaglia[$x][$y]=1 ; return 1}; my $ret ; foreach my $yps (0..$y){ $ret += ( $tartaglia[$x-1][$yps] || &tartaglia($x-1,$yps) ); } $tartaglia[$x][$y] = $ret; return $ret; } } sub tartaglia_row { my $y = shift; my $x = 0; my @row; $row[0] = &tartaglia($x,$y+1); foreach my $pos (0..$y-1) {push @row, &tartaglia(++$x,--$y)} return @row; } for (0..5) {print join ' ', &tartaglia_row($_),"\n"} print "\n\n"; print &tartaglia(3,3),"\n"; my @third = &tartaglia_row(5); print "@third\n";
    there are no rules, there are no thumbs..
WebTimeLoad 0.15 scan and time website using LWP::Ua in Cool Uses for Perl
2 direct replies — Read more / Contribute
by Discipulus
on Jun 06, 2011 at 05:22
    while learning few of the many things about LWP::* modules I wrote down this program to time and test websites.
    The main goal is to report the download speed of one (or more) webpage and eventually some other information. This is accomplished by running the program in the simplest way: -u
    One of other goal was to distinguish the content served by same website from content coming from outside the main site.
    The program can load not only http site but every protocol supported by LWP itself (with the -p --protocol switch). You can repeat the download using the -c --count switch sleeping as you wish between requests with the -s --sleep switch. You can control the LWP::Ua timeout with the -t --timeout switch and print the headers of the main response with the -h --header switch

    Most of the flexibility is obtained via the -v --verbosity switch: with a value of zero, the verbosity is quit null giving a one line output usefull for post processing. The next step is -v 1 which is hte default give up a short summary of the resposnse and a total of the download time. Verbosity 2 add more info about the server response and subtotals for included content.Verbosity 3 add detailed information (url, bytes, seconds) for each item downloaded.

    TODO(please help me to complete)
    • Take track of redirections
    • be exhaustive parsing the html (is body img src frame sufficient?)i'm not sure to grab background

    UPDATE: new version available below!
    UPDATE feb 2013: new version available below!

    there are no rules, there are no thumbs..
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2016-10-21 18:36 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.