Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

GDBM_File with Tie function

by bheeshmaraja (Novice)
on Oct 17, 2012 at 08:49 UTC ( #999492=perlquestion: print w/replies, xml ) Need Help??
bheeshmaraja has asked for the wisdom of the Perl Monks concerning the following question:

I have a simple getdata perl script which is used to get users First Name, Last Name and their email details. I'm getting these details from a file(test.txt). test.txt has 25 fields separated by "|" delimiter and I'm getting only 3 fields using my getdata script. I couldn't understand the behavior of this script. I need help in understanding the below script.

#!/opt/perl/5.8.0/bin/perl #ident "%W%" use CGI qw(:standard); use GDBM_File ; use POSIX qw(fcntl_h errno_h); use Getopt::Std; use Fcntl; $dbfile_exist = "no"; $arg1 = $ARGV[0]; # Argument 1 is the User ID. $dbmdatabase = "/home/bheeshmaraja/test.txt"; if (-f "$dbmdatabase") { $dbfile_exist = "yes"; } else { print "NULL"; exit 0; } tie %DBMDB, GDBM_File, $dbmdatabase, &GDBM_READER, 0400 or die "Couldn +'t tie NDBM file 'filename': $!; aborting"; untie %DBMDB;

test.txt contains 5176219 lines. Could anyone help me to understand why I'm getting only 3 fields instead of all 25 fields by providing User Id as an argument. Thanks in Advance... Bheeshmaraja

Replies are listed 'Best First'.
Re: GDBM_File with Tie function
by moritz (Cardinal) on Oct 17, 2012 at 09:16 UTC

    Is the data format that GDBM_File uses compatible with your formats (CSV with | as delimiter)? I don't know very much about GDBM, but I'd be surprised if that was the case.

    If not, you need to read the contents of the file (Text::CSV_XS can help you with that), and if you want them to live in a GDBM file, insert them into one.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://999492]
Approved by Ratazong
[stevieb]: choroba my GPS home device is done, at least prototype v1 is. I'm just making sure all of my code does what it says now
[stevieb]: I test/prototype code on my Pi, then I migrate it over to Arduino when it's ready (if that's a better platform for what I'm doing). The whole RPi stuff was for learning at first, then it snowballed. I'm just trying to get my in-house CI...
[stevieb]: ...done, which obviously requires a specific hardware setup.
[stevieb]: I don't write tests for the lower-level distributions (ie. ICs, sensors etc) within those distributions, I have all tests in a master distribution which encompasess all of the sub-modules

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2017-06-25 22:56 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (572 votes). Check out past polls.