: if ((($amounts{$cheque}) - $amount) != 0) {
:
: $sth1->execute(split/,/)
: }
:
: ...
:
: However the $sth1->execute(split/,/) is giving me all the fields from the
: original file (when I only want 2) and I get the following error :
:
: execute called with 8 bind variables when 2 are needed at
: ./matchingcheques3.pl line 123,<FILE1> chunk 7.
To get just the first 2 fields, you can do it the explicit way:
if ((($amounts{$cheque}) - $amount != 0 ) {
my @fields = split /,/;
$sth->execute($field[0], $field[1]);
}
or the fun way:
if ((($amounts{$cheque}) - $amount != 0 ) {
$sth->execute((split/,/)[0,1]);
}
(split() returns a list that you can index- in this case, with a list
of indices. Isn't Perl cool? ;)
By the way, the first split() in your code seems to assume that $remark
won't have a comma in it, as part if the remark. If it can, then the
first split would be safer to do like this:
($type,$cheque,$amount,$remark) = split(/,/, $_, 4);
which means that the string will be split into no more than 4 pieces,
with the rest of the line going into $remark. Don't know if this
situation applies to you, but if it does, this may save you a nasty
debugging headache later on.
--
Tim Kimball · ACDSD / MAST ¦
Space Telescope Science Institute ¦ We are here on Earth to do good to others.
3700 San Martin Drive ¦ What the others are here for, I don't know.
Baltimore MD 21218 USA ¦ -- W.H. Auden