Link to home
Start Free TrialLog in
Avatar of slok
slok

asked on

Problem "unpacking"

I got some problem trying to "unpack" some data.
the variables "p_carrier_cod" and "p_flight_num"
are not assigned values.
Pls advise.

===============================================
#!/usr/local/bin/perl

# auto flush output
$|=1;

# define seperator. Informix uses a pipe character.
$seperator = '|';

# define input file
$fsafile = '/export/home/slok/SIMSQ.TXT';

# define output file
$dumpfile = '> /export/home/slok/sia_segment.txt';
$dumpfile1 = '>> /export/home/slok/sia_segment.txt';

# define format of record type 3 in input file
$format3 = 'x2 a3 a4 a2 a2 x1 a7 a7 a7 x1 a3 a4 a4 a5 a2 a3 a4 a4 a5 a2 a3 a20 x54  a10';

# define format of record type 4 in input file
$format4 = 'x28 a1 a1 a3 x6 a154';

# define format of various data in record type 4 based on DEI
$format4_010 = 'a3 a4 x147';
$format4_050 = 'a3 a4';
#$format4_101 = '';
#$format4_106 = '';
#$format4_109 = '';
#$format4_111 = '';
$format4_503 = 'x8 a1';

# open file for reading ($fsafile) and outputing ($dumpfile)
open (INFILE, $fsafile) or die "open file: $!";
open (OUTFILE, $dumpfile) or die "open file: $!";


      # local variable declarations for Record Type 3
      local (
            $carrier_code,
            $flight_num,
            $IVI,
            $leg_num,
            $period_from,
            $period_to,
            $DOP,
            $dept_station,
            $dept_passanger_STD,
            $dept_aircraft_STD,
            $dept_time_var,
            $dept_terminal,
            $arrv_station,
            $arrv_aircraft_STA,
            $arrv_passanger_STA,
            $arrv_time_var,
            $arrv_terminal,
            $aircraft_type,
            $aircraft_config
      );

      # local variable declarations for Record Type 4
      local (
            $BPI,      # Board Point Indicator
            $OPI,      # Off Point Indicator
            $DEI,      # Data Element Indicator
            $data,      # Data

            $restrict_code,      # traffic restriction
            $cargo_ind,      # cargo indicator
            $code_share_ind,      # code share indicator
            $p_carrier_code,      # partner carrier code
            $p_flight_num      # partner flight number
      );

# init loop counter
$i=0;

while( <INFILE> ) {

      last if $i > 120;

      #
      # in loop initialization!
      #

      # init cargo_ind to 'B'
      $cargo_ind = 'B';

      # init code_share_ind to '0'
      #$code_share_ind = 0;

      #chomp;

      #
      # Record Type 3 handler
      #
      if (/^3/) {

            # increment counter
            $i++;

            # if this is not first Record Type 3
            if ( $i > 1 ) {


                  if ($code_share_ind eq "") { $code_share_ind = "0"; }

                  # append data from Record Type 4
                  $record3 .=
                        ( $BPI . $seperator .
                         $OPI . $seperator .
                         $restrict_code . $seperator .
                         $cargo_ind . $seperator .
                         $code_share_ind . $seperator .
                         $p_carrier_code . $seperator .
                         $p_flight_num );

                  # add a CR
                  $record3 .= "\n";
            }

            ($carrier_code,
                  $flight_num,
                  $IVI,
                  $leg_num,
                  $period_from,
                  $period_to,
                  $DOP,
                  $dept_station,
                  $dept_passanger_STD,
                  $dept_aircraft_STD,
                  $dept_time_var,
                  $dept_terminal,
                  $arrv_station,
                  $arrv_aircraft_STA,
                  $arrv_passanger_STA,
                  $arrv_time_var,
                  $arrv_terminal,
                  $aircraft_type,
                  $aircraft_config
                  )
                  = unpack($format3, $_);

            # replace 00XXX00 with null string if found
            $period_to =~ s/00XXX00/       /;

            $record3 .= ($carrier_code . $seperator .
                        $flight_num . $seperator .
                        $IVI . $seperator .
                        $leg_num . $seperator .
                        $period_from . $seperator .
                        $period_to . $seperator .
                        $DOP . $seperator .
                        $dept_station . $seperator .
                        $dept_passanger_STD . $seperator .
                        $dept_aircraft_STD . $seperator .
                        $dept_time_var . $seperator .
                        $dept_terminal . $seperator .
                        $arrv_station . $seperator .
                        $arrv_aircraft_STA . $seperator .
                        $arrv_passanger_STA . $seperator .
                        $arrv_time_var . $seperator .
                        $arrv_terminal . $seperator .
                        $aircraft_type . $seperator .
                        $aircraft_config . $seperator );


      }

      #
      # Record Type 4 handler
      #
      if (/^4/) {

            ($BPI, $OPI, $DEI, $data) = unpack ($format4, $_);

            if ( $DEI eq "010" ) {
                  ($p_carrier_code,
                        $p_flight_num,
                        $dummy)
                        = unpack ($format_010, $data);
                  $code_share_ind = '1';
                  print "I am in 010\n";
                  print "data is [$data].\n";
                  print $p_carrier_code."\n";
                  print "p_flight_num [$p_flight_num].\n";
                  print "dummy [$dummy]\n";
                  print "\n";
            }
            elsif ( $DEI eq "050" ) {
                  ($p_carrier_code,
                        $p_flight_num)
                        = unpack ($format_050, $data);
                  $code_share_ind = '2';
            }
            elsif ( $DEI eq "503" ) {
                  ($restrict_code)
                        = unpack ($format_503, $data);
            }
            else {
                  #print "Information: DEI $DEI not handled.\n";
            }

      }

}

# add another CR
$record3 .= "\n";

print OUTFILE $record3;

close(INFILE);
close(OUTFILE);
============================================
Avatar of ozo
ozo
Flag of United States of America image

perl -wc 10106242.perl
Name "main::format4_503" used only once: possible typo at 10106242.perl line 29.
Name "main::format_010" used only once: possible typo at 10106242.perl line 179.
Name "main::format_050" used only once: possible typo at 10106242.perl line 191.
Name "main::dumpfile1" used only once: possible typo at 10106242.perl line 14.
Name "main::format_503" used only once: possible typo at 10106242.perl line 196.
Name "main::format4_010" used only once: possible typo at 10106242.perl line 23.
Name "main::format4_050" used only once: possible typo at 10106242.perl line 24.
Avatar of slok
slok

ASKER

Hi ozo,

thanks for the help.
Will wait for you to submit it as answer and I will award you the points.

With what grade?
Avatar of slok

ASKER

it will be an 'A'.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial