473,486 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Perl strict and "my"

1 New Member
Hello,

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
  1. #!/usr/bin/perl -w
  2. # v1.pl
  3. # Works as supposed and connects to the database.
  4. use strict;
  5. use DBI;
  6. use DBD::mysql
  7.  
  8. my $Username = "a";
  9. my $Password = "b";
  10. my $Hostname = "c";
  11. my $Database = "d";
  12.  
  13. my $dsn        = "dbi:mysql:$Database:$Hostname:3306";
  14. my $connect    = DBI->connect($dsn, my($Username), $Password);
  15.  
  16.  
$ perl -c v1.pl
v1.pl syntax OK

but this doesn't work at all:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. # v2.pl
  3. # This one fails
  4. use strict;
  5. use DBI;
  6. use DBD::mysql
  7.  
  8. my $Username = "a";
  9. my $Password = "b";
  10. my $Hostname = "c";
  11. my $Database = "d";
  12.  
  13. my $dsn        = "dbi:mysql:$Database:$Hostname:3306";
  14. my $connect    = DBI->connect($dsn, $Username, $Password);
  15.  
  16.  
$ perl -c v2.pl
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.
Feb 26 '08 #1
1 1828
KevinADC
4,059 Recognized Expert Specialist
using "strict" will help you to write good perl code. It may be hard to see how or why it does, but keep using it.
Feb 26 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

20
11636
by: Chris Krasnichuk | last post by:
hello, Does anyone know how I make php work on "my" computer? I made a mistake in my last post so I fixed it here. Chris
4
1825
by: babylon | last post by:
I created a class which inherits from UserControl.. However, I can't find it in the "My User Controls" tab in designer view... How can i add it back myself? thx...
0
2438
by: Grant_S | last post by:
I need to identify the path to a users "My Document" folder where the user has a roaming profile and their "My Documents" folder is mapped to a network share as the H drive (specifically H:\\ -...
4
1641
by: yaipa | last post by:
All, I've been asked by my boss to put an Icon in WinXP's "My Computer" for a utility we use around the shop. My tool of choice is of course Python and therefore what I am using to attempt my...
0
1307
by: John Phelan | last post by:
It use to work. I created numerous coppies of my MS Access2003 developed application for distribution using both the new "Startup" and "Package and Deployment" wizards (that incudes "autorun"...
3
1628
by: Claire | last post by:
Sorry for such a daft question. Ive been following some tutorials on creating windows services. Ive not done them before. In my original debuggable windows form application, I create my worker...
3
2237
by: Chris Mahoney | last post by:
Hi I have two machines, one running Win 2000 and VS.NET 2002, and one running Mac OS 10.2. I can develop web apps on my Windows machine, and look at them in IE, and they look fine. But if I...
8
4410
by: Just Me | last post by:
1)How can I find the folders like "My Recent Document", "Desktop", "My Pictures",... if I want to store a file there? 2) How can I find the icon for those files if I want to display it? ...
6
2122
by: JamesG | last post by:
I'm trying to convert a unix timestamp to a readable time, such as 4 hours ago, or 25 minutes ago. My code is below: function ago($ts) { /* time difference */ $ts = (time() - $ts); if($ts <...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.