Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Re: [RedRum] top 5 search terms global

Quote Reply
Re: [RedRum] top 5 search terms global In reply to
What I meant, in the short hand, was the variable was defined with "my" inside the while loop.

You need to do that OUTSIDE the while loop, and _yes_ in this case, you _do_ need to pre-declare it, pre-set the scope, or otherwise tell the compiler what to do with the variable before it's actually "used".

Remember, Links SQL needs to be mod_perl compatible, and since you are first using the $output _inside_ a loop, then returning it outside the loop at the end of the routine, you do need to pre-declare it.

"my" sets the scope of the variable. If you don't like the term "pre-declare" then use the term "set the scope" before you use it.

I actually _like_ thinking in terms of pre-declare, since it brings me back to my early days, and it makes sure I have defined, set up, and set the scope on, all the variables I need to use.

Perl allows a lot of bad behavior, and that is good for quick and dirty programs as it was originally set up for, but OO Perl requires a whole different mindset, and programming style.

One of my constructs is I usually set the variables with "my" near where they are first used. But, I _only_ do that if that is only where they are going to be used -- ie: within a few lines of where they were originally declared. If not, I still define them at the top of the program, begining of the loop or block, or where it makes the most sense.

A great example is $sth used as the statement handle. If you only use it in the 2 lines required to set it, and then iterate it, it is fine to declare it with $my where it's first assigned. _but_ if you are going to use it multiple times, or with multiple options, it's better to define it at the top of the block, or subroutine, since it no longer belongs to a single statement, and in trying to maintain the code a few weeks or months later, you will start to wonder where $sth was originally scoped/declared and who owns it.

Most of Perl is creative and liberal use of white space and style. The more consistent you are, the more clear you are, the better your scripts will go together, and the easier they will be to read and maintain.




PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Subject Author Views Date
Thread top 5 search terms global katabd 19760 Nov 4, 2001, 11:01 AM
Thread Re: [katabd] top 5 search terms global
Alex 18583 Nov 4, 2001, 12:13 PM
Thread Re: [Alex] top 5 search terms global
katabd 18612 Nov 4, 2001, 1:21 PM
Thread Re: [katabd] top 5 search terms global
pugdog 18490 Dec 28, 2001, 1:57 PM
Post Re: [pugdog] top 5 search terms global
katabd 18479 Dec 28, 2001, 2:30 PM
Thread Re: [katabd] top 5 search terms global
pugdog 18435 Dec 29, 2001, 5:12 PM
Thread Re: [pugdog] top 5 search terms global
Paul 18526 Dec 30, 2001, 3:28 AM
Thread Re: [RedRum] top 5 search terms global
pugdog 18406 Dec 30, 2001, 7:21 AM
Post Re: [pugdog] top 5 search terms global
Paul 18505 Dec 30, 2001, 7:35 AM
Thread Re: [katabd] top 5 search terms global
Paul 18605 Dec 30, 2001, 7:51 AM
Post Re: [RedRum] top 5 search terms global
pugdog 18442 Dec 30, 2001, 9:04 AM
Thread Re: [RedRum] top 5 search terms global
katabd 18372 Mar 10, 2002, 6:54 PM
Thread Re: [katabd] top 5 search terms global
Paul 18370 Mar 11, 2002, 2:42 AM
Thread Re: [RedRum] top 5 search terms global
katabd 18424 Mar 11, 2002, 3:41 AM
Thread Re: [katabd] top 5 search terms global
katabd 18486 Mar 11, 2002, 7:58 PM
Thread Re: [katabd] top 5 search terms global
Paul 18289 Mar 12, 2002, 1:45 AM
Thread Re: [RedRum] top 5 search terms global
katabd 18317 Mar 12, 2002, 4:03 AM
Thread Re: [katabd] top 5 search terms global
Paul 18370 Mar 12, 2002, 4:13 AM
Thread Re: [RedRum] top 5 search terms global
katabd 18331 Mar 12, 2002, 5:04 AM
Thread Re: [katabd] top 5 search terms global
waxxie 17912 May 20, 2003, 8:34 AM
Thread Re: [waxxie] top 5 search terms global
pugdog 17936 May 20, 2003, 8:45 AM
Thread Re: [pugdog] top 5 search terms global
waxxie 18013 May 20, 2003, 9:22 AM
Thread Re: [waxxie] top 5 search terms global
Paul 17937 May 20, 2003, 9:58 AM
Thread Re: [Paul] top 5 search terms global
waxxie 17841 May 20, 2003, 10:04 AM
Thread Re: [waxxie] top 5 search terms global
waxxie 17946 May 20, 2003, 1:52 PM
Thread Re: [waxxie] top 5 search terms global
webslicer 8957 May 22, 2003, 12:13 PM
Post Re: [webslicer] top 5 search terms global
Paul 8903 May 22, 2003, 1:39 PM
Thread Re: [webslicer] top 5 search terms global
waxxie 8893 May 22, 2003, 2:45 PM
Thread Re: [waxxie] top 5 search terms global
gundamz 8853 Dec 26, 2003, 11:20 PM
Post Re: [gundamz] top 5 search terms global
Gypsypup 8753 Dec 26, 2003, 11:39 PM
Thread Re: [gundamz] top 5 search terms global
pugdog 8728 Dec 27, 2003, 8:05 AM
Thread Re: [pugdog] top 5 search terms global
tenoch 8657 Mar 18, 2006, 4:54 PM
Thread Re: [tenoch] top 5 search terms global
pugdog 8641 Mar 18, 2006, 8:31 PM
Thread Re: [pugdog] top 5 search terms global
tenoch 8718 Mar 19, 2006, 8:03 PM
Post Re: [tenoch] top 5 search terms global
pugdog 8528 Mar 28, 2006, 10:11 AM
Thread Re: [katabd] top 5 search terms global
HopeForYou 8340 Jun 1, 2009, 7:56 PM
Post Re: [HopeForYou] top 5 search terms global
Andy 8280 Jun 1, 2009, 11:52 PM