[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Pack/UnPack Question



Hi everyone!  :-)

My question is this:  Does UNPACK do something to the
information it is unpacking?


My reason for this is as follows:

I'm writing a little database program.  I pack three
integers into an index variable and store this information
into a database.  The information is: record number in
another database, record location in that database, length
of the record in that database.

The part of this program which is giving me a pain is the
fmEdit.cgi (the Edit option under one of my menus via
HTML).  What the thing does is to get the list of the above
information, then open the second database, and read in the
record.  Due to the fact that I have no idea what order the
records are in, I first have to get a number and then go
locate that record in the database.  I've reduced this (so
far) down to just looking through the array which holds the
above information twice.  Later I plan on eliminating the
double look-up but for now I have to use it.  :-/

Anyway, the first time (before the &readDBF call) - the
unpack has no problem with doing the unpack.  The second
time (inside of the &readDBF function) I get an error which
reads:

Can't coerce ARRAY to integer in array deref at dbfRoutines.pl line 89.

Which is why I am wondering if Perl tampers with the second
argument in the UNPACK command.  Here's the two code
snippets:

fmEdit.cgi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#
#   Get the list of CRs
#
    &openDBF( $theDirectory );
#
#   Now pop open each file and read the title
#
    @titleList = ();
    for( $i=0; $i<=$#crdbIndex; $i++ ){
        @indexInfo = unpack( "iii", $crdbIndex[$i] );
        &readDBF( $indexInfo[0], 0 );
        open( THEFILE, "The.Users/$theUser" );
        @userInfo = <THEFILE>;
        close( THEFILE );

        for( $j=0; $j<=$#userInfo; $j++ ){
            $userInfo[$j] = &generic::stripEnd( $userInfo[$j] );
            }

        if( ($theStatuses[0] eq "Open") ||
            ($theStatuses[1] eq "Open") ||
            ($theStatuses[2] eq "Open") ){
            $titleList[++$#titleList] = sprintf( "%s) %s (%s %s)\n",
                $sortList[$i], $theCR[4], $userInfo[0], $userInfo[1] );
            }
        }

    &closeDBF( $theDirectory );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

and dbfRoutines.pl
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#
#   -------------------------------------------------------------------
#   Routine to read the database.
#   -------------------------------------------------------------------
#
sub readDBF
{
    local( $crNumber, $theOption ) = @_;

    local( $recNumber, $i, $curLine, $newLine );
    local( @theLine, @indexInfo );
#
#   Convert the CR Number to the actual record number
#
    $recNumber = -1;
    for( $i=0; $i<=$#crdbIndex; $i++ ){
        @indexInfo = unpack( "iii", $crdbIndex[$i] );
        if( $indexInfo[0] eq $crNumber ){
            $recNumber = $i;
            last;
            }
        }

	.
	.
	.

	return;
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

As you can see, the first unpack is right before the
&readDBF which just goes back into a loop which looks
through the array again to find where the number actually
resides.  It is the UNPACK in the &readDBF function which
has the problem.  The first one unpacks everything just
dandy!  :-)

PS: Yes, I know I could probably do this a lot more
efficiently - but I'm just trying to get the thing up and
running first - then I will worry about efficiency.  :-)

Thanks in advance to any ideas or help.  If anyone is
interested in the database manipulation code I'll be more
than happy to send you a copy.  Nothing fancy, just a
variable length record database randomly organized with an
index file.