homepage Welcome to WebmasterWorld Guest from 54.235.36.164
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Beginner's question on coding with perl
runner




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

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?

 

PhraSEOlogy




msg:435957
 7:26 pm on Jan 20, 2005 (gmt 0)

Try googling:

defining local variables my

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

Lord Majestic




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

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.

runner




msg:435959
 7:34 pm on Jan 20, 2005 (gmt 0)

I guess that answers my question!

SeanW




msg:435960
 4:11 pm on Jan 21, 2005 (gmt 0)


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

moltar




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

use strict and my saves hours of development time on daily basis :)
satanclaus




msg:435962
 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.

wruppert




msg:435963
 3:21 am on Feb 1, 2005 (gmt 0)

Definitely strongly agree with "use strict".

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

runner




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

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.

moltar




msg:435965
 11:15 pm on Feb 1, 2005 (gmt 0)

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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved