Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to split a line of data and last part is missing 1

Status
Not open for further replies.

jcarrott

Programmer
May 28, 2009
130
US
I am using this input data,
BIG^20090807^45315897^20090807^1550510^^^DI

This is the code,
# segin[3] is BIG
for ($seqin[3]) {
@line = split(/\^/, $segin[3]);
$company = substr($line[4], 0, 1);
if($company eq 1) {
$company = 120;
} elsif($company eq 7) {
$company = 710;
} elsif($company eq 8) {
$company = 800;
}
$invoice_dte = $line[1];
$invoice = $line[2];
$po_date = $line[3];
$po_number = $line[4];
$x = $line[5];
$y = $line[6];
if ($line[7]) {
$inv_typ = " ";
}else {
$inv_typ = $line[7];
}
}

The last segment ($LINE[7]) is never found and neither are segments 5 or 6.
Perl seems to get confussed when there are several seperators with no data.
Does anybody know of a fix for this?
 
a few problems

your split line you mistype seqin
When doing your compares you should be using == not eq
This logic makes no sense
Code:
     if ($line[7]) {
             $inv_typ = " ";
          }else {
         $inv_typ = $line[7];
          }
If line[7] has data you set inv_type to blank, if it doesn't have data you try and set it equal to line[7] (which you know by your test doesn't exist)

You should start with using strict on your code, it pointed out the first problem right away.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I took that for loop out also.. it seems out of place for what you are doing.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top