Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

runrig (3385)

runrig
  dougwNO@SPAMcpan.org

Just another perl hacker somewhere near Disneyland

I have this homenode [perlmonks.org] of little consequence on Perl Monks [perlmonks.org] that you probably have no interest in whatsoever.

I also have some modules [cpan.org] on CPAN [cpan.org] some of which are marginally [cpan.org] more [cpan.org] useful [cpan.org] than others.

Journal of runrig (3385)

Sunday September 28, 2008
12:18 PM

PowerCenter XML

Everyone I talk with says that mucking with the XML exported by Informatica's PowerCenter is not recommended, or that they tried and failed...so I had no choice but to ignore that advice when we were upgrading from version 7 to 8. I think the advice must be from people who don't quite know what they're doing, and/or "parse" with grep/awk/sed.

I've been messing with more XML in the last few weeks than I have in the last few years. I have my own (shared) opinion about Informatica/ETL (and I've taken up Aristotle's call to action), but at least it provides an opportunity to practice some XML-fu. Most transformations were simple changing of some attributes, but there was one issue where after importing into v8, if you delete a group from a Union transformation, the GUI crashes. So I created a Union transformation from scratch, exported it, and compared it to what I was importing, and hey, there was some stuff missing! So I wrote the following:

  # Fix Union transformations
  my $union_cnt;
  for my $trans (
    $root->findnodes(q[
      //TRANSFORMATION[@TYPE="Custom Transformation" and @TEMPLATENAME="Union Transformation"]
    ])
  ) {
    $union_cnt++;
    my $name = $trans->getAttribute('NAME');
    my $parent = $trans->parentNode();
    print "X: Fixing Union transformation $name\n";
    my @output;
    for my $field (
      $trans->findnodes(q[
        TRANSFORMFIELD[@GROUP="OUTPUT"]/@NAME
      ])
    ) {
      push @output, $field->value();
    }
    my %dep;
    my $dep_cnt;
    for my $field (
      $trans->findnodes(q[
        TRANSFORMFIELD[@PORTTYPE="INPUT"]
      ])
    ) {
      my $name  = $field->getAttribute('NAME');
      my $group = $field->getAttribute('GROUP');
      my $dep_group = $output[$dep{$group}++];
      my $new = $trans->addNewChild( '', 'FIELDDEPENDENCY' );
      $new->setAttribute( 'INPUTFIELD', $name );
      $new->setAttribute( 'OUTPUTFIELD', $dep_group );
    }
  }
  $_->unbindNode() for $root->findnodes('//text()');

Warning: this code is not endorsed or guaranteed by anyone for anything!

The removing of all text nodes was so that the result would stay pretty-printed after output (is there a better/easier way?):

  eval { $doc->toFile($file, 1) } or die "Could not write to $file: $@";

And there are no text nodes with anything but whitespace anyway. XML::LibXML seemed hard to use at first, but once you get used to how the docs are arranged (and learn some XPath), it's quite easy.

11:46 AM

Suck followup

It may not have been blogged about in the most diplomatic way, but to follow up on my previous post, I followed btilly's diplomatic advice pretty much, and found out that the code was written by a college intern, who was now gone, but a couple of other developers were now reponsible for maintaining (or rewriting) it, and were glad to get some advice and feedback.
Friday August 08, 2008
09:17 PM

You suck or silence?

When someone posts a "utility" on the company intraweb, and it's perl, and it's about 900 lines long, with no strict or warnings, has no indentation, needlessly builds strings and splits to an array when qw() would've been appropriate, needlessly uses ".*" in regular expressions, (mis)uses subroutine prototypes, has lots of repeated code that could be factored into subroutines, and lots of other things you'd expect to see in the sort of code that has all the previous issues, and you've already written a library to do the same thing and more (in fewer lines...though slightly more if you count the documentation), what do you do?
Friday July 25, 2008
06:00 PM

Novell Netware checksum

Dear lazyweb,

When I rightclick on a file on my work Windows system and go to File-Properties, there's a "NetWare Version" tab which has a "View Version, Copyright, and Check Sum Info" button. When you click that, you get a 48-bit checksum of the file in hex. Does anyone know how this checksum is calculated, or even how to find an external exe to run (or a dll and how to use it) to get this value? I've tried comparing the value against as many known checksum algorithms as possible before tearing my hair out.

Update: and why I want this? We are currently required to enter this value into some document, and the only way to cut n paste it is via screen copy...you can not copy just the text.

Update: nevermind...we have switched to using Jacksum.

Saturday June 28, 2008
08:05 PM

So long its been good to know you

