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

Re: [MacPerl] Code cleaning and questions

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
> 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) {
    print $num = ord $_;
    $num > 127 and warn "WARNING -- ASCII value exceeds 127.\n";

Such as:

  @characters = split(//, $line);    # null pattern splits into chars
  foreach $character (@characters) {
      $num = ord($character);
      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

> 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
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