I started out learning Perl today, but strict mode is just *weird* and not usefull? Why should I use it?
What makes $Username different than the other variables?
I was wondering, why I have to use "my ($Username)" to get this working:
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl -w
- # v1.pl
- # Works as supposed and connects to the database.
- use strict;
- use DBI;
- use DBD::mysql
- my $Username = "a";
- my $Password = "b";
- my $Hostname = "c";
- my $Database = "d";
- my $dsn = "dbi:mysql:$Database:$Hostname:3306";
- my $connect = DBI->connect($dsn, my($Username), $Password);
v1.pl syntax OK
but this doesn't work at all:
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl -w
- # v2.pl
- # This one fails
- use strict;
- use DBI;
- use DBD::mysql
- my $Username = "a";
- my $Password = "b";
- my $Hostname = "c";
- my $Database = "d";
- my $dsn = "dbi:mysql:$Database:$Hostname:3306";
- my $connect = DBI->connect($dsn, $Username, $Password);
Global symbol "$Username" requires explicit package name at v2.pl line 14.
v2.pl had compilation errors.
$ perl -v
This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi
edit: it was the missing ; after "use DBD::mysql". Sorry, my mistake.