notes

There are notes or example code pieces for historical purposes

data url

#!c:\usr\bin\perl.exe -w use MIME::Base64; use open IN => ':raw', OUT => ':raw'; binmode STDOUT; our %mime = ( 'gif' => 'image/gif', 'svg' => 'image/svg+xml', 'png' => 'image/png', 'ico' => 'image/x-icon', 'txt' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html', ); foreach $file (@ARGV) { local $/; $file =~ m{\.([^\.]*)$}; my $ext = $1 || ''; open(my $fh, '<', $file) or die $!; binmode $fh; print "data:" . ($mime{$ext}||'application/octet-stream') . ";base64," . encode_base64(<$fh>, ''); close($fh); }

base64

enocde64.pl

#!c:\usr\bin\perl.exe -w use MIME::Base64; use open IN => ':raw', OUT => ':raw'; binmode STDOUT; local $/; print encode_base64(<>);

decde64.pl

#!c:\usr\bin\perl.exe -w use MIME::Base64; use open IN => ':raw', OUT => ':raw'; binmode STDOUT; local $/; print decode_base64(<>);

findPerlMod

#!perl -l die "usage:\n\t$0 Perl::Module::One [Optional::Perl::Modules...]" unless @ARGV; foreach (@ARGV) { my $k = $_; $k =~ s{::}{/}g; $k =~ s{(?<!\.pm)$}{.pm}i; # this will add .pm to the end, unless it's already there... [perldoc perlre # zero-width engative lookbehind] eval{require $k} unless exists $INC{$k}; unless(exists $INC{$k}) { print "$_ => {could not find $k}"; next; } (my $v = $INC{$k}) =~ s{/}{\\}g; print "$_ => $v"; }

used modules?

This script allows me to find the perl modules that I'm actually using in some set of directories

#!perl use 5.012; # strict, // use warnings; use Path::Tiny; my @modules = map { s/^.*?"Module" //r =~ s/[\r\n]+$//r } <DATA>; # print for @modules; my @search_folders = map { path($_) } qw( c:/usr/local/scripts c:/usr/local/share c:/usr/local/share/sandbox c:\users\peter.jones\downloads\tempdata ); my %used; for my $p ( @search_folders ) { my $iter = path($p)->iterator({recurse=>1, follow_symlinks=>0}); while( my $entry = $iter->() ) { next if $entry =~ m(\.svn/); next unless $entry =~ m(\.p[lm]$)i; #print "$entry\n"; for(grep { m(^\h*use) } map { split /;/, $_ } grep { m(^\h*use) } $entry->lines({chomp=>1})) { s/#.*$//; s/^\h*//g; s/\h*$//g; m/use\h*('.*?'|".*"|.+?)(?:\h+(.*)$)?$/ and do { push @{ $used{$1} }, "$entry"; }; } } } use Data::Dump; #dd \%used; for my $module ( @modules ) { local $\ = $/; #dd $module, $used{$module}//'' if exists $used{$module}; print $module if exists $used{$module}; } # grab the results of `perldoc perllocal`, # then strip out all the ones to perl\lib and perl\vendor\lib (which were installed by strawberry) # leaving only ones with perl\site\lib # Paste the results in the _DATA_ section: __DATA__ Tue Nov 2 19:05:39 2021: "Module" WWW::KeePassRest ...

win32log

To get logging to "common areas" in Win32:

Event Viewer
Sys::Syslog:
  • $ident: This is the "source" column of Event Viewer
  • $logopt: string of comma-separated tokens
    • ndelay: no delay before connecting
    • pid: seems to be irrelevant to Win32
    • perror: seems to be irrelevant to Win32
    • example: ndelay,perror
  • $facility: use :macros LOG_xxx constants or string
    • LOG_USER / "user": generic (Event ID = 157)
    • LOG_SYSLOG / "syslog": syslogd (Event ID = 133)
    • LOG_LOCALn / "localn": local, with n ∈ [0..7] (Event ID = 140..147)
  • $priority: use :macros LOG_xxx constants or string
    • LOG_DEBUG / LOG_INFO: 🛈 Information
    • LOG_NOTICE / LOG_WARNING / LOG_EMERG: ⚠ Warning (LOG_EMERG should really be below)
    • LOG_ERR / LOG_CRIT / LOG_ALERT: Error
