Perl Question
Dan Brown
plug-devel@lists.PLUG.phoenix.az.us
Tue Nov 20 14:29:01 2001
--FL5UXtIhxfXey3p5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
It's a good idea to use the -w switch and 'use strict'. With these added I=
get
Argument "O_WZOO\\Y" isn't numeric in sysopen at
/home/dan/Devl/Perl/Testing/Bar.pm line 12.
This told me that when used in Bar.pm, Perl sees these modes as strings, no=
t as integers.
Here's my take on it. The modes loaded from Fcntl are not loaded into the =
Bar name space.
I added=20
warn "FOO: [" . O_CREAT . "] [" . O_EXCL . "] [" . O_WRONLY . "]";
to the top of the main script (before the call to foo()) and=20
warn "BAR: [" . O_CREAT . "] [" . O_EXCL . "] [" . O_WRONLY . "]";
to the top of Bar::bar.
The FOO output shows integers, the BAR output shows
BAR: [O_CREAT] [O_EXCL] [O_WRONLY]
Which tells me again that these are strings, not integers.
If I add the=20
use Fcntl qw(O_CREAT O_EXCL O_WRONLY);
to Bar.pm, everything works without error (as a bonus, both files are creat=
ed).
Another thing that worked was to add that Fcntl to Bar.pm and add the modes=
to=20
the @EXPORT array
@EXPORT =3D qw(bar O_CREAT O_EXCL O_WRONLY );
Then the 'use Fcntl...' can be removed from the main script since they are =
available
from Bar.pm.
Hope this helps.
Dan
Jeffrey Pyne (jpyne@worldatwork.org) wrote:
> Date: Tue, 20 Nov 2001 12:47:18 -0700
> From: "Jeffrey Pyne" <jpyne@worldatwork.org>
> Sender: plug-devel-admin@lists.PLUG.phoenix.az.us
> To: "'plug-devel@lists.plug.phoenix.az.us'" <plug-devel@lists.PLUG.phoeni=
x.az.us>
> Subject: Perl Question
> X-Mailer: Internet Mail Service (5.5.2653.19)
> Reply-To: plug-devel@lists.PLUG.phoenix.az.us
> Lines: 69
>=20
> What is going on here? I looked through the Perl Mongers archive and did=
n'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...."
>=20
> $ cat /home/jpyne/bin/foo
> #!/usr/bin/perl
>=20
> use lib '/home/jpyne/lib';
> use Bar;
> use Fcntl qw(O_CREAT O_EXCL O_WRONLY);
>=20
> foo();
> bar();
>=20
> sub foo {
> $FOOLOCKFILE =3D "/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;
> }
>=20
>=20
> $ cat /home/jpyne/lib/Bar.pm
> #!/usr/bin/perl
>=20
> use Fcntl qw(O_CREAT O_EXCL O_WRONLY);
>=20
> package Bar;
> require Exporter;
> @ISA =3D qw(Exporter);
> @EXPORT =3D qw(bar);
>=20
> sub bar {
> $BARLOCKFILE =3D "/var/tmp/bar.lk";
> sysopen BARLOCKFILE, $BARLOCKFILE, O_WRONLY|O_CREAT|O_EXCL, 0600
> or die "Could not create $BARLOCKFILE: $!\n"; =20
> print BARLOCKFILE "bar";
> close BARLOCKFILE;
> }
>=20
> $ ./bin/foo
> Could not create /var/tmp/bar.lk: No such file or directory
>=20
> $ ls /var/tmp/*lk
> /var/tmp/foo.lk
>=20
> Why is it that when I call sysopen from MAIN{}, it properly creates a fil=
e,
> but not when I call it from within my module? I know I'm missing somethi=
ng
> stoopid....
>=20
> TIA
>=20
> ~Jeff
>=20
> Jeffrey Pyne
> UNIX Systems Administrator
> WorldatWork
> 14040 N. Northsight Blvd.=20
> 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
--FL5UXtIhxfXey3p5
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE7+shcPIfIXJRddQ0RAlI3AKD0UBnMsSsfAhY2yFATt640HQVpxgCfT1Yx
kDi/3lYfzZAfpbDGOvcR/3U=
=ZjZQ
-----END PGP SIGNATURE-----
--FL5UXtIhxfXey3p5--