in reply to file parsing help

if ($index eq '' )
should be
if (trim($index) eq '' )

Also, something's fishy about

if ($id eq "") { $id=sprintf("%-*s",8,$prev_id); } else { $id=sprintf("%-*s",8,$prev_id); }

By the way, please use <c>...</c> instead of <pre>...</pre> on PerlMonks.

Update:

$a=index($sub_line,'|',1); $b=index($sub_line,'|',8); $c=index($sub_line,'|',20);

should be

$a=index($sub_line,'|'); $b=index($sub_line,'|', $a+1); $c=index($sub_line,'|', $b+1);

Although you shouldn't use $a and $b. They are special variables, and using them can create problems at a distance.

Replies are listed 'Best First'.
Re^2: file parsing help
by ctaustin (Sexton) on Nov 13, 2006 at 17:32 UTC
    Good catch on the Also, something's fishy about
    if ($id eq "") { $id=sprintf("%-*s",8,$prev_id); } else { $id=sprintf("%-*s",8,$prev_id); }
    This fixed the problem I had with the holes in the fourth field.
    I have also changed the variables names away from $a and $b.

    I am still getting missing values for the SIC code in the second field, after adding in the trim($index) eq '' ...

    I appreciate the feedback thus far.

      Also, something's fishy about

      This fixed the problem I had with the holes in the fourth field.

      The "then" and "else" part are identical.

      if ($id eq "") { $id=sprintf("%-*s",8,$prev_id); } else { $id=sprintf("%-*s",8,$prev_id); }

      is the same thing as

      $id=sprintf("%-*s",8,$prev_id);

      I am still getting missing values for the SIC code in the second field

      The problem occurs for the first record of every employee except the first employee. That should be easy to debug.