473,549 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ 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 1833
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
11641
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
1829
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
2451
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:\\ - where the "My Received Files" folder path then is H:\\My Refeceived Files. The double \\ is not an escape character as subfolders only have sinvle "\"...
4
1648
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 given task. I have no trouble putting Icons in the WinXP Toolbar using Python, but have totally failed to get an Icon to appear in My Computer. Any...
0
1312
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" that is automatically customized for my application) that is a part of "Visual Studio Developer Extensions". After burning each CD, I used each copy...
3
1632
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 classes. The classes 'run' themselves using several threads and only stop when the form is closed. Now I've used these worker classes in the service...
3
2245
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 try to view my pages in Safari (Apple's web browser) on my Mac, there are various formatting problems. I've investigated what's happening and it...
8
4416
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? Thanks in advance for any helpful suggestions
6
2128
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 < 60) { /* <1 minute */
0
7524
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7960
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5372
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3501
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
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 we have to send another system
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
766
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.