Greetings,
Late last week a co-worker asked me for some assistance with a set of perl CGI scripts that are being moved from a retiring HPUX box to another similar HPUX box (same OS level, same Perl, etc). fyi, the co-worker inhereited this system, and is exceedingly new to the world of perl.
The scripts in question were all accessing DBM files. all the scripts, while not failing, were returning very incomplete information on the new server.
(note that the following code is "as-is" from what I was shown, as you can see there are a few things that could be improved... including error handling on the open, using %HASH syntax on the open, and the regex should be referring to $notesInfo[0] not @notesInfo[0].)
if (dbmopen(DBDIR, '/wwwroot/test/groupweb/data/techExch/' . notesDir, + undef)) { foreach $notesDate (sort(keys (%DBDIR))) { $notesInfo = $DBDIR{$notesDate}; @notesInfo = split(/\|/, $notesInfo); @notesInfo[0] =~ s/([0-9]+)[\/](.*)/\2\/\1/; } }
So I isolated and tested the above from the command line on the new box, and sure enough I got the same incomplete info as the version running from the NES server on the same box. So I moved my test code over the original box and did another command-line test, and I ALSO got incomplete info. So my tests were behaving as follows:
OrigBox NewBox
CGI PASS FAIL
cmdline FAIL FAIL
So I did some digging around using perldoc -f dbmopen (and related) and came to the conclusion that at minimum, perhaps a simple:
was in order.....but, I get the same incomplete data....so I tryuse NDBM_File;
and all the magical data appears! (brute force sometimes has it's moments :)use SDBM_File;
After speaking at length with my sysadmins to determine what might be the reason this WORKS as CGI on the older box. but not anywhere else , they determined that I knew much more about this than they did, and could not provide anything useful. (from zero to "expert" in 30 minutes....yikes)
So.....I pose this to Perlmonks everywhere....
What could allow this appears-to-be-working-by-accident code to work properly (know the file is SDBM without being told) in the CGI environment, but not command-line? Is there an environment setting that manages this? Is it perhaps the way DBM was initially installed on the two HP's? (I have a hard time beleiving you even see references to DBM during an HPUX install, and this wouldn't explain discrepancies in command-line vs. CGI execution(or could it?)) Is there are default format for DBM files? (if so, I missed it in all the docs I located).
As far as all the failing scripts. adding the
"fixed" all of them without exception or additional code changes.use SDBM_File;
My co-worker is a happy camper and is now able to continue her budding perl education in areas a little more relevent than dbm.
But me, I am having difficulty putting this to rest in my mind. I'd just like to have some insight as to what was going on here.
thanks!
In reply to Seeking DBM wisdom by wardk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |