Perl Question

Victor Odhner plug-devel@lists.PLUG.phoenix.az.us
Tue Nov 20 13:49:01 2001


I don't have time to test my thinking at this moment, but this
may be the problem.

It looks to me like the message may be issued when "use Bar"
is processed, which is before the "use Fcntl" has taken
effect.

If you ever have a perl question, phone me.

Good luck,

Vic
602 867-4785

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
>