Carl,
When I tried it just now (first time using DBD::CSV) it just worked as I
would expect.

First, here's my script that I named test.pl:
#!/bin/env perl
use strict;
use warnings;

use Data::Dumper;
use DBI;
use Try::Tiny qw( try catch );

my $dbh = DBI->connect( 'DBI:CSV:', '', '', {
    f_schema => undef,
    f_dir => '.',
    f_ext => '.csv/r',
    RaiseError => 1,
    PrintError => 0,
}) or die "Cannot connect: $DBI::errstr";

my $test = try {
    return $dbh->selectall_arrayref( 'select * from test' );
}
catch {
    my $err = $_;
    if ( $err =~ m!^.*DBD::CSV::db.*?Execution ERROR: (.*?) at
.*?DBI/DBD.*?line \d+.*?called from (.*? at \d+)\..*?$!s )
    {
        my ( $msg, $where ) = ( $1, $2 );
        warn "$msg -- $where\n";
    }
    else
    {
        warn "$err\n";
    }
    return {};
};

print Dumper( $test );
__END__

Here is my test.csv file:
id,value
a,1
b,2
c,3

When I run it with test.csv (whether or not it is open in Excel) I get this
output:
$VAR1 = [
          [
            'a',
            '1'
          ],
          [
            'b',
            '2'
          ],
          [
            'c',
            '3'
          ]
        ];

When I run it from a network drive I get this output:
Cannot obtain shared lock on /export/home/mmusgrove/test.
csv: No locks available -- ./test.pl at 18
$VAR1 = {};

HTH,
Matt


On Wed, Feb 25, 2015 at 11:25 AM, Furst, Carl <carl.fu...@mlb.com> wrote:

> I think someone wrote about this before, but I just wanted to bring it up
> again.
>
> Is there a way to have DBD::CSV produce a warning or a message (like when
> printError and raise error is set) to say that it’s waiting for a file
> lock??
>
> For example if I’m using my oh so beloved MS Excel and it locks the csv
> file and at the same time I’m trying to also run my even more beloved perl
> script which is trying to open the file for read. The script of course
> hangs when trying to execute any statements because it’s waiting for the
> flock put there by MS Excel..Is there a lock timeout? Is that what f_lock
> => 2 is for??
>
> At least I’m pretty sure that’s what’s happening because when I open it in
> things that put the whole file into memory (like my other beloved text
> editor) I have no problem, but excel likes to lock things, it seems. When
> I close the file in Excel, of course, the perl runs like a charm.
>
> Thanks,
> Carl Furst
>
> **********************************************************
>
> MLB.com: Where Baseball is Always On
>

Reply via email to