Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem "unpacking"

Posted on 1998-12-07
5
Medium Priority
?
258 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 85

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 85

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 85

Accepted Solution

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Six Sigma Control Plans

927 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