Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-06-19 21:19 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (115 votes). Check out past polls.