Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

grinder's scratchpad

by grinder (Bishop)
on Jun 01, 2004 at 17:46 UTC ( #358312=scratchpad: print w/replies, xml ) Need Help??

Does this putative File::Watch module exist?

use File::Watch; my $w = File::Watch->new( file => '/var/run/foo', open = sub { use YAML; return LoadFile( $_->[0] ) } }; my $data = $w->get; while( 1 ) { # uses the same $data forever do_something( $data ); sleep 10; } while( 1 ) { # may the same $data forever, unless /var/run/foo changes # during the process's lifetime do_something( $w->get ); sleep 10; }

Better than Regex::PreSuf

#! /usr/local/bin/perl -w use Regexp::Assemble; my $re = Regexp::Assemble->new->add( 10..374, 376..379, 382..385, 388..499, 530..534, 541..543, 618, 619, 700..704, 707..709 ); % ./ra (?:3(?:7[012346789]?|8[234589]?|0\d?|1\d?|2\d?|3\d?|4\d?|5\d?|6\d?|9\d +?)|1(?:0\d?|1\d?|2\d?|3\d?|4\d?|5\d?|6\d?|7\d?|8\d?|9\d?)|2(?:0\d?|1\ +d?|2\d?|3\d?|4\d?|5\d?|6\d?|7\d?|8\d?|9\d?)|4(?:0\d?|1\d?|2\d?|3\d?|4 +\d?|5\d?|6\d?|7\d?|8\d?|9\d?)|5(?:[01256789]|3[01234]?|4[123]?)|7(?:[ +123456789]|0[01234789]?)|6(?:[023456789]|1[89]?)|8\d|9\d) % ./ra | wc -c 335

And if I add something like japhy's List-to-Range generation it would be even shorter. Context: Matching data against non-consecutive range (and in particular bart's |reply).

Mystery package

Does the following beast Thing exist?

my $foo = [ 1, [2, 3], [4, [5, 6, 7]], ]; my $path = Thing->new($foo); while( defined( my $p = $path->next )) { print join( ' ' => @$p ), "\n"; } __PRDDUCES__ 1 2 4 5 1 2 4 6 1 2 4 7 1 3 4 5 1 3 4 6 1 3 4 7

Auto-refreshing an image (or two) in an HTML page

<head> <script language="javascript"> function refresh_thumbs() { if (!document.images) return; var now = new Date(); document.images['oleane-th'].src = 'oleane-thumb.png?' + now.get +Time(); document.images['completel-th'].src = 'completel-thumb.png?' + now. +getTime(); setTimeout('refresh_thumbs()',5000); } </script> </head> <body onLoad=" setTimeout('refresh_thumbs()',5000)" bgcolor="#ffffff"> <img border="0" name="oleane-th" src="oleane-thumb.png"/><br /> <img border="0" name="completel-th" src="completel-thumb.png" /> </body></html>

Scanning Oracle user tables

#! /usr/bin/perl -w use strict; use DBI; use constant DBI_AGR => 'dbi:Oracle:agrtest'; my $table = shift; my $dbo = DBI->connect( DBI_AGR, 'foo', 'bar', {PrintError => 1} ) or die "Couldn't connect to @{[DBI_AGR]}\n"; #foreach( $dbo->tables ) { # print "$_\n"; #} #print "\n"; my $typeinfo = $dbo->type_info_all;; my $tnames = shift @$typeinfo; my %typenames; foreach( %$tnames ) { $typenames{$tnames->{$_}} = $_; # print "$_ => $tnames->{$_}\n"; } if( !defined $table ) { print join( "\t" => @typenames{sort {$a<=>$b} keys %typenames} + ), "\n"; my $nr = 0; foreach my $ti( @$typeinfo ) { print $nr++; foreach my $t( @$ti ) { print "\t", $t ? $t : 'undef'; } print "\n"; } } my $sth = $dbo->table_info; while( my $d = $sth->fetchrow_hashref ) { if( defined $table ) { next unless uc $table eq uc $d->{TABLE_NAME}; } print "$d->{TABLE_NAME}\t$d->{TABLE_TYPE}\n"; my $sdump = $dbo->prepare( "select * from $d->{TABLE_NAME}" ); if( $sdump->execute ) { my $names = $sdump->{NAME}; my $types = $sdump->{TYPE}; my $nr = $sdump->{NUM_OF_FIELDS}; for( my $n = 0; $n < $nr; ++$n ) { print "\t$n\t$names->[$n]\t$types->[$n]\n"; } } $sdump->finish; print "\n"; }

User search trickery

Nowadays only of historical interest

my @friends = ("merlyn","nate", "vroom", "neshura", "chromatic", "seta +ntae", "btrott","stephen","lhoward","ZZamboni","kudra","tilly","cogen +t"); my $friend; $friend ||= $friends[rand(@friends)]; $query->textfield("usersearch", $friend);

Using syslog

#! /usr/bin/perl -w use strict; use Sys::Syslog; use File::Basename; openlog( basename($0), 'pid', 'daemon' ); syslog('err', 'this is a test'); closelog();

That doesn't work, why?

Murphy's law, the fitness of evolving species, and the limits of software reliability

the article
the author's homepage

A whole mess of Perl Monks links

I keep planning to organise these bookmarks into some useful order, but I don't think it will ever happen. I'm not even sure why I bookmarked half of them...

User Settings
Best Nodes
Worst Nodes
Perlmonks Navigator
Message Inbox
Re: make / Makemaker trouble
The fickleness of Reputation
I think I saw it move!
Extending object you don't create
Timing out shell commands (paranoia)
my $var = ''; vs. use constant VAR =&gt; '';
Assemble times into ranges
(very silly) BOFH::Easy (instantiated in Net::Telnet)
This is not a flame
Voting/Experience System
Re: threaded display of replies
Unix text-mode CB Client
HP Jet Direct Control
(Genetic) Perls of Evolution
/msg me for new nodes in a thread I noded in
This is not Flamebait
Electronic Pricetag Alteration
Personal Nodelet Extractor
Net::FTP Wrapper: TCP problem
Re: Ways of Passing Configuration Parameters
CPAN Mirror locator
Tricks with DBI
java chatterbox
Re: Reactionary Coding—One-Shot Programs
Code Smarter
Nodes To Consider
Parsing your script's command line
The Perl Film Festival
Creating a perlmonks node grabber
local scoped cwd
The Center of PerlMonk Mass
Super Search
A better non-existant string...
Rabin Miller
Replies and previews.
hup - home node updater
More Fun with Zero!
Adding 2 + 2
Weird Warning
Higher level posts
Proposed XP System Changes
Fish dinner
Borg's Belly
is 'my' that much faster than 'local'?
SPAM eater
Random NonHome Nodes
The zen of code blocks
Cheesy Webring
On-demand single-pixel GIFs
pmdev task lister
pmdev wiki
scratch pad viewer
Why I hate File::Find and how I (hope I) fixed it
Most Visited Nodes
Win32::OLE Type Library Browser
Array vs. Hash (newbie perlguts)
Votes in the pool
The Dynamic Method Calls Strike Back
Dynamic Method Calls
Shakespeare Programming Language
Perl Bug in Regex Code Block?
Separating big numbers with commas
pm-port wiki
Data::Dumper Efficiency Problem
Grabbing XML from PerlMonks
Hex dump
neat little win32 freeware utility
RE: My favorite sodapop is...
Extreme Programming Frightens This Perl Programmer
Sorting ip addresses quickly
Compare2Files LinebyLine
Input button question
DisplayType Raw

The end :)

XML::Twig handlers weirdness?
Problems with IPC::Run module on Windows XP
Crossword Puzzle
Secret Perl Operators: the boolean list squash operator, x!!
Better keyboard-driven navigation, any? - yes...
Randomize an array
spiraling quine
3-D Stereogram, Self replicating source.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2022-09-30 19:16 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (126 votes). Check out past polls.