David T-G wrote at Wed, 12 Jun 2002 19:42:46 +0200:

> ...
> %   - Now Perl's complaining about many no declared variables. %   - You declare 
>them all at the
> beginning.
> 
> In this limited context, yes.  I wouldn't usually declare them all up front.
>

Well, I thought you never do (as I know you're not a beginner any more)
But I know, some beginners do, so I was a little bit provocant :-)
 
> 
> %   - Now Perl gives warnings because there are some undefined variables. %   - Now 
>you want to
> assign all variables values like "", 0, () or so for the beginning.
> 
> Well, not necessarily.  I didn't really need
> 
>   my ($a, @b, %c) = "" ;
> 
> [ignoring for the moment that that doesn't work] but that instead grew out of my 
>original
> requirements.  If you look at
> 
>   my ($artist, $album, $track) ;
>   while (<>)
>   {
>     ($artist, $album, $track) = split(/\//);
>     if ( $track eq "foo" )
>     ...
>   }
>   }

I would try to write it as
while (<>) {
   my ($artist, $album, $track) = split m:/:;
   if ($track eq $foo) {   # $foo eq "$foo" :-)
      ...
   }
}

> %
> % I think, that it is my obligation to warn you
> % that use strict; use warnings; wasn't made for that way.
> 
> Now, them's fightin' word, pardner!  Into the street!

I like fightings :-)
But to say the truth, it reads harder than I meant it.
Of course, TMTWTDI, as I only wanted to say, it could be dangerous this way.

Again it was adressed to the many beginners outside the world.
In fact, curiously, to understand why strict declarations and warnings are needed,
it's more a problem to java beginners than to perl beginners.
I still try to understand why :-)

> %
> % If the variables are declared at the beginning,
> % assigned with the standard values for undefined values. % you only can check (a).
> 
> Hmmm...  Well, I'll grant you that, but what about the example above?  It would only 
>be undef for
> the first N lines that are short, and once it gets loaded then it will get reset 
>instead.  It
> seems more sensible to set it to a defined but appropriate value for the upcoming 
>loop than to
> integrate single-case undef logic into the loop, no?
> 

Yep, you're right!
(But taking my way would force every loop an undef, doesn't it :-))

> I still don't quite get the whole "our"/"local" think yet.  Still workin' on that.

Oh, and I have always problems to explain it.
Well, when you'll understand the philosphy you never want to go back.
It's like the difference between the goto statement from BASIC and subroutines.

> At the moment I'm storing then in a hash as
> 
>     $threez{$fullpath} =
>       [($mp3,$source,$host,$artist,$disk,$track)] ;
> 
> and will move that to a DB routine that will write to a hash, a flat file, a 
>database, or whatnot
> -- and then I can pass it the parameters (where it will scope them locally) from 
>this "read in
> some more data" subroutine, which will also scope them locally.

That sounds good.

> 
> Given all of that (*whew*), does it sound like I'm on the right track or instead 
>still Not Getting
> It Even If TMTOWTDI?
> 

Yes.
There are only some ways with a little bit more adventure :-)

(It's like with doubled code which one is an alert signal for me too for various 
reasons.)

Cheerio,
Janek


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to