The internet is a strange universe where we mostly know one another (or don't really know one another) through bits and bytes and blog entries and email. It was through PerlMonks that I first knew of VSarkiss, and found that he lived relatively nearby, and we met up once. It was about a year ago (more or less) that he came to be working at the same place I was through a different consulting agency (though it's a big company so I didn't see him much). Then he disappeared, I emailed him and never heard back, and finally just recently I got around to asking someone about him, and was told that he passed away. So long Vahe... :'-(
Friday March 14, 2008
04:53 PM

Building perl and libs on HP-UX

I must keep this somewhere in one place semi-permanent...boring stuff plus hoops to jump through to get XML(LibXML and LibXSLT), and DBD::Oracle and DBD::Sybase working on HP-UX (I have no explanation for having to run 'perl Makefile.PL' over and over). I don't remember if I needed to use 'chatr' to change some of the shared libraries to get them to load:

----------------------------------------
Notes on Building perl 5.10.0 and various
libraries on HP-UX (11.11)

All of the following was installed under
/users/foo
Adjust all prefix parameters accordingly
to install in another directory (or remove
to install in default location).
----------------------------------------

First perl itself:

> which cc
must be /opt/softbench/bin/cc compiler
(default HP /usr/bin/cc compiler will not work)
(gcc compiler can work, but everything here was done
with softbench compiler).

# Add prefix to install in non-standard path
sh Configure -Dprefix=/users/foo

keep default of building non-threaded perl, but
add '-lcl -lpthread' to beginning of libraries to include.
(So that DBD::Oracle will build dynamically later).

make
make test
make install

----------------------------------------
XML::LibXML and XML::LibXSLT:
----------------------------------------
First install shared libraries:

install binaries of zlib(libz), iconv, and gettext
libraries, unless you really feel like building them
(install in local directory if necessary..e.g./users/foo/lib
and include files in /users/foo/include).

Build source for libxml library:
Set env variables:
export CC=cc
export LDFLAGS="-L/users/foo/lib -I/users/foo/include"

./configure --prefix=/users/foo --without-threads --without-thread-alloc --with-iconv=/users/foo --with-zlib=/users/foo

make
make install

# Fix permission on config info file:
chmod +x /users/foo/bin/xml2-config

----------------------------------------
Build source for libxslt library:
Set env variables:
export CC=cc
export LDFLAGS="-L/users/foo/lib -I/users/foo/include"

./configure --prefix=/users/foo
make
make install

# Fix permission on config info file:
chmod +x /users/foo/bin/xslt-config

----------------------------------------
Build source for XML::LibXML::Common:
perl Makefile.PL
  (doesn't always work first time..repeat until Makefile is created)

make
make test
make install

----------------------------------------
Build source for XML::NamespaceSupport:

perl Makefile.PL
make
make test
make install
----------------------------------------
Build source for XML::SAX:

perl Makefile.PL
make
make test
make install
----------------------------------------
Build source for XML::LibXML:

perl Makefile.PL (repeat until Makefile is created)
make
make test
make install
----------------------------------------
Build source for XML::LibXSLT:

Change the following lines (this might be fixed in a future
version):
#xsystem("$Config{make} $file test 'OTHERLDFLAGS=$opt'");
xsystem("$Config{make} $file test");

#$result = try_link(<<"SRC", $libs);
$result = try_link(<<"SRC", undef);

perl Makefile.PL LIBS=-L/users/foo/lib INC="-I/users/foo/include -I/users/foo/include/libxml2"
make
make test
  (a couple of tests, e.g. exslt tests, will fail, install exslt library
  if you need exslt)
make install
----------------------------------------
Build source for DBI

perl Makefile.PL
make
make test (many tests are skipped)
make install
----------------------------------------
Build source for DBD::Oracle (1.20)

perl Makefile.PL

edit Makefile:
# Look for
$(LD) -Wl,+b"$(LD_RUN_PATH)"  $(LDDLFLAGS) $(LDFROM) $(OTHERLDFLAGS) -o $@ $(MYEXTLIB)  \
# Remove "-Wl,"
$(LD) +b"$(LD_RUN_PATH)"  $(LDDLFLAGS) $(LDFROM) $(OTHERLDFLAGS) -o $@ $(MYEXTLIB)  \

make
make test
  (many 'connects' fail unless you set env vars for a test db)
  (many charset tests skipped on old versions of Oracle)
make install
----------------------------------------
Build source for DBD::Sybase (1.08)

Edit Sybase.pm:
# Look for:
sub dl_load_flags { if($^O eq 'aix') { 0x00 } else { 0x01 }}
# Change to:
sub dl_load_flags { if($^O eq 'aix') { 0x00 } else { 0x00 }}

update: patch to display line numbers on RaiseError:
*** ../DBD-Sybase-1.08/dbdimp.c Thu Apr 19 11:31:19 2007
--- dbdimp.c    Thu Jun 19 14:09:45 2008
***************
*** 545,550 ****
--- 545,551 ----
        else
            retcode = CS_SUCCEED;

+       sv_catpv(DBIc_ERRSTR(imp_dbh), " ");
        return retcode;
      } else {
        if(srvmsg->msgnumber) {

perl Makefile.PL (prompts for test server/db and user/passwd)
make
make test
make install

Thursday February 28, 2008
02:40 AM

Hey buddy

I received a pleasant surprise when I got home today. "Close your eyes and hold out your hands," my wife and daughter said. A new CD. For me :) And I'd never heard of it. I really like Ry Cooder, but I haven't been paying attention lately to what he's been doing, so My Name Is Buddy was a complete revelation. It's great...there's a song about a pig named J. Edgar Hoover (uh huh, it's just about the pig, yeah, right). There's a socially relevant story line about a cat, a mouse, and a toad...but I'm just going to enjoy the music for the first 3 or 4 or 7 listens. And it's got two (count'em!), Two Seegers playing on the album. And in a great confluence of synergistic coincidence, there was a great show on PBS tonight about Pete Seeger ("The Power of Music"). If anyone can stop a war with a banjo, he can :-)
Thursday February 21, 2008
12:39 PM

