dbmopen can't open /etc/aliases.db file
Hi, I'm triyng to open the /etc/aliases.db file for reading with the dbmopen function - the result is that I can't open the file for reading, or something like this. yes, I have permission because I'm root. My script is: #!/usr/bin/perl -w use diagnostics; dbmopen(%ALIAS,'/etc/aliases',undef) || die "No aliases!: $!"; while (($key,$value) = each(%ALIAS)) { chop($key,$value); print "$key $value\n"; } the output error is: ### Use of uninitialized value in dbmopen at ./zz line 3 (#1) (W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables. Use of uninitialized value in null operation at ./zz line 3 (#1) Uncaught exception from user code: No aliases!: Invalid argument at ./zz line 3. Does someone could explain me why is it happening? (i'm using perl 5.6.0 and Red Hal linux 7.2) Thank you, - -- Bruno Negrão -- Suporte -- Plugway Acesso Internet Ltda. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: dbmopen can't open /etc/aliases.db file
Why is the third parameter in your dbmopen call undef? The example in perldoc -f dbmopen is almost identical to yours except that it defines that third parm as 0666. If the dbmfile does not already exist, it will be created with permissions specified by that third parm. >= Original Message From "Bruno Negrao - Perl List" <[EMAIL PROTECTED]> = >Hi, >I'm triyng to open the /etc/aliases.db file for reading with the dbmopen >function - the result is that I can't open the file for reading, or >something like this. yes, I have permission because I'm root. > >My script is: >#!/usr/bin/perl -w >use diagnostics; >dbmopen(%ALIAS,'/etc/aliases',undef) || >die "No aliases!: $!"; >while (($key,$value) = each(%ALIAS)) { >chop($key,$value); >print "$key $value\n"; >} > >the output error is: >### >Use of uninitialized value in dbmopen at ./zz line 3 (#1) > >(W uninitialized) An undefined value was used as if it were already >defined. > It was >interpreted as a "" or a 0, but maybe it was a mistake. To suppress >this >warning assign a defined value to your variables. > >Use of uninitialized value in null operation at ./zz line 3 (#1) >Uncaught exception from user code: >No aliases!: Invalid argument at ./zz line 3. > >Does someone could explain me why is it happening? >(i'm using perl 5.6.0 and Red Hal linux 7.2) > >Thank you, >- > -- Bruno Negrão -- Suporte > -- Plugway Acesso Internet Ltda. > > > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dbmopen can't open /etc/aliases.db file
On Thu, Sep 26, 2002 at 09:38:18PM -0300, Bruno Negrao - Perl List wrote: > Hi, Hi Bruno, > I'm triyng to open the /etc/aliases.db file for reading with the dbmopen > function - the result is that I can't open the file for reading, or > something like this. yes, I have permission because I'm root. > > My script is: > #!/usr/bin/perl -w > use diagnostics; > dbmopen(%ALIAS,'/etc/aliases',undef) || > die "No aliases!: $!"; > while (($key,$value) = each(%ALIAS)) { > chop($key,$value); > print "$key $value\n"; > } Disclaimer: I've never messed around with dbmopen() before, so I can't test this example, but seeing as nobody with more authority has answered this yet, I'll give it a shot: dbmopen() expects a file permission mask (an octal number) as its third argument, which 'undef' is not. You might try something like this as your lines 3 and 4: dbmopen(%ALIAS,'/etc/aliases', 0644) || die "No aliases!: $!"; Even if you're sure /etc/aliases is there, that should make dbmopen() happy. Again, not sure if that's the answer, but it seems logical to me, -- Michael -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dbmopen can't open /etc/aliases.db file
Hi Michael, the problem is not with the "undef" value - undef is fine - if you read the dbmopen's documentation you could see it. If I choose a value like "0644" the script still doesn't work. Bellow, is the output of the execution of the same program, but with 0644 in place of undef: Uncaught exception from user code: No aliases!: Invalid argument at ./zz line 3. I must admit that the errors are shorter but the program still doesn't work!! Oh, hell!!! Thank you for any help, bnegrao. - Original Message - From: "Michael Kelly" <[EMAIL PROTECTED]> To: "Perl Beginners List" <[EMAIL PROTECTED]> Sent: Friday, September 27, 2002 1:04 AM Subject: Re: dbmopen can't open /etc/aliases.db file > On Thu, Sep 26, 2002 at 09:38:18PM -0300, Bruno Negrao - Perl List wrote: > > Hi, > > Hi Bruno, > > > I'm triyng to open the /etc/aliases.db file for reading with the dbmopen > > function - the result is that I can't open the file for reading, or > > something like this. yes, I have permission because I'm root. > > > > My script is: > > #!/usr/bin/perl -w > > use diagnostics; > > dbmopen(%ALIAS,'/etc/aliases',undef) || > > die "No aliases!: $!"; > > while (($key,$value) = each(%ALIAS)) { > > chop($key,$value); > > print "$key $value\n"; > > } > > Disclaimer: I've never messed around with dbmopen() before, so I can't test this > example, but seeing as nobody with more authority has answered this yet, I'll > give it a shot: > > dbmopen() expects a file permission mask (an octal number) as its third argument, > which 'undef' is not. You might try something like this as your lines 3 and 4: > > dbmopen(%ALIAS,'/etc/aliases', 0644) || > die "No aliases!: $!"; > > Even if you're sure /etc/aliases is there, that should make dbmopen() happy. > > Again, not sure if that's the answer, but it seems logical to me, > -- > Michael > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: dbmopen can't open /etc/aliases.db file
>Uncaught exception from user code: >No aliases!: Invalid argument at ./zz line 3. Well you have three arguments. If you are *sure* that the undef is not the problem, that leaves only two to possibly be invalid. To start, try battening down the hatches with use strict, predeclaring your vars with my. Does using a hash NOT called ALIAS make a difference (the implication being maybe that is somehow a reserved identifier for hashes on your system or distro)? Are you *sure* that the path specified in the dbmopen call is 100% correct? Dumb, dumb questions but most problems in programming turn out to be really stupid, and it doesn't hurt to brainstorm and try anything. > >I must admit that the errors are shorter but the program still doesn't >work!! >Oh, hell!!! > >Thank you for any help, >bnegrao. > > >- Original Message - >From: "Michael Kelly" <[EMAIL PROTECTED]> >To: "Perl Beginners List" <[EMAIL PROTECTED]> >Sent: Friday, September 27, 2002 1:04 AM >Subject: Re: dbmopen can't open /etc/aliases.db file > > >> On Thu, Sep 26, 2002 at 09:38:18PM -0300, Bruno Negrao - Perl List wrote: >> > Hi, >> >> Hi Bruno, >> >> > I'm triyng to open the /etc/aliases.db file for reading with the dbmopen >> > function - the result is that I can't open the file for reading, or >> > something like this. yes, I have permission because I'm root. >> > >> > My script is: >> > #!/usr/bin/perl -w >> > use diagnostics; >> > dbmopen(%ALIAS,'/etc/aliases',undef) || >> > die "No aliases!: $!"; >> > while (($key,$value) = each(%ALIAS)) { >> > chop($key,$value); >> > print "$key $value\n"; >> > } >> >> Disclaimer: I've never messed around with dbmopen() before, so I can't >test this >> example, but seeing as nobody with more authority has answered this yet, >I'll >> give it a shot: >> >> dbmopen() expects a file permission mask (an octal number) as its third >argument, >> which 'undef' is not. You might try something like this as your lines 3 >and 4: >> >> dbmopen(%ALIAS,'/etc/aliases', 0644) || >> die "No aliases!: $!"; >> >> Even if you're sure /etc/aliases is there, that should make dbmopen() >happy. >> >> Again, not sure if that's the answer, but it seems logical to me, >> -- >> Michael >> >> -- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dbmopen can't open /etc/aliases.db file
Thank you nkuipers for answering. I already tried declaring variables with "my", i already checked the path, i tested the hash with another name - all this doesn't make difference. To me, it seems that my /etc/aliases.db in written in a format uncompatible with the dbmopen(). I'm on the 17 chapter of the book "Learning Perl second edition" and I'm stuck in this problem. (to open the /etc/aliases.db file for reading is an exercise of the chapter 17). If somebody there has a server runing Sendmail, you have the aliases.db file too. Moreover to simply solve this exercise, i'd like to know it the dbmopen() really works with my system files. Thanks for any help, Bruno. - Original Message - From: "nkuipers" <[EMAIL PROTECTED]> To: "Bruno Negrao - Perl List" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Friday, September 27, 2002 12:30 PM Subject: RE: dbmopen can't open /etc/aliases.db file > >Uncaught exception from user code: > >No aliases!: Invalid argument at ./zz line 3. > > Well you have three arguments. If you are *sure* that the undef is not the > problem, that leaves only two to possibly be invalid. To start, try battening > down the hatches with use strict, predeclaring your vars with my. Does using > a hash NOT called ALIAS make a difference (the implication being maybe that is > somehow a reserved identifier for hashes on your system or distro)? Are you > *sure* that the path specified in the dbmopen call is 100% correct? Dumb, > dumb questions but most problems in programming turn out to be really stupid, > and it doesn't hurt to brainstorm and try anything. > > > > > >I must admit that the errors are shorter but the program still doesn't > >work!! > >Oh, hell!!! > > > >Thank you for any help, > >bnegrao. > > > > > >----- Original Message - > >From: "Michael Kelly" <[EMAIL PROTECTED]> > >To: "Perl Beginners List" <[EMAIL PROTECTED]> > >Sent: Friday, September 27, 2002 1:04 AM > >Subject: Re: dbmopen can't open /etc/aliases.db file > > > > > >> On Thu, Sep 26, 2002 at 09:38:18PM -0300, Bruno Negrao - Perl List wrote: > >> > Hi, > >> > >> Hi Bruno, > >> > >> > I'm triyng to open the /etc/aliases.db file for reading with the dbmopen > >> > function - the result is that I can't open the file for reading, or > >> > something like this. yes, I have permission because I'm root. > >> > > >> > My script is: > >> > #!/usr/bin/perl -w > >> > use diagnostics; > >> > dbmopen(%ALIAS,'/etc/aliases',undef) || > >> > die "No aliases!: $!"; > >> > while (($key,$value) = each(%ALIAS)) { > >> > chop($key,$value); > >> > print "$key $value\n"; > >> > } > >> > >> Disclaimer: I've never messed around with dbmopen() before, so I can't > >test this > >> example, but seeing as nobody with more authority has answered this yet, > >I'll > >> give it a shot: > >> > >> dbmopen() expects a file permission mask (an octal number) as its third > >argument, > >> which 'undef' is not. You might try something like this as your lines 3 > >and 4: > >> > >> dbmopen(%ALIAS,'/etc/aliases', 0644) || > >> die "No aliases!: $!"; > >> > >> Even if you're sure /etc/aliases is there, that should make dbmopen() > >happy. > >> > >> Again, not sure if that's the answer, but it seems logical to me, > >> -- > >> Michael > >> > >> -- > >> To unsubscribe, e-mail: [EMAIL PROTECTED] > >> For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > > > > > >-- > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dbmopen can't open /etc/aliases.db file
Thank you nkuipers for answering. I already tried declaring variables with "my", i already checked the path, i tested the hash with another name - all this doesn't make difference. To me, it seems that my /etc/aliases.db in written in a format uncompatible with the dbmopen(). I'm on the 17 chapter of the book "Learning Perl second edition" and I'm stuck in this problem. (to open the /etc/aliases.db file for reading is an exercise of the chapter 17). If somebody there has a server runing Sendmail, you have the aliases.db file too. Moreover to simply solve this exercise, i'd like to know it the dbmopen() really works with my system files. Thanks for any help, Bruno. - Original Message - From: "nkuipers" <[EMAIL PROTECTED]> To: "Bruno Negrao - Perl List" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Friday, September 27, 2002 12:30 PM Subject: RE: dbmopen can't open /etc/aliases.db file > >Uncaught exception from user code: > >No aliases!: Invalid argument at ./zz line 3. > > Well you have three arguments. If you are *sure* that the undef is not the > problem, that leaves only two to possibly be invalid. To start, try battening > down the hatches with use strict, predeclaring your vars with my. Does using > a hash NOT called ALIAS make a difference (the implication being maybe that is > somehow a reserved identifier for hashes on your system or distro)? Are you > *sure* that the path specified in the dbmopen call is 100% correct? Dumb, > dumb questions but most problems in programming turn out to be really stupid, > and it doesn't hurt to brainstorm and try anything. > > > > > >I must admit that the errors are shorter but the program still doesn't > >work!! > >Oh, hell!!! > > > >Thank you for any help, > >bnegrao. > > > > > >----- Original Message - > >From: "Michael Kelly" <[EMAIL PROTECTED]> > >To: "Perl Beginners List" <[EMAIL PROTECTED]> > >Sent: Friday, September 27, 2002 1:04 AM > >Subject: Re: dbmopen can't open /etc/aliases.db file > > > > > >> On Thu, Sep 26, 2002 at 09:38:18PM -0300, Bruno Negrao - Perl List wrote: > >> > Hi, > >> > >> Hi Bruno, > >> > >> > I'm triyng to open the /etc/aliases.db file for reading with the dbmopen > >> > function - the result is that I can't open the file for reading, or > >> > something like this. yes, I have permission because I'm root. > >> > > >> > My script is: > >> > #!/usr/bin/perl -w > >> > use diagnostics; > >> > dbmopen(%ALIAS,'/etc/aliases',undef) || > >> > die "No aliases!: $!"; > >> > while (($key,$value) = each(%ALIAS)) { > >> > chop($key,$value); > >> > print "$key $value\n"; > >> > } > >> > >> Disclaimer: I've never messed around with dbmopen() before, so I can't > >test this > >> example, but seeing as nobody with more authority has answered this yet, > >I'll > >> give it a shot: > >> > >> dbmopen() expects a file permission mask (an octal number) as its third > >argument, > >> which 'undef' is not. You might try something like this as your lines 3 > >and 4: > >> > >> dbmopen(%ALIAS,'/etc/aliases', 0644) || > >> die "No aliases!: $!"; > >> > >> Even if you're sure /etc/aliases is there, that should make dbmopen() > >happy. > >> > >> Again, not sure if that's the answer, but it seems logical to me, > >> -- > >> Michael > >> > >> -- > >> To unsubscribe, e-mail: [EMAIL PROTECTED] > >> For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > > > > > >-- > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dbmopen can't open /etc/aliases.db file
Bruno Negrao - Perl List wrote: > Hi Michael, the problem is not with the "undef" value - undef is fine - > if you read the dbmopen's documentation you could see it. > > If I choose a value like "0644" the script still doesn't work. > Bellow, is the output of the execution of the same program, but with 0644 > in place of undef: > > Uncaught exception from user code: > No aliases!: Invalid argument at ./zz line 3. > > I must admit that the errors are shorter but the program still doesn't > work!! > Oh, hell!!! > the dbmopen function has been largely superseded by the "tie" function. you shouldn't use it in the first place. in older version of Perl or that your system do not support DBM or ndbm, calling dbmopen generates a fatal error and it tries the sdbm calls. try eval{ dbmopen(..) } and check the $@ error if you can, try not to use dbmopen at all, tie is better, safer and faster. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dbmopen can't open /etc/aliases.db file
Ok david. Could you send me a code example of a database file being opened for reading with tie? thanks, bnegrao. - Original Message - From: "david" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, September 27, 2002 2:41 PM Subject: Re: dbmopen can't open /etc/aliases.db file > Bruno Negrao - Perl List wrote: > > > Hi Michael, the problem is not with the "undef" value - undef is fine - > > if you read the dbmopen's documentation you could see it. > > > > If I choose a value like "0644" the script still doesn't work. > > Bellow, is the output of the execution of the same program, but with 0644 > > in place of undef: > > > > Uncaught exception from user code: > > No aliases!: Invalid argument at ./zz line 3. > > > > I must admit that the errors are shorter but the program still doesn't > > work!! > > Oh, hell!!! > > > > the dbmopen function has been largely superseded by the "tie" function. > you shouldn't use it in the first place. > > in older version of Perl or that your system do not support DBM or ndbm, > calling dbmopen generates a fatal error and it tries the sdbm calls. > > try eval{ dbmopen(..) } and check the $@ error > > if you can, try not to use dbmopen at all, tie is better, safer and faster. > > david > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dbmopen can't open /etc/aliases.db file
Bruno Negrao - Perl List wrote: > Ok david. > > Could you send me a code example of a database file being opened for > reading with tie? > > thanks, > bnegrao. use NDBM_File; tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0); while (($key,$val) = each %HIST) { print $key, ' = ', unpack('L',$val), "\n"; } untie(%HIST); this example is directly from perldoc -f tie david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dbmopen can't open /etc/aliases.db file
Yeah it worked! I simply changed the '/usr/lib/news/history' for '/etc/aliases' and the script showed the file contents. But, why? Why dbmopen didn't work? thanks, Bruno. - Original Message - From: "david" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, September 27, 2002 3:49 PM Subject: Re: dbmopen can't open /etc/aliases.db file > Bruno Negrao - Perl List wrote: > > > Ok david. > > > > Could you send me a code example of a database file being opened for > > reading with tie? > > > > thanks, > > bnegrao. > > use NDBM_File; > tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0); > while (($key,$val) = each %HIST) { > print $key, ' = ', unpack('L',$val), "\n"; > } > untie(%HIST); > > this example is directly from perldoc -f tie > > david > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dbmopen can't open /etc/aliases.db file
Bruno Negrao - Perl List wrote: > Yeah it worked! I simply changed the '/usr/lib/news/history' for > '/etc/aliases' and > the script showed the file contents. > But, why? Why dbmopen didn't work? > > thanks, > Bruno. dbmopen defaults to NDBM so if tie works, chances are that dbmopen should work as well. but since Perl does not recommand using dbmopen, we should respect that. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dbmopen can't open /etc/aliases.db file
Hi Bruno, The reason you could not open it properly is that Sendmail changed the hashing algorithm it uses some time back. Have a look at man makemap to see how Sendmail does it. PERL can read the Sendmail hash tables if you save them in the right format R At 16:22 27/09/2002 -0300, Bruno Negrao - Perl List wrote: >Yeah it worked! I simply changed the '/usr/lib/news/history' for >'/etc/aliases' and >the script showed the file contents. >But, why? Why dbmopen didn't work? > >thanks, >Bruno. >- Original Message - >From: "david" <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]> >Sent: Friday, September 27, 2002 3:49 PM >Subject: Re: dbmopen can't open /etc/aliases.db file > > > > Bruno Negrao - Perl List wrote: > > > > > Ok david. > > > > > > Could you send me a code example of a database file being opened for > > > reading with tie? > > > > > > thanks, > > > bnegrao. > > > > use NDBM_File; > > tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0); > > while (($key,$val) = each %HIST) { > > print $key, ' = ', unpack('L',$val), "\n"; > > } > > untie(%HIST); > > > > this example is directly from perldoc -f tie > > > > david > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]