Log::Any::Adapter::Syslog: uses Sys::Syslog in a Log::Any environment
Event Viewer:
  • Go to the Windows Logs > Application tab
  • Filter Current Log: Last Hour (custom sources don't appear to be in Event Sources filter)
OutputDebugString()Sysinternals DebugView
Win32::OutputDebugString($string)
DbgView64.exe
  • Include: use some common string (prefix, etc) in the OutputDebugString() call, and filter on that
  • Exclude: matches to ignore
  • Highlight: there are 20 different search terms, with each getting its search expression in the colored dropdown

debug in notepad++

the conversation here made me think about Perl+DBGp in Notepad++ again, since there's a x64 build of the plugin now. I tried to get it to work based on Michael Vincent's old x86 instructions in his blog, but trying with the perl5db.pl that ships with Strawberry Perl, but it wouldn't actually pause. However, grabbing a 32-bit NPP and following his pm version of the instructions exactly, I was able to get it to work.

So I then took that modified perl5db.pl and DB subdirectory into the x64 NPP, and took the hint from @rdipardo's repo for the x64 plugin which said that the port changed from 9000 to 9003, and with those changes, a hello-world script would actually pause:

set PERL5LIB=C:\Program Files\Notepad++\plugins\PerlDebug set PERLDB_OPTS=RemotePort=127.0.0.1:9003 REM Plugins|DBGp|Debugger|TurnON perl -d tryNppDebugger.pl

The perl correctly launches but doesn't return to command line, and I'm able to single-step through and see variables.

However, I don't like that I have to "borrow" from Komodo source code to get that DB directory. Some searching found Devel::Debug::DBGp. Looking through their source, they might still have the CDATA fix in DB\DBgrProperties.pm, but don't appear to have the context_id/context; and the perl5db.pl fixes seem to already be there. Unfortunately, trying to install that module and its dependencies fails for me -- cpantesters shows no installations in win32, so blech. (The DBGp::Client test suite failed, and when I --notest on that one, the Devel::Debug::DBGp won't compile its XS correctly. The DBGp::Client has never passed on >perl5.24, and that only on 0.06 compared to 0.12 recent release -- thus, I don't think getting it to install is likely.) I might be able to just extract the non-XS bits.

Tried with the non-XS bits: modified the DB\DBgrProperties.pm, and found that it mostly worked, but has the "local context" that Michael had mentioned, which the context_id/context change had fixed. There we go: DB\DbgrContext.pm has a context_id="%d" -- change it to context="%d" and now the context works correctly, and it can debug. Hurrah!

win32::gui notes

- Overhead and border: x:(16,10), y:(39,10) - Fonts: create new font through my $f=Win32::GUI::Font::->new(), and attach it as attribute of its parent window $win->{_attach_font} = $f; (so it doesn't go out of context as it is running) - ENTRY boxes are Textfield() objects - Combobox and Textfield should be 21 high with default fonts, and Label needs vertical offset of 4px to align text in the Label with text in the Textfield or Combobox - Combobox (https://learn.microsoft.com/en-us/windows/win32/controls/about-combo-boxes) -simple ⇒ Always shown down ("Displays the list at all times, and shows the selected item in an edit control.") -dropdown ⇒ drop down, and editable ("Displays the list when the icon is clicked, and shows the selected item in an edit control.") -dropdownlist ⇒ drop down, but not editable ("Displays the list when the icon is clicked, and shows the selected item in a static control.") - Win32::GUI::Grid and Win32::GUI::AxWindow can only be compiled if using MSVC to compile, instead of Strawberry's mingw gcc, so don't get those with Strawberry installations.

page look-and-feel inspired by lifehacker.me