LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-18-2006, 01:45 PM   #1
cramer
Member
 
Registered: Feb 2006
Distribution: Red Hat 9
Posts: 112

Rep: Reputation: 15
Perl: Accessing value from DBM file.


I am using the following program to access and IP value stored by the key defined in $user. (a valid one is kimball).

Code:
#!/usr/bin/perl5

print "Username to lookup:  ";
chomp($_=lc(<STDIN>));
$user=$_;

dbmopen(%ip, "useraddr", 0644) || die "Cannot open DBM file: $!";

print "$ip{$user} \n";

dbmclose(%ip);
It doesn't show the value associated with $ip{$user}" even though there is one. Any help appreciated.
 
Old 08-19-2006, 06:42 AM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Try running a loop to see what the values and keys are to make sure it is valid:

while(($key, $val) = each %ip){
print "'$key' = '$val'\n";
}

Make sure you check for case and extra spaces etc.
 
Old 08-19-2006, 05:00 PM   #3
cramer
Member
 
Registered: Feb 2006
Distribution: Red Hat 9
Posts: 112

Original Poster
Rep: Reputation: 15
I ran a 'each' on them, to get the key and the value for each in the hash, it showed up as a valid one.

key=kimball value=192.168.2.101
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing inodes with perl the_uplink2x Programming 0 06-10-2005 10:21 AM
view vacation dbm file sohmc Linux - Software 0 10-11-2004 07:04 AM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
DBM help! katana Linux - General 1 06-19-2001 11:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration