Perl Question
Michael Wittman
plug-devel@lists.PLUG.phoenix.az.us
Tue Nov 20 14:02:01 2001
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