Re: how would you work with this material

2002-12-27 Thread Tad McClellan


On Thu, Dec 26, 2002 at 10:21:39PM -0800, Michael R. Wolf wrote:
 
 What do you think of material that has this material?  


That it is not making effective use of the time available.

Perl is a large language. There can never be enough time, so
you have to be hard-hearted about what you'll spend the time on...

Also, it presents error-prone ways of doing things when they
can easily be done more safely. ie. it seems to prefer tricks
rather than solid Software Engineering.


 How would you present it to students in an Intro to Perl Programming
 course?


I don't recommend doing this, but you might see it in other people's
code, so I'll cover it quickly so you'll understand it if you see it.


 What would you do about it if you were employed by the company that
 wrote it?


Whine.


 What about if you contracted to them?


Replace it with something more valuable, or at least be
brisk and caveat it.


 Changing the $#array also changes the length of the array
 
 Similar to using the pop function


TMTOWTDI is nice, but a clear way is better than an obsure way.

I'd teach the clear way and save the obscure way time 
for something else.


 @teams = (redsox,yankees, bluejays,rockies,giants,mariners);
 print Last element int he Array: $#teams\n;


Errr, the last element in the array is mariners, not 5  :-)


 print \@teams has  .($#teams + 1).  elements\n;

   print \@teams has  . @teams .  elements\n;

will do the same thing, and avoid the possibility of the
famous off by one class of mistakes.


 This funciton is useful for loopping through the array


But not as useful as foreach.


 for($i=0; $i  $#teams+1; $i++) 


If you maintain the index yourself, you have the possibility
of making a mistake. If you use foreach instead, perl will do
the indexing for you.

Machines don't make mistakes, people do, so it's better to
leave it to a machine when possible.


 To grow or shrink the array, you simply change the value of the last
 index in the array


That is the obscure way. The clear way it to just put in into
the array (push/splice), and let perl grow it for you.

(unless you anticipate the array becoming very large, but
 beware of premature optimization...
)


 Output:
 
 Elements 11
 1, 2, 3,  , 300, , , , , , 


Errr, where are all of the uninitialized warning messages?  grin


 - Get better performance behind the scenes by creating the array and
   growing it to the required length first instead of building it
   element by element.


Beware, as above.


 It is possible to empty an array by setting its length to a negative
 number

 @#array = -1;
  ^
  ^

I'll ignore the typo.

That's the obscure way.

@array = ();   # the clear way


Is job security the primary objective of the class?  grin again


 -- 
 Michael R. Wolf
 All mammals learn by playing!


Some lessons are better learned later, when you time to kill.


-- 
Tad McClellan  SGML consulting
[EMAIL PROTECTED]   Perl programming
Fort Worth, Texas



Re: how to copy a file ?

2005-01-02 Thread Tad McClellan

On Sun, Jan 02, 2005 at 02:27:00PM +0200, Gabor Szabo wrote:
 
 The other day in a class I was teaching as I was showing how
 to copy a file using File::Copy someone asked (as that happens
 always) how could he find out the answer alone to this and
 similar questions.
 I pointed to various sources such as
 
 perldoc -q   but it has no anse to this question


I think it is asked often enough qualify for frequently asked status.

There should be a How do I copy a file? question added to the FAQ.


-- 
Tad McClellan  SGML consulting
[EMAIL PROTECTED]   Perl programming
Fort Worth, Texas


finding help (was Re: how to copy a file ?)

2005-01-02 Thread Tad McClellan

On Sun, Jan 02, 2005 at 02:27:00PM +0200, Gabor Szabo wrote:


 someone asked (as that happens
 always) how could he find out the answer alone to this and
 similar questions.
 I pointed to various sources such as

[snip std docs]

I think the docs have let us down with regards to file copying
(even if it does depend on OS/filesystem more than a
particular programming language).


 I pointed to vairous mailing lists for beginners and even to PerlMonks.


I mention Usenet newsgroups, lists.perl.org and PerlMonks.


 What do you ppl. tell them, 


   Tens of thousands of people have already learned Perl. It is
   not very likely that you are the first person to have your
   question. It has probably been asked and answered already,
   all you have to do is go find out where.

   http://groups.google.com/advanced_group_search is my very top
   bookmark, even ahead of regular google. I use it for many
   things besides Perl too, picked up lots of useful info there
   for my family's trip to DisneyWorld for example.


Do the lists or Monks have useful search functions that I could mention?


 how to learn more 


I spew out these suggestions at the conclusion of the training:

   solve a problem from work

   solve a problem from your personal interests or hobbies

   find an existing Perl program at work to maintain or modify

   find someone already using Perl and ask them what they're doing

   rewrite well-understood commands in Perl, eg. ls, grep

   find questions in some forum, decide what answer you would give,
  monitor what answers others give, when those begin matching
  up often enough, start actually posting your answers  :-)

   watch other people doing any of the above in some forum, by
   participating or by just searching.


 and get answers to such 
 questions ?


I encourage them to email me questions, but they almost never do.

So I present the checklist below (I've injected significant editorial
bias starting at step #6).

It could be applied to lists/Monks rather than Usenet as well.


--
Perl problem resolution checklist:
--

1) check the Perl FAQs 

   (word search with perldoc -q. Or better, find where the 
*.pod's are on your system, and word search (grep) the 
entire contents of the files)

2) expand the above to _all_ of the standard *.pod files.

3) check a Usenet archive such as:

  http://groups.google.com/advanced_group_search

4) check books, websites, mailing lists (this step is optional)

5) write a Usenet article, but don't post it yet!

   5a) make a small and complete (including data) program that 
   people can execute that shows your problem.

   5b) state how the program's output is not what you want. Describe
   what you do want.

   5c) repeat steps 1-4 using search terms taken from your description
   of the problem or your Subject header (try some synonyms for
   the terms also)

6) Give up on a quick answer. Post to Usenet for a slow answer.

7) wait hours/days/forever for followups with answers rather than
   than the 5 or 10 minutes it would have taken if steps 1-3
   had worked.

8) Wonder at the quality of the answers given, rather than know
   it is a peer-reviewed, validated answer if steps 1-2 had worked.

9) Repeat steps 1-3 many times for many problems. You will seldom
   get past step 3, and even less often get past step 5a.

10) Now that you know so much, go *answer* some questions on Usenet  :-)


-

To help with 1 and 2 above, I make headlines files to grep in,
because sometimes there is Too Much Information when grepping
the entire bodies:

   cd /an/INC/dir/pod/

   grep '^=' perlfaq[1-9].pod faq.heads

   grep '^=' *.pod all.heads


It is sometimes helpful to use an Initial Cap on the search term,
under the assumption that headlines and beginnings of sentences
might be most relevant.



-- 
Tad McClellan  SGML consulting
[EMAIL PROTECTED]   Perl programming
Fort Worth, Texas


Re: How to get people use forums and mailing lists [was Re: Career Help Urgent!]

2006-05-17 Thread Tad McClellan

On Wed, May 17, 2006 at 07:07:23PM +0200, Amir E. Aharoni wrote:

 I also introduced them to comp.lang.perl.*


I present a triple-whammy:

Usenet as above, plus www.perlmonks.com and lists.perl.org.


-- 
Tad McClellan  SGML consulting
[EMAIL PROTECTED]   Perl programming
Fort Worth, Texas