blue_cowdawg has asked for the wisdom of the Perl Monks concerning the following question:

Disclaimer: This is my first attempt at playing around with jZed's module DBD::AnyData so my understanding of "the way it works" may well be flawed.

That said, I was inspired to start playing around with DBD::AnyData after a short exchange between myself and jZed. So, I wrote a seriece of quick little ditties to get myself familiar with it and with this code:

#!/usr/bin/perl -w ###################### use DBI; use strict; my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):') or die $DBI::errstr; $dbh->func('CSV',[<DATA>], 'XML','animals.xml', 'ad_convert'); __END__ animal_id,animal 1,bear 2,lion 3,tiger
ran into an issue. Running that code it seems to go off into "the weeds" and never return. A zero length file "animals.xml" results. I expected the file, but I expected content.

Is my undertanding flawed? Is there an undocumented feature? Has Elvis invaded my laptop?

Replies are listed 'Best First'.
Re: Interesting issue with DBD::AnyData?
by jZed (Prior) on Nov 17, 2005 at 17:48 UTC
    Looks like the XML convert is hosed, it works with other formats, I'll look into it, sorry.
          Looks like the XML convert is hosed,

      OK, so who is this guy in the sequined suit hanging out in my laptop? :-)

      Let me know and I'll Beta test the fix!


      Peter L. Berghold -- Unix Professional
      Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Interesting issue with DBD::AnyData?
by idsfa (Vicar) on Nov 17, 2005 at 20:42 UTC

    I think you've been flock blocked.

    The code is hanging trying to get an exclusive flock on the output filehandle (well, IO::File). I'm not entirely sure why this is so, but I am confused by this line at the top of AnyData::Storage::File:

    use constant HAS_FLOCK => eval { flock STDOUT, 0; 1 };

    Which to me looks like it would always return 1. If I remove the '1' from that definition, your program works, but that '1' is in all of the versions on CPAN, so I probably just don't understand constants flock. Of course, you'd never see this as a problem if your perl implementation supports flock ...

    Updated: To expand on jZed's explanation, the flock fails fatally when flock is not supported. eval catches this and returns undef. I was mistakenly thinking it failed and continued. I flock-ed up.


    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
      use constant HAS_FLOCK => eval { flock STDOUT, 0; 1 };
      
      If the flock fails, eval will return undef. If it succeeds, eval returns 1.

        Cool. Figured I wasn't understanding, thanks for the explanation. Still, the exclusive flock in open_local_file is where it is hanging, so I think there is something odd there.


        The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon