open's first argument can be a reference to a filehandle. As of perl 5.6.0, if the argument is uninitialized, Perl will automatically create a filehandle and put a reference to it in the first argument, like so:Indirect filehandles make namespace management easier. Since filehandles are global to the current package, two subroutines trying to open INFILE will clash. With two functions opening indirect filehandles like my $infile, there's no clash and no need to worry about future conflicts. Another convenient behavior is that an indirect filehandle automatically closes when it goes out of scope or when you undefine it:open( my $in, $infile ) or die "Couldn't read $infile: $!"; while ( <$in> ) { # do something with $_ } close $in;sub firstline { open( my $in, shift ) && return scalar <$in>; # no close() required }
bind_paramThe bind_param method takes a copy of $bind_value and associates it (binds it) with a placeholder, identified by $p_num, embedded in the prepared statement. Placeholders are indicated with question mark character (?). For example:$sth->bind_param($p_num, $bind_value) $sth->bind_param($p_num, $bind_value, \%attr) $sth->bind_param($p_num, $bind_value, $bind_type)$dbh->{RaiseError} = 1; # save having to check each method ca +ll $sth = $dbh->prepare("SELECT name, age FROM people WHERE name LIKE ? +"); $sth->bind_param(1, "John%"); # placeholders are numbered from 1 $sth->execute;
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
In reply to Re: Insert into database table
by CountZero
in thread Insert into database table
by curtisb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |