Welcome to WebmasterWorld Guest from 107.22.87.205

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Beginner's question on coding with perl

     
7:18 pm on Jan 20, 2005 (gmt 0)

10+ Year Member



I've been programming in half a dozen languages for some time now and I recently picked up perl. I have no formal training in perl so forgive my ignorance if this question sounds stupid. My question concerns the use of "my" when defining variables. In all the perl programs I've written I never used "my" for anything. I assume it's a way of defining local variables that are not available outside the local environment. What is the purpose of defining local variables like this? And... should I be doing this?
7:26 pm on Jan 20, 2005 (gmt 0)

10+ Year Member



Try googling:

defining local variables my

You will find some good information on how to use 'my' and why to use it.

7:29 pm on Jan 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Once you waste a few good hours debugging your software only to find out that bug was due to local variable with the same name as global, thus masking global var's value that you actually needed, you will appreciate necessity to always "use strict" in Perl, and therefore use "my" to declare variables explicitly.
7:34 pm on Jan 20, 2005 (gmt 0)

10+ Year Member



I guess that answers my question!
4:11 pm on Jan 21, 2005 (gmt 0)

10+ Year Member




always "use strict" in Perl, and therefore use "my" to declare variables explicitly

If there were one thing every perl newbie should learn, that is it.

Sean

4:14 pm on Jan 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



use strict
and
my
saves hours of development time on daily basis :)
6:26 pm on Jan 24, 2005 (gmt 0)



Pick up the Oreilly Programming Perl book and look at the scoping functions in chapter 29 which lists all the functions. That chapter alone has pushed me far into PERL usage.
3:21 am on Feb 1, 2005 (gmt 0)

10+ Year Member



Definitely strongly agree with "use strict".

Also, "use warnings" (or perl -W) and provide prototypes for your subroutines.

10:52 pm on Feb 1, 2005 (gmt 0)

10+ Year Member



I've got <i>Programming Perl</i> third edition. I'll read chapter 29 tonight. I'm almost afraid to become enlightened because I'll have to go and rewrite all my scripts. I'd better get started.
11:15 pm on Feb 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, once you learn a few perl tricks, you will love it! And you will write scripts much faster. There will be no way back. Perl helps me every day!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month