This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Perl database problem


Hallo Goksun,

Am 2001-10-27 um 00:59 schriebst du:

> I am trying to run a Perl program in cygwin. When I
> create the database using dbmopen command, it looks
> like it's working (it's only creating .pag file, not
> .dir file). However, when I try to read something from
> the database, it cannot open the file. I run the
> program on a UNIX machine and it works. Is there way
> to run that program using cygwin? 

#!/usr/bin/perl -w
# recipe 14.1 from the 'Perl Cookbook'

use DB_File;

$db = '/tmp/userstats.db';

# use tie or dbmopen, as you like it,
# both works for me (on cygwin!)
# tie(%db, 'DB_File', $db)
#        or die "Cannot open DB_File $db: $!\n";

dbmopen (%db, $db, 0666)
        or die "Cannot open DB_File $db: $!\n";

if (@ARGV) {
    if ("@ARGV" eq "ALL") {
            @ARGV = sort keys %db;
    }
    foreach $user (@ARGV) {
            print "$user\t$db{$user}\n";
    }
} else {
    @who = `who`;             # execute who(1)
    if ($?) {
            die "Cannot execute who(1): $?\n";
    }
    # extract usernames and update
    foreach $line (@who) {
            $line =~ /^(\S+)/;
            die "error in who(1) output: $line\n"
              unless $1;
            $db{$1}++;
            }
}

# untie %db;
dbmclose %db;

# Ciao,

# Gerrit P. Haase                            mailto:gp@familiehaase.de
-- 
=^..^=


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]