Or, for a more robust approach, you could use one of the getopt modules to use command line switches and execute your script like this:
myscript.pl -i <input filename> -o <output filename>
There are a number of improvements that could and should be made, but first lets track down the syntax error.
I don't receive a syntax error with the change I suggested.
C:\test>perl -c mark1110.pl
mark1110.pl syntax OK
C:\test>type mark1110.pl
#
# nbr_FormatRelateRecord.pl
#
#...
I'd need to see a sample of the input data and a better explanation of your goal.
But see if this change gives you what you want.
print OVERRELATEFIL (
trim($overrelatefil{tin}),
trim($overrelatefil{parent_tin}),
trim($overrelatefil{paid_tin})...
Why are you putting that print statement in an unless block?
OVERRELATEFIL is a filehandle and can't be used like that in an if statement.
Change it to:
if ( $overrelatefil{tin} eq "|||" ) {
Your trim sub is unnecessary and makes the script a little less efficient.
It would be better to...
Mark,
There's no syntax error in that code UNLESS you're running under strictures, which it's obvious that you're not using the strict pragma.
EVERY Perl script you write should include the strict and warnings pragmas i.e.,
use strict;
use warnings;
All non global vars that are declared with...
See if any of these modules do what you want.
http://search.cpan.org/search?query=trycatch&mode=all
You can also take a look at the eval function.
http://perldoc.perl.org/functions/eval.html
If you still receive the same error, you should add a print statement above the execute statement that outputs the data to be inserted, namely $uwind[$i].
Since the error states that the data was truncated, it would appear that it's attempting to insert more data in that field than what the db...
<FILE> line 193348
That part of the error message seems odd since <FILE> was slurped into an array and at this point <FILE> has nothing to do with the sql statement.
Try changing it to this:
open(my $FILE1, '<', $filename) or die $!;
my @uwind = <$FILE1>...
Please show the updated code after moving the prepare statement and post the complete error message.
It would also be helpful for you to fix your indentation and declare the vars in the smallest scope they require.
Try passing all of the values in the execute statement.
In your other post "String variable won't work outside of loop" the error message you posted mentioned "Data truncated for column 'U' at row 1 at line 93, <FILE>". What does line 93 of your data file look like?
Hi Kevin,
If you think those prices are high, you should take a 5hr drive up the coast and see what we have up here. Prices around here are at least double.
Perl is not DCL so IMO there's no valid reason to want them to act the same. Do you feel the same way with bash scripts?
Declaring all of your vars with local means that you're not running under strictures, which is bad, and you may not even have warnings enabled. The combination of the...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.