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 19647 Nov 4, 2001, 11:01 AM
Thread Re: [katabd] top 5 search terms global
Alex 18471 Nov 4, 2001, 12:13 PM
Thread Re: [Alex] top 5 search terms global
katabd 18499 Nov 4, 2001, 1:21 PM
Thread Re: [katabd] top 5 search terms global
pugdog 18378 Dec 28, 2001, 1:57 PM
Post Re: [pugdog] top 5 search terms global
katabd 18366 Dec 28, 2001, 2:30 PM
Thread Re: [katabd] top 5 search terms global
pugdog 18322 Dec 29, 2001, 5:12 PM
Thread Re: [pugdog] top 5 search terms global
Paul 18412 Dec 30, 2001, 3:28 AM
Thread Re: [RedRum] top 5 search terms global
pugdog 18293 Dec 30, 2001, 7:21 AM
Post Re: [pugdog] top 5 search terms global
Paul 18392 Dec 30, 2001, 7:35 AM
Thread Re: [katabd] top 5 search terms global
Paul 18493 Dec 30, 2001, 7:51 AM
Post Re: [RedRum] top 5 search terms global
pugdog 18330 Dec 30, 2001, 9:04 AM
Thread Re: [RedRum] top 5 search terms global
katabd 18259 Mar 10, 2002, 6:54 PM
Thread Re: [katabd] top 5 search terms global
Paul 18257 Mar 11, 2002, 2:42 AM
Thread Re: [RedRum] top 5 search terms global
katabd 18311 Mar 11, 2002, 3:41 AM
Thread Re: [katabd] top 5 search terms global
katabd 18374 Mar 11, 2002, 7:58 PM
Thread Re: [katabd] top 5 search terms global
Paul 18176 Mar 12, 2002, 1:45 AM
Thread Re: [RedRum] top 5 search terms global
katabd 18205 Mar 12, 2002, 4:03 AM
Thread Re: [katabd] top 5 search terms global
Paul 18257 Mar 12, 2002, 4:13 AM
Thread Re: [RedRum] top 5 search terms global
katabd 18217 Mar 12, 2002, 5:04 AM
Thread Re: [katabd] top 5 search terms global
waxxie 17801 May 20, 2003, 8:34 AM
Thread Re: [waxxie] top 5 search terms global
pugdog 17824 May 20, 2003, 8:45 AM
Thread Re: [pugdog] top 5 search terms global
waxxie 17900 May 20, 2003, 9:22 AM
Thread Re: [waxxie] top 5 search terms global
Paul 17825 May 20, 2003, 9:58 AM
Thread Re: [Paul] top 5 search terms global
waxxie 17728 May 20, 2003, 10:04 AM
Thread Re: [waxxie] top 5 search terms global
waxxie 17832 May 20, 2003, 1:52 PM
Thread Re: [waxxie] top 5 search terms global
webslicer 8871 May 22, 2003, 12:13 PM
Post Re: [webslicer] top 5 search terms global
Paul 8819 May 22, 2003, 1:39 PM
Thread Re: [webslicer] top 5 search terms global
waxxie 8810 May 22, 2003, 2:45 PM
Thread Re: [waxxie] top 5 search terms global
gundamz 8769 Dec 26, 2003, 11:20 PM
Post Re: [gundamz] top 5 search terms global
Gypsypup 8668 Dec 26, 2003, 11:39 PM
Thread Re: [gundamz] top 5 search terms global
pugdog 8644 Dec 27, 2003, 8:05 AM
Thread Re: [pugdog] top 5 search terms global
tenoch 8573 Mar 18, 2006, 4:54 PM
Thread Re: [tenoch] top 5 search terms global
pugdog 8557 Mar 18, 2006, 8:31 PM
Thread Re: [pugdog] top 5 search terms global
tenoch 8633 Mar 19, 2006, 8:03 PM
Post Re: [tenoch] top 5 search terms global
pugdog 8444 Mar 28, 2006, 10:11 AM
Thread Re: [katabd] top 5 search terms global
HopeForYou 8255 Jun 1, 2009, 7:56 PM
Post Re: [HopeForYou] top 5 search terms global
Andy 8195 Jun 1, 2009, 11:52 PM