Get a quick snapshot of the quantity and structure of elements in an XML file -- useful for getting acquainted with some new XML source, or for confirming expectations about XML data you created. (Yes, it is worthwhile to use XML::Parser in a one-liner...)
Creates a dialog box that enables the user to select a folder.
This small procedure is part of a larger programm that lets you choose a directory and manipulate its contents i.e combines nicely with File::Find
Cisco IOS-XR introduces a new prompt format that is "breaking" Net::Telnet::Cisco. Basically, the Route Processor and CPU instance is added with a colon ":" before the router hostname. I was wondering why my Telnet sessions were "failing" but the logs showed they connected and got the prompt.
I looked for an update to Net::Telnet::Cisco, but the latest version I could find was 1.10, which is what I have installed. To get around this, I used the -prompt option when calling Net::Telnet::Cisco->new() from my script.
Under the "sub new" procedure in Cisco.pm, I found the existing prompt regex (you can't miss it). I copied that code and added the new piece and passed that in when I make the Net::Telnet::Cisco->new() call via the "-prompt" option. (See Net::Telnet for more info.)
All we're doing is adding a check for the Route Processor and CPU instance and colon before the hostname - optionally, so we don't break what's currently working. This is done with the addition of:
Not all templating systems are string-oriented. HTML::Seamstress is not.
It works with HTML::Element instances.
As such, it would be nice if the result of filling in the form could be
returned as a tree for further processing by HTML::Element methods.
As it stands, I am forced to parse the results of HTML::FillInForm back
into a tree (even though it was a tree before HTML::FillInForm
Now, just consider how much is being done.
seamstress has an HTML tree that it wants the form filled in on
seamstress converts this to a string
FillInForm parses the string into an HTML tree and then fills in the form
FillInForm converts the HTML tree to a string
seamstress re-parses the HTML for additional processing
If FillInForm could receive and return trees, my apps would be much faster.
For the time being, I at least need to turn this multiline process into a single function call, so here it is.
fp does not have a scanl function. I considered contributing
this code to it, but am turned off by the semantics of the
reduce function... I think that would be better named
behead. It also potentially conflicts with List::Util in that
So here we have the scanl function, a staple of functional
programming, available in standalone fashion. As you can see, it
behaves the same as scanl
Browser caches are interesting places. Firefox, in particular, has many files all with intuitive names like 'FA509DE4d01', and no extensions. Fortunately Unix culture has a method for bringing order to this chaos: 'magic' databases, or files containing bytes found in particular types of files. These allow you to guess a file's type based on its contents. Perl provides 'magic' support in the form of File::MMagic, and the following one-liner uses it to print the guessed types of all files in the current directory.
(Update: typo, and removed useless Data::Dumper)
I use PuTTY tools from a Perl script, in particular pscp (PuTTY scp), and I use Pageant for automated authentication, so that I don't have to type in my password for every single file to transfer.
But my Pageant uses a password to its vault, too. So Pageant must already be running and ready before I attempt to scp files, or I still have to type in my password, every time, manually.
And that's where this snippet comes in. It tries to start up Pageant, waits till it comes back and/or until you typed in the password and pressed return, and only then resumes.
I use Win32::Process to launch Pageant, and one of 2 things may happen:
Pageant wasn't running and it will pop up a login dialog box asking for the password. And then, after the dialog box closes, the process will continue running in the background, with an icon in the systray. If you Wait for that process to finish, you can wait for a very long time...
Pageant was already running in the systray and the process immediately exits.
So, what does the snippet do?
It reads the parameters to launch Pageant with from a Windows shortcut file (*.lnk file) — You may skip this part.
It launches Pageant using Win32::Process, and it waits for 2 seconds for it to finish. So, in case (2) it'll immediately return, but in case (1) it'll give the program enough time to show its password dialog window.
It uses Win32::GuiTest to see if the password dialog is still up, and polls, and waits until it closes.
I've a few good friends who like Python a lot (yes it is a nice Language, but I like Perl more). One difference is, that you can program in Python without using semicolons. Well, this is possible using the Perl language too, like the following code demonstrates it (it calculates fibonacci numbers, however without use strict). I don't tell, that you will have any benifit by not using a semicolon. But I think this is a funny way of programming in Perl. Enjoy :)
I was thinking if there any chance to write an accessor in just one line, and I came up with the following code. Of course I wouldn't use in a real project because its unreadable but it might worth sharing. The good thing is just replacing subroutine name creates a new accessor.
So I'm getting married in October, and I started thinking about wedding vows, and so I wanted to get a better feel for what other people spend most of their wedding vow-ing time talking about. Here's a little script that came out of that effort. It takes a text file full of wedding vows (which you'll have to provide for yourself) and prints the text's triptycs.
This dumps the contents of a Judy::HS/JudyHS(3) array. I had to violate its API to do this. JudyHS is constructed as nested Judy::L/JudyL(3) arrays. The top level encodes the string length. The next level encodes a hashing. Each additional level encodes another 4 or 8 bytes of the input string until no more are needed and it terminates in a C struct which contains the key and value.
The below example loaded Judy::HS with a map from string to line number. It's completely arbitrary and I did it just to demo to myself that I could enumerate the contents of Judy::HS if I needed to.
Judy.h in the Judy C library has a nice, readable description of the structure that's being dumped here.
Recently, I was thinking about that example in the docs where they demonstrate a method for inserting commas into a numerical string. Now, I realize that they're trying to illustrate a specific mechanism with regexes... but that thing is just clumsy and awful and obfuscated for any Perl beginner. So, just for my own entertainment, I decided to see how I'd do it "for real" - i.e., in the best way possible rather than by this contrived method.
Herewith, humbly, I present a couple of options. :)