From: Carl Jolley [mailto:[EMAIL PROTECTED]]

> On Mon, 13 May 2002 [EMAIL PROTECTED] wrote:
>
> > Dear friends,
> >             When i  am trying to process the flat database
> using the DB_File , it is giving the error like this ,
> >                   Cannot open C:\CC-LIC-USAGE\teams.txt: File exists
> >
> >             How will i get the values from the existing file.
> Is it possible or not.
> >             Expecting your valuable suggestions. Please ...
> >
> >
> > <CODE>
> >
> > Contents in the teams.txt file
> >
> > pons  TEAM1
> > ram   team2
> >
> >  use warnings ;
> >     use strict ;
> >     use DB_File ;
> >     use Fcntl ;
> >     our ($dotdir, $HISTORY, %hist_db, $user, $team) ;
> >     $dotdir = "C:\\CC-LIC-USAGE";
> >     $HISTORY = "$dotdir\\teams.txt";
> >     tie %hist_db, 'DB_File', $HISTORY
> >         or die "Cannot open $HISTORY: $!\n" ;;
> >     # Dump the complete database
> >     while ( ($user, $team) = each %hist_db ) {
> >         print "$user, $team\n" ;
> >     }
> >     untie %hist_db ;
> >
>
> You are probably getting caught by the default flags or permissions/mode.
> Re-examine the call on tie %hist_db.
>
> According to my perldoc DB_File the tie for DB_File looks like:
>
>         [$X =] tie %hash,  'DB_File', [$filename, $flags, $mode,
> $DB_HASH];

That indeed is part of the problem. If you don't tell DB_File otherwise, it
assumes you want to open a hash database. Also if you want to access a text
file, you do so via a tied array, not a tied hash.

The tie call should be something like this:

    my @hist_db;
    tie @hist_db, 'DB_File', $HISTORY, O_RDWR, 0666, $DB_RECNO
        or die "Cannot open $HISTORY: $!\n" ;

Have a look at the DB_RECNO section in the DB_File documentation for more
details.

Paul

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to