Advertisement

02.08.2005 at 02:34PM PST, ID: 21307071
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Perl debugger has wrong initial entry point and line numbers

Asked by luke_airig in Perl Programming Language

Tags: , , ,


UNIX SunOS 5.8, Perl version 5.003

When I invoke the Perl debugger on the following script, the debugger entry point is line 5 (which in
reality is line 75) as follows:

Stack dump during die enabled outside of evals.

Loading DB routines from perl5db.pl patch level 0.94
Emacs support available.

Enter h or `h h' for help.

Unquoted string "null" may clash with future reserved word at junk.perl line 70.
Useless use of a constant in void context.
main::(junk.perl:5):
5:      #print "Loaded list\n";
  DB<1> w
2:        }
3:      }
4:      close(LIN); # we are done we have our list array.
5==>    #print "Loaded list\n";
6:
7:      open(INFILE, $datainputfile) or die "Can not open input $datainputfile";
8:      open(OUTFILE, "> " . $dataoutputfile) or die "Can not open output $dataoutputfile";
9:
10:     # read in real data and put in array!
11:
  DB<1>

How can I get the debugger to start at the first executable line and accurately reflect the source code
line numbers?


Here is the source code:

#!/usr/bin/perl

# variables

$sortlistfile = "";
$datainputfile = "";
$dataoutputfile = "";
$CMD = "";
$hit99 = 0; # boolean to trigger email with 99 notice

$NOTIFY = `cat /opt/apps/empower/cpi/control/CPI.notify`;
chomp($NOTIFY);
print $NOTIFY;

# take in file names as command line arguments. First the mask list,
# then the data input, then the data output.


chomp($ARGV[0]);
if ($ARGV[0] eq "-c") { exit; }

if (!($ARGV[2]))
{
  print "Execute with: 'cpisort.perl masklist datainput dataoutput [prog_to_run]'\n";  
  exit;
} else {
  $sortlistfile = $ARGV[0];
  $datainputfile = $ARGV[1];
  chomp($ARGV[2]);
  $dataoutputfile = $ARGV[2];
  chomp($ARGV[3]);
  $CMD = $ARGV[3];
}

@LIST = ""; # array holding list of sort patterns in sort order!
@DATA = ""; # array holding data from real input file. Index is integer!
@MASKHITS = ""; #array holding relationship between masks
                # in @LIST and lines in @DATA. @LIST index is index,
                # while data is index from @DATA
@CARDLINE = ""; # will eventually contain list of lines split from
                 # @MASKHITS data to be printed as a group.

$TRUE = 1;
$opline = "";
$opmask = "";
$card_line_ctr = 0;
$file_line_ctr = 0;
$file_max = 0;
$list_line_ctr = 0;
$list_max = 0;
$knownmask = 0;
$ldelim = "~";

open(LIN, $sortlistfile) or die "Can not open $sortlistfile";

# read in list

while ($sline = <LIN>)
{
  chomp($sline);
  if ($sline)
  {
    if (!(substr($sline,0,1) =~ /^\#/))
    {
       $list_line_ctr++;
       $list_max++;
       $LIST[$list_line_ctr] = $sline;
       #print "list " . $list_line_ctr . " " . $LIST[$list_line_ctr] . "\n";
    } else {
       null; # is a comment
    }
  }
}
close(LIN); # we are done we have our list array.
#print "Loaded list\n";

open(INFILE, $datainputfile) or die "Can not open input $datainputfile";
open(OUTFILE, "> " . $dataoutputfile) or die "Can not open output $dataoutputfile";

# read in real data and put in array!

while ($fline = <INFILE>)
{
  chomp($fline);
  if ($fline)
  {
     $file_line_ctr++;
     $file_max++;
     $DATA[$file_line_ctr] = $fline;
  }
}

# we don't need the INFILE any more we have it in an array
close(INFILE);

#print "Loaded \@DATA array\n";

# Now. Loop through @DATA line by line. Extract the bytes from
# positions 1, 2, 3, 14, 15, 18, 24, 64, 69, 80. Compare the resulting string
# with ALL the masks in @LIST. If a match is found, use the @LIST index
# number as the index value into @MASKHITS, and take the index from @DATA,
# the $file_line_ctr, and append it to the existing data value for @MASKHITS.
# E.g., $MASKHITS[$list_line_ctr] = $MASKHITS[$list_line_ctr] .
# . $file_line_ctr . "~";
#

$file_line_ctr = 1; # must start at 1 or first element will look like NULL
while ($file_line_ctr <= $file_max)
{
  $opline = $DATA[$file_line_ctr];
  #print "line " . $opline ."\n";
  $opmask = substr($opline,0,3)
  . substr($opline,8,1)
  . substr($opline,13,3)
  . substr($opline,17,1)
  . substr($opline,23,1)
  . substr($opline,63,1)
  . substr($opline,68,1)
  . substr($opline,79,1);

  $lnum = substr($opline,89,13);

  #print "linemask " . $file_line_ctr . " " . $opmask . "\n";

  $knownmask = 0;

  for ($list_line_ctr = 1; $list_line_ctr <= $list_max; $list_line_ctr++)
  {
    #print "compare " . $opmask . "-" . $list_line_ctr . "-" . $LIST[$list_line_ctr] . "\n";
    if ($opmask =~ /$LIST[$list_line_ctr]/)
    {
      # Our real line mask matches!
      $MASKHITS[$list_line_ctr] = $MASKHITS[$list_line_ctr]
      . $file_line_ctr . $ldelim;
      #print "matched " . $list_line_ctr . "-" . $MASKHITS[$list_line_ctr] . "\n";
      $knownmask = 1;
      last;      
    }
  }
  # check to make sure we found a matching mask. If not, put the line in a
  # '99' category to be printed last.
  if (!$knownmask)
  {
    $MASKHITS[99] = $MASKHITS[99] . $file_line_ctr . $ldelim;
    print "99hit " . $opmask . " for loan " . $lnum . "\n";
    $hit99 = 1;
  }

  $file_line_ctr++;
  # remember that @MASKHITS may have entries that are NULL. If, for example
  # there are no trasn cards of type 20 (say "^0311...1") in today's feed!
}

#print "Loaded \@MASKHITS array\n";
#print "MASKHITS AFTER LOAD " . $MASKHITS[0] . "**" . $MASKHITS[1] . "\n";

# Now @MASKHITS is loaded. Simply go through each line of it by its
# index (you can use $list_line_ctr since this represents the same value)
# and then find the LINES in $DATA that correspond to the string of lines now
# stored as the data to @MASKHITS, eg. "2449010212345". Note the presence
# of $ldelim at end of line. Should make split easy, but must use split() into
# array as don't know how many lines there are matching any given @LIST mask.
#

for ($list_line_ctr = 1; $list_line_ctr <= 99; $list_line_ctr++)
{
    #print "MASKHITS " . $MASKHITS[$list_line_ctr] . "\n";
    if ($MASKHITS[$list_line_ctr])
    {
      #We want to make sure this data at this position in $MASKHITS
      # is not null!. @CARDLINE must never have null lines!
      @CARDLINE = ""; # reinitialize this array

      (@CARDLINE) = split(/$ldelim/,$MASKHITS[$list_line_ctr]);
      #print "cardline " . $list_line_ctr . " " . $CARDLINE[0] . $CARDLINE[1] . "\n";

      # @CARDLINE should now be an array of line numbers in @DATA that contain
      #  the cards we want from this particular line of @MASKHITS...

      $TRUE = 1;
      $card_line_ctr = 0;
      while ($TRUE)
      {
        #print "cardline inside " . $CARDLINE[$card_line_ctr] . "\n";
        if ($CARDLINE[$card_line_ctr])
        {
          # test for data, don't print otherwise cause we're at end
          print OUTFILE $DATA[$CARDLINE[$card_line_ctr]] . "\n";
          #print "cardline to output " . $DATA[$CARDLINE[$card_line_ctr]] . "\n";
          $card_line_ctr++;
        }else{
          # end of card, we can break from this while  
          $TRUE = 0;
        }
      }
    }  
}

# we should be done, so close output and do any reporting for test
# purposes, etc.

close(OUTFILE);
open(EMAIL, "| mailx -s'CPI sort report ' $NOTIFY");
print EMAIL "CPI file sorted\n";
if ($hit99) { print EMAIL "There were UNSORTABLE transactions!\n"; }
            else
            { print EMAIL "There were no unsortable transactions.\n"; }
close(EMAIL);
if ($CMD) { exec $CMD; }

exit;

Start Free Trial
[+][-]02.08.2005 at 04:23PM PST, ID: 13260104

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.09.2005 at 09:49AM PST, ID: 13266750

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.03.2005 at 09:36PM PST, ID: 13456329

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]03.08.2005 at 01:50AM PST, ID: 13484589

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: perl, line, array, number
Sign Up Now!
Solution Provided By: modulo
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32