while(@data) works but why
while(@data) works but why
am 12.08.2011 21:02:13 von Tony Esposito
--0-1635047660-1313175733=:90702
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
..=0A.=0A.=0Awhile(@dat =3D $sth->fetchrow) {=0A print "@dat\n";=0A.=
=0A.=0A.
This code works yet there is no 'my @dat' defined anywhere in=
the code.=0AUsing Perl 5.8.x - 5.14.x
Q: Why does the variable @dat n=
ot need a 'my' in front?
Cheers!
--0-1635047660-1313175733=:90702--
Re: while(@data) works but why
am 12.08.2011 21:08:52 von Brandon McCaig
On Fri, Aug 12, 2011 at 3:02 PM, Tony Esposito
wrote:
> .
> .
> .
> while(@dat =3D $sth->fetchrow) {
> Â Â Â Â print "@dat\n";
> .
> .
> .
>
> This code works yet there is no 'my @dat' defined anywhere in the code.
> Using Perl 5.8.x - 5.14.x
>
> Q: Why does the variable @dat not need a 'my' in front?
See `perldoc strict'. In particular, the "strict vars" section.
--=20
Brandon McCaig
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software
..org>
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: while(@data) works but why
am 12.08.2011 21:13:26 von Jim Gibson
On 8/12/11 Fri Aug 12, 2011 12:02 PM, "Tony Esposito"
scribbled:
> .
> .
> .
> while(@dat = $sth->fetchrow) {
> print "@dat\n";
> .
> .
> .
>
> This code works yet there is no 'my @dat' defined anywhere in the code.
> Using Perl 5.8.x - 5.14.x
>
> Q: Why does the variable @dat not need a 'my' in front?
It does on my system:
#!/usr/local/bin/perl
use strict;
use warnings;
use DBI;
my $sth = DBI->connect();
while( my @dat = $sth->fecthrow) {
print "dat: ", join(",",@dat), "\n";
}
% perl -c esposito.pl
Global symbol "@dat" requires explicit package name at esposito.pl line 9.
Global symbol "@dat" requires explicit package name at esposito.pl line 10.
esposito.pl had compilation errors.
perl v5.10.1
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: while(@data) works but why
am 12.08.2011 21:15:31 von Tony Esposito
--0-1759626266-1313176531=:52794
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
got it ... thank you. cheers!
=0A______________________________=
__=0AFrom: Brandon McCaig =0ATo: Tony Esposito
4567893@yahoo.co.uk>=0ACc: beginners@perl.org=0ASent: Fri, 12 August, 2011 =
14:08:52=0ASubject: Re: while(@data) works but why
On Fri, Aug 12, 201=
1 at 3:02 PM, Tony Esposito=0A wrote:=0A> .=0A>=
.=0A> .=0A> while(@dat =3D $sth->fetchrow) {=0A> print "@dat\n";=0A=
> .=0A> .=0A> .=0A>=0A> This code works yet there is no 'my @dat' defined a=
nywhere in the code.=0A> Using Perl 5.8.x - 5.14.x=0A>=0A> Q: Why does the =
variable @dat not need a 'my' in front?
See `perldoc strict'. In parti=
cular, the "strict vars" section.
=0A-- =0ABrandon McCaig
bamccaig.com/> =0AV zrna gur orfg jvgu jung V fnl. Vg q=
brfa'g nyjnlf fbhaq gung jnl.=0ACastopulence Software
nce.org/> =0A
--0-1759626266-1313176531=:52794--
Re: while(@data) works but why
am 12.08.2011 21:17:54 von Tony Esposito
--0-1623414873-1313176674=:70994
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
It was the absence of the 'use strict;' that permitted the execution.=0ANow=
fails if 'use strict;' is added to code and 'my' is missing.=0AAdded 'use =
strict;' and 'my'.
Cheers!
=0A___________________________ __=
___=0AFrom: Jim Gibson =0ATo: beginners@perl.org=0ASe=
nt: Fri, 12 August, 2011 14:13:26=0ASubject: Re: while(@data) works but why=
On 8/12/11 Fri Aug 12, 2011 12:02 PM, "Tony Esposito"=0A
7893@yahoo.co.uk> scribbled:
> .=0A> .=0A> .=0A> while(@dat =3D $sth->=
fetchrow) {=0A> print "@dat\n";=0A> .=0A> .=0A> .=0A> =0A> This cod=
e works yet there is no 'my @dat' defined anywhere in the code.=0A> Using P=
erl 5.8.x - 5.14.x=0A> =0A> Q: Why does the variable @dat not need a 'my' i=
n front?
It does on my system:
#!/usr/local/bin/perl=0Ause strict=
;=0Ause warnings;
use DBI;
my $sth =3D DBI->connect();
while=
( my @dat =3D $sth->fecthrow) {=0A print "dat: ", join(",",@dat), "\n";=0A=
}
% perl -c esposito.pl=0AGlobal symbol "@dat" requires explicit packa=
ge name at esposito.pl line 9.=0AGlobal symbol "@dat" requires explicit pac=
kage name at esposito.pl line 10.=0Aesposito.pl had compilation errors.=0A=
=0Aperl v5.10.1
-- =0ATo unsubscribe, e-mail: beginners-unsubscr=
ibe@perl.org=0AFor additional commands, e-mail: beginners-help@perl.org=0Ah=
ttp://learn.perl.org/
--0-1623414873-1313176674=:70994--