[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Code cleaning and questions



Thank you very much Vicki for your objective analysis of my problem with the
documentation and while I did read a lot, I missed some of the items that I
asked about.  I am still reading and still trying to piece things together, so
I hope you seasoned veterans have patience and understanding as I get up to
speed.  Who knows, I may be asked one day to help and I might actually be able
to.

Vicki Brown wrote:

> At 14:28 -0400 6/24/99, Ronald J Kimball wrote:
> >
> > I'm afraid I don't have MacPerl: Power and Ease, so I don't know where in
> >the
> > book $_ is explained.
>
> Horrors! ;0)
>
> $_ is first discussed on p. 130, ch. 9 "Odd Corners") (That one missed the
> Index :-(
>
> If one is first learning Perl, $_ is a bit new.  And there is a certain
> ratinale for spreading things out while you "get the hang of it".
>
> When going from the C-ish syntax (which _is_ legal Perl, of course :-)
>
>     for ($i=1;$i <= length($line);$i++) {
>        $num = ord(substr($line, $i, 1));
>
> Perhaps there is a workable compromise on the way to the very idiomatic:
>
>   foreach (split //, $line) {

This is not self explanatory to me coming from the 4th Dimension/C
environment.  There seems to be a lot of steps missing from this statement,
which doesn't seem to bother MacPerl near as much as it does me.  Until you
read about $_ you don't know where the blazes it assigns the results of the
function.  I still have a problem with split in that it will take a horizontal
reference and make it vertical.  In other words, the above line takes a word
which is read from left to right and makes you have to reference vertically as
in elements of an array.  This is still hard to get used to as indicated by
the above statement that some referred to as C like.  I was able to go from
left to right and do my thing on each character.

>
>     print $num = ord $_;

This is wild but not totally out of wack, since C can have functions and
assignments on the same line without any delimiters for each statement.

>
>     $num > 127 and warn "WARNING -- ASCII value exceeds 127.\n";
>   }
>
> Such as:
>
>   @characters = split(//, $line);    # null pattern splits into chars

As I see examples like this I will know from that moment on to look for and
practice specific shortcut patterns of programming.

>
>   foreach $character (@characters) {
>       $num = ord($character);
>       print("$num,");
>       if ($num > 127) {
>           print ("\n\nW A R N I N I N G -- ASCII value exceeds 127\n\n");
>       }
>   }
>
> This also has the attraction of being more explicit about what's going on

It definitely does make more sense since the functionality is obvious.

>
>
> > Tip #1.  Read the documentation.
>
> An excellent idea. However, to some extent, this begs the age-old
> question... before one can successfully hope to RTFM, how does one
> determine which FM to R?  There are oodles (both megabytes and reams) of
> fine documentation for Perl (and digging/scrolling through the online stuff
> is not everyone's cup of tea). You can also read the FAQs... if you are

Like myself, I am a digger but still didn't see reference to 2 of the items in
my code in one place.  They were referenced in 2 completely different sets of
documentation.

>
> lucky enough to be phrasing your question in the same way.
>
> Some people do best with a real paper book on the desk, walking through it
> from the beginning (and Robert, while he has ordered the book (bless him
> :-) doesn't yet have a book).
>
> If one is coming from a C background, how does one know to use split?  How
> does one know to look for split?
>
> Admittedly, split is the right tool, but _how does one know that_ until
> being told? (in MP:P&E, split is discussed on p. 88 in ch. 6 in the section
> "Breaking Data Apart"). (sigh... this also missed the index :(
>
> -- --
>        |\      _,,,---,,_       Vicki Brown <vlb@cfcl.com>
>  ZZZzz /,`.-'`'    -.  ;-;;,_   Journeyman Sourceror: Scripts & Philtres
>       |,4-  ) )-,_. ,\ (  `'-'  P.O. Box 1269  San Bruno  CA  94066
>      '---''(_/--'  `-'\_) http://www.cfcl.com/~vlb  http://www.macperl.com


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org