Perl Question

Jeffrey Pyne plug-devel@lists.PLUG.phoenix.az.us
Tue Nov 20 15:04:01 2001


Ding ding ding!!  That's exactly it.  I figured it was something simple.  I
had seen that behaviour before when I omitted the "use Fcntl" completely,
but I could see clearly that I had included that directive, so this was
driving me nuts (and that's not a very long drive, believe you me).  Thanks
for pointing out my error!

Also, I'm glad I asked the question because, for some reason, I had gotten
out of the habit of using the -w.  This reminds me that I need to get back
into that habit.  In this case, I probably would have still needed to ask
the question because the message you get when you add the -w (Argument
"O_WZOO\\Y" isn't numeric in sysopen at /home/jpyne/lib/Bar.pm line 12.)
wouldn't have meant much to me.  It tells me that it doesn't see O_WRONLY,
etc. as numeric, but not WHY it doesn't see them as numeric.  Although Dan
Brown's explanation in the message that followed yours makes complete sense.

Thanks for everyone's help.

~Jeff

-----Original Message-----
From: Michael Wittman [mailto:wittman@acm.org]
Sent: Tuesday, November 20, 2001 1:51 PM
To: plug-devel@lists.PLUG.phoenix.az.us
Subject: Re: Perl Question


You need to put the "use Fcntl qw(O_CREAT O_EXCL O_WRONLY);" line after
the "package Bar;" declaration.  As is, the Fcntl declarations are going
into the main namespace, not the Bar namespace.

By the way, Perl would have caught this if you'd used the -w switch and
"use strict;".

-Mike

On Tue, Nov 20, 2001 at 12:47:18PM -0700, Jeffrey Pyne wrote:
> What is going on here?  I looked through the Perl Mongers archive and
didn't
> see anything relevant to my problem.  I fruitlessly searched Google, too,
> but I'm sure I'm just not using the right keywords.  I was hoping maybe
> someone here can give me a "Hey, dumb@$$, you forgot to...."
> 
> $ cat /home/jpyne/bin/foo
> #!/usr/bin/perl
> 
> use lib '/home/jpyne/lib';
> use Bar;
> use Fcntl qw(O_CREAT O_EXCL O_WRONLY);
> 
> foo();
> bar();
> 
> sub foo {
> 	$FOOLOCKFILE = "/var/tmp/foo.lk";
> 	sysopen FOOLOCKFILE, $FOOLOCKFILE, O_WRONLY|O_CREAT|O_EXCL, 0600
> 		or die "Could not create $FOOLOCKFILE: $!\n";
> 	print FOOLOCKFILE "foo";
> 	close FOOLOCKFILE;
> }
> 
> 
> $ cat /home/jpyne/lib/Bar.pm
> #!/usr/bin/perl
> 
> use Fcntl qw(O_CREAT O_EXCL O_WRONLY);
> 
> package Bar;
> require Exporter;
> @ISA = qw(Exporter);
> @EXPORT = qw(bar);
> 
> sub bar {
> 	$BARLOCKFILE = "/var/tmp/bar.lk";
> 	sysopen BARLOCKFILE, $BARLOCKFILE, O_WRONLY|O_CREAT|O_EXCL, 0600
> 		or die "Could not create $BARLOCKFILE: $!\n";      
> 	print BARLOCKFILE "bar";
> 	close BARLOCKFILE;
> }
> 
> $ ./bin/foo
> Could not create /var/tmp/bar.lk: No such file or directory
> 
> $ ls /var/tmp/*lk
> /var/tmp/foo.lk
> 
> Why is it that when I call sysopen from MAIN{}, it properly creates a
file,
> but not when I call it from within my module?  I know I'm missing
something
> stoopid....
> 
> TIA
> 
> ~Jeff
> 
> Jeffrey Pyne
> UNIX Systems Administrator
> WorldatWork
> 14040 N. Northsight Blvd. 
> Scottsdale, AZ  85260-3601
> Phone: 480-905-5977
>   Fax: 480-483-8352
>  Cell: 480-206-3163
> Pager: 888-359-2469
> _______________________________________________
> PLUG-devel mailing list  -  PLUG-devel@lists.PLUG.phoenix.az.us
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-devel
_______________________________________________
PLUG-devel mailing list  -  PLUG-devel@lists.PLUG.phoenix.az.us
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-devel