Date: Fri, 15 Sep 2000 17:15:09 +0100 From: Mark Ovens <marko@freebsd.org> To: Ben Smithurst <ben@FreeBSD.org> Cc: chat@FreeBSD.org Subject: Re: perl(1) variable declarations Message-ID: <20000915171509.A258@parish> In-Reply-To: <20000915163441.A56185@strontium.scientia.demon.co.uk>; from ben@FreeBSD.org on Fri, Sep 15, 2000 at 04:34:41PM %2B0100 References: <20000915130220.C257@parish> <20000915163441.A56185@strontium.scientia.demon.co.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Sep 15, 2000 at 04:34:41PM +0100, Ben Smithurst wrote: > Mark Ovens wrote: > > > Is > > > > use vars qw/ $foo $bar /; > > > > the same as > > > > my $foo; > > my $bar; > > > > when used for global variables? > > I think "my" variables won't work if you want to set them from another > file, but I don't remember exactly. e.g. I should have added, "in a single file program". I did wonder if multiple files might be different, but it wasn't stated anywhere that I could find. Both ways appear to work identically in a single file. I think your answer makes sense. > > ==== main ==== > my ($foo, $bar); > require "globals.pl"; > print "foo=$foo bar=$bar\n"; > ============== > > ==== globals.pl ==== > $foo = 1; > $bar = "sheep"; > ==================== > > I don't think this will work, but I think it will if you use "use vars" > instead. That's the only difference I recall coming across, so I always > use "my" except in cases like the above. > > -- > Ben Smithurst / ben@FreeBSD.org / PGP: 0x99392F7D -- 4.4 - The number of the Beastie ________________________________________________________________ 51.44°N FreeBSD - The Power To Serve http://www.freebsd.org 2.057°W My Webpage http://ukug.uk.freebsd.org/~mark mailto:marko@freebsd.org http://www.radan.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000915171509.A258>