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

Re: [MacPerl] Counting lines in a document opened in Append mode.



At 12:23 26/04/96 -0500, "Robert A. Decker" <comrade@umich.edu> wrote:

> #this method works when I open $queue_file_path in write mode, but not
> #when I open it in append mode (it always reports it as having 0 lines)

????

All the methods descibed require you to open the file in *read* mode. So I
suggest you close your file, and reopen it to read the contents. Then you
can use any of the methods described.

>            print "this is a confirmation of success", "\n";
>            print "option = ", $option, "\n";
>            print "calltaker = ", $calltaker, "\n";
>...

Obviously, you haven't discovered the use of "interpolation", i.e.
replacement of variables by their value in strings:

        print "option = $option\n";

will fill in the value of $option in the result.


Also, use of $\ could be benificial: $\ determines what comes at the end of
a print instruction. Default value is nothing. Also, $, determines what is
printed instead of the comma's between fields (and between elements of
arrays). Defaults also to nothing.

So:

        $\="\n";
        print "this is a confirmation of success";
        print "option = $option";
        print "calltaker = $calltaker";

looks a bit simpler, and will produce the same results.

Also: if you define:

        @letters=('A','B','C','D');
        $\="\n"; $,=" -- ";
        print 1,2,3;
        print @letters;

will produce

        1 -- 2 -- 3
        A -- B -- C -- D



Another alternative: if you type a *lot* of literal strings, how about:

print(<<END);
this is a confirmation of success
option = $option
calltaker = $calltaker
...
END

You may replace "END" in both places by any string (without whitespace) you
choose. Only make sure it doesn't appear all alone in your text. (Don't set
$\ to "\n" in this case).

You could use
print(<< );
...

followed by *one empty line*. Now you must only make sure your text doesn't
contain any empty lines.

 
Thought this was just good to know.


--- Embracing the KIS principle: Keep It Simple