Solved

Problem "unpacking"

Posted on 1998-12-07
5
252 Views
Last Modified: 2010-03-05
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);
============================================
0
Comment
Question by:slok
  • 3
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1206790
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.
0
 
LVL 3

Author Comment

by:slok
ID: 1206791
Hi ozo,

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

0
 
LVL 84

Expert Comment

by:ozo
ID: 1206792
With what grade?
0
 
LVL 3

Author Comment

by:slok
ID: 1206793
it will be an 'A'.
0
 
LVL 84

Accepted Solution

by:
ozo earned 100 total points
ID: 1206794
as general advice: use the -w flag
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question