Local "network" printer

My wife just bought a Dell laptop with Windows Vista...the Desktop is Windows XP with a printer connected directly to it, and the printer was configured to be "shared". Tried to get the printer working from the laptop...click "add a printer", then "Is this a local or network printer?". Well, it's on the network, it sure doesn't seem local, but the network discovery thing doesn't find it, and you get "Access Denied" when trying to connect to it. Google, google, and low and behold, it's really a "local" printer, though you do give it the "\\systemname\printername" path in one of the entry fields.

Very intuitive. Also, the salesman who was trying to sell us another printer when buying the laptop was telling us "the old printer probably won't work...there probably no printer driver for Vista...". BS.

Of course, my wife needed something printed out right now because she was going out right now, and another option was to export the Word document to PDF, and email it to ourselves and print it out at the other computer. But Word didn't natively export to PDF, you had to install a Microsoft Plug-in for that, and you needed the "validation code" that came with word to install it, and we didn't have that handy. Eventually, I did also install PDFCreator, but that was around the same time I found out about the "Local Printer" thing.

What would we do without the internet? Spend useless hours on hold with Technical Support probably.

Friday January 18, 2008
07:15 PM

XSLT sort puzzle

Following up on previous XML sorting efforts, where I mostly wanted to sort by tag name, then by NAME attribute, but for some elements, there were other attributes that I wanted to sort by. I first did the tag_name/NAME_attribute sort with XML::Filter::XSLT then sorted by the other odd elements using XML::Filter::Sort.

Out of curiosity, I wanted to try to do it all with XSLT, so I came up with:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">

<xsl:output method="xml" version="1.0"
encoding="iso-8859-1" indent="yes" omit-xml-declaration="no"/>

<xsl:template match="/">
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="//*">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>

    <xsl:apply-templates select="D">
      <xsl:sort select="@FOO"/>
    </xsl:apply-templates>

    <xsl:apply-templates select="*[not(self::D)]">
      <xsl:sort select="name()"/>
      <xsl:sort select="@NAME"/>
    </xsl:apply-templates>

  </xsl:copy>
</xsl:template>

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Which sorts "D" elements by the FOO attribute, and everything else by tag name then NAME attribute. The difference between this and my previous method is that now "D" tags will come before "A" tags (and any others), whereas before they were still sorted by tag name. I think I can get the former two-pass approach behavior in one XSLT document, but for now, it's more trouble than it's worth. It would be easy if you could define a sort callback function.... :-)

Sunday December 30, 2007
06:45 PM

Burnin' Vinyl

Today is the day I'm glad I never got rid of all my vinyl. Though I haven't heard any of it for about 12 years, I've managed to to hang on to most of it...and the irony is that although my wife is the one who has encouraged jettisoning the records, she's the one who gave me the turntable w/the USB connection (big thank you to you dear).

So, what to record first? A while back, I did sell my copy of Generic Flipper, and I'm still kicking myself for that, though I do still have Public Flipper Limited, but that's not exactly a family friendly album (I'll record that one some late night or when no one's home). I've also got some 78's of Yehudi and Hephzibah Menuhin playing Beethoven's Sonata No. 9 in A (Op. 47 "Kreutzer Sonata"), but I don't yet have a 78 needle, so I'll leave that one for now. And besides, Amazon seems to have it, though I'm not sure if their 6:48 version is what I have (what is the play time of 4 78 disks anyway?).

So first up on the platter is Jon and the Nightriders, which seems to have been never released to CD, though it's the greatest surf album ever recorded...IMHO :-) Hmmm, if it says on the album "Unauthorized copying, hiring, lending, public performance, and broadcasting of this record would be appreciated", I wonder if that includes permission to post one or two tunes on YouTube? Well, until I figure that out, this disk join my other two new disks/presents in heavy rotation on my car stereo...Moby Grape(Listen My Friends) and Cowboy Nation(Journey Out of Time).