Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: READDIR and DBI

by marto (Cardinal)
on Feb 26, 2024 at 17:26 UTC ( [id://11157904]=note: print w/replies, xml ) Need Help??


in reply to READDIR and DBI

Something like:

my $path = '/home/marto/code/'; # open dir opendir(my $dh, $path) || die "Can't opendir $path $!"; # grep, testing for files my @files= grep { -f "$path/$_" } readdir($dh); closedir $dh; # connect to sqlite db my $dbh = DBI->connect('dbi:SQLite:dbname=filelist.sqlite','',''); # prepare insert my $sth = $dbh->prepare('insert into files(filename) values(?)'); # bind params $sth->bind_param_array(1, \@files); # execute $sth->execute_array({ ArrayTupleStatus => \my @tuple}) or die $sth->er +rstr;

Replies are listed 'Best First'.
Re^2: READDIR and DBI
by Anonymous Monk on Feb 26, 2024 at 17:51 UTC
    what sort of magic is that ?
    $sth->execute_array({ ArrayTupleStatus => \my @tuple}) or die $sth->er
    
    never see it before! what does it do?

      what sort of magic is that ?

      $sth->execute_array({ ArrayTupleStatus => \my @tuple}) or die $sth->errstr;

      It depends on which portion of that line seems like "magic" to you.

      • LanX answered with the execute_array description.
      • ArrayTupleStatus is described in the DBI bind_param_array and execute_array documentation.
      • \my @tuple syntax is shown in the examples of that DBI documentation. The concept of creating an array and immediately getting a reference to that array is described in perlref: Assigning-to-References, and is essentially shorthand for calling my @tuple; in one line and then using \@tuple in the execute_array() call to pass the reference to the function. (This is my best guess as to what you would consider the "magic" portion of that line of code.)
      • or die $sth->errstr is the typical way to raise an error with DBI, unless you use RaiseError

      You and me both....

      But it works...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11157904]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-30 22:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found