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

MacPerl-Digest V1 #11




MacPerl-Digest        Saturday, March 13 1999        Volume 01 : Number 011



Re: [MacPerl] Elementary question (I think)
Re: [MacPerl] Elementary question (I think)
[MacPerl] New Mac::OSA::Simple, p2as
[MacPerl] Re: [MacPerl-Toolbox] New Mac::OSA::Simple, p2as
Re: [MacPerl] Re: [MacPerl-Toolbox] New Mac::OSA::Simple, p2as
[MacPerl] Another elementary question
[MacPerl] Re: More General XML Help
Re: [MacPerl] Another elementary question
Re: [MacPerl] Another elementary question
Re: [MacPerl] Another elementary question
Re: [MacPerl] Another elementary question
Re: [MacPerl] Another elementary question
Re: [MacPerl] Another elementary question

----------------------------------------------------------------------

Date: Fri, 12 Mar 1999 06:55:19 -0600
From: Greenblatt & Seay <g-s@navix.net>
Subject: Re: [MacPerl] Elementary question (I think)

>Suppose I have an array @stuff, when can and can't I use this syntax:
>
>for ($i = 0; $i <= @stuff, $i++) {
>...
>}

In addition to what others have pointed out after @stuff should be ";" not ",".

David Seay
http://www.mastercall.com/g-s



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

------------------------------

Date: Fri, 12 Mar 1999 14:42:33 +0000
From: Chris Sansom <chris@highway57.co.uk>
Subject: Re: [MacPerl] Elementary question (I think)

I typed clumsily:
>>Suppose I have an array @stuff, when can and can't I use this syntax:
>>
>>for ($i = 0; $i <= @stuff, $i++) {
>>...
>>}

And at 06:55 -0600 12/3/99, Greenblatt & Seay spoke thusly:
>In addition to what others have pointed out after @stuff should be ";" not
>",".

Indeed - typo! I knew that one. :-)

 Cheers ... Chris
 ======================================================================
 Chris Sansom    -    Highway 57   -   Designs for the World Wide Web |
 chris@highway57.co.uk                     http://www.highway57.co.uk |
 ======================================================================



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

------------------------------

Date: Fri, 12 Mar 1999 10:23:01 -0500
From: Chris Nandor <pudge@pobox.com>
Subject: [MacPerl] New Mac::OSA::Simple, p2as

I put up a new Mac::OSA::Simple 0.50 this morning, should be making its
rounds.  Here is a revised p2as that takes advantage of the new save()
method.  It greatly simplifies the script.  It is now very easy to save
something as a compiled AppleScript:

  #!perl -w
  use Mac::OSA::Simple;
  $script = compile_applescript('return "foo"');
  $script->save('HD:Desktop Folder:newscript');

And equally easy to load it in:

  $script2 = load_osa_script('HD:Desktop Folder:newscript');
  print $script2->execute;

Enjoy!  Read the docs in the module if you want to use it directly, there
are some issues you need to know about.

#!perl -w
# p2as
# pudge@pobox.com
# 1999.03.12

use File::Basename;
use Mac::OSA::Simple 0.50 qw(:all);
use Mac::Resources;
use Mac::Memory;
use strict;

sub fix_text (\$);

die "Need at least one Perl script!\n" unless @ARGV;

# select which type of compiled script you want ... hardcode this
# if you like:  Text = 1, Alias = 0
my $switch = MacPerl::Answer('For all scripts, save script text or ' .
     'alias to script on disk?', 'Text', 'Alias');

# drop as many scripts as you can handle
for my $f (@ARGV) {
    my($comp, $data, $res, $script, $len, $file, $dir, $text);

    # get AppleScript text
    $text = ($switch ? get_text($f) : get_alias($f))
        or (warn("No text for '$f'") && next);

    # get new name of file
    ($file, $dir) = fileparse($f, '\..+$');
    $file = "$dir$file.scr";

    # get compiled AppleScript and save it to the file
    $comp = compile_applescript($text);
    $comp->save($file);
}

sub get_alias {
    my($file, $text) = @_;

    fix_text($file);

    $text = qq'tell application "MacPerl" to Do Script alias "$file"';

    $text;
}

sub get_text {
    my($file, $script, $text) = @_;
    local($/, *F);

    open F, $file or die "Can't open '$file': $!";
    $script = <F>;
    close F or die "Can't close '$file': $!";

    fix_text($script);

    $text = <<EOS;
tell application "MacPerl" to Do Script "
$script
"
EOS

    $text;
}

sub fix_text (\$) {
    my $text = shift;

    # more to do than just fix " marks and \ ?
    $$text =~ s/\\/\\\\/g;
    $$text =~ s/"/\\"/g;

    1;
}

__END__

- --
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

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

------------------------------

Date: Fri, 12 Mar 1999 09:49:25 -0600
From: "Jefferson R. Lowrey" <lowrey@mailbag.com>
Subject: [MacPerl] Re: [MacPerl-Toolbox] New Mac::OSA::Simple, p2as

At 10:23 AM -0500 3/12/99, Chris Nandor wrote:
>I put up a new Mac::OSA::Simple 0.50 this morning, should be making its
>rounds.  Here is a revised p2as that takes advantage of the new save()
>method.  It greatly simplifies the script.  It is now very easy to save
>something as a compiled AppleScript:
>

Just a quick thanks for all the hard work you do for MacPerl.  Thanks!

>sub fix_text (\$) {
>    my $text = shift;
>
>    # more to do than just fix " marks and \ ?
>    $$text =~ s/\\/\\\\/g;
>    $$text =~ s/"/\\"/g;
>
>    1;
>}

Do we want to recognize the AppleScript line continuation character?  It
might not be terribly necessary, but there could be instances where people
are reading in scripts that have it.  I'm going to type it in in quotes,
and hope it doesn't get too mangled by mailers "¬".  I assume the AS
compiler recognizes it by ASCII value - but that might not be true.  If so,
it's 194.

- -Jeff Lowrey



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

------------------------------

Date: Fri, 12 Mar 1999 12:03:55 -0500
From: Chris Nandor <pudge@pobox.com>
Subject: Re: [MacPerl] Re: [MacPerl-Toolbox] New Mac::OSA::Simple, p2as

At 10.49 -0500 1999.03.12, Jefferson R. Lowrey wrote:
>>sub fix_text (\$) {
>>    my $text = shift;
>>
>>    # more to do than just fix " marks and \ ?
>>    $$text =~ s/\\/\\\\/g;
>>    $$text =~ s/"/\\"/g;
>>
>>    1;
>>}
>
>Do we want to recognize the AppleScript line continuation character?  It
>might not be terribly necessary, but there could be instances where people
>are reading in scripts that have it.  I'm going to type it in in quotes,
>and hope it doesn't get too mangled by mailers "¬".  I assume the AS
>compiler recognizes it by ASCII value - but that might not be true.  If so,
>it's 194.

It shouldn't need to be escaped, because when in quotes in AppleScript, it
is treated as normal text, which is what is wanted.  So:

  --- script.plx ---
  print "¬"

Becomes:

  --- script.scr ---

  tell application "MacPerl" to Do Script "print \"¬\""

Which does what we want.

- --
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

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

------------------------------

Date: Fri, 12 Mar 1999 12:12:22 -0500
From: "Noe Dinnerstein:  President, BodhiSoftWare" <norbu108@tuna.net>
Subject: [MacPerl] Another elementary question

Still trying to get the hang of file I/O.  With the help the MacPerl list
I've gotten the following script working:

#!perl -w
$iput = "Address.txt"; # name the file, edits much easier. my copy of your
script
$oput = "Report";   # ditto
open (IN, "<$iput") or die ("Input File '$iput' open failed\n");
open (OUT,">$oput") or die ("Output File '$oput' open failed\n");
print ("starting loop\n"); # still to stdout
$x = 0;
while ($line = <IN>) {
			$x++;

				print OUT ("****** RECORD $x **********\n");
    @line = split (/\t/,$line);
      for ($i =0; $i <=$#line; $i++) {

						 print OUT ("Field $i:
$line[$i]\n"); 								#
this uses $_ the default loop variable
      }

   }
print  ("end of loop\n"); # still to stdout
print ("$x records read \n");
close (IN);
close (OUT);

****
When I run it I get the following output:

# Value of <HANDLE> construct can be "0"; test with defined().
File 'DorjeJigje:Programming:MacPerl Ÿ:Noe's Perl Stuff:addRpt3'; Line 8
starting loop
end of loop
1376 records read
******
The problem with this result is that there are only 989 records.  This is a
text file exported from a Hypercard stack and it seems that whenever there
is a <RET> in a large text field, MacPerl interprets that as a record
delimiter. Is there some reliable data massaging that can get the record
delimiter to be properly perceived by MacPerl?  I have WordPerfect and
Microsoft Word, as well SimpleText (although that can't handle such a large
file) but don't know if soft vs. hard returns is the relevant issue when
saving   as a text file.   I'm not aware of the internals of Hypercard
(which is beyond the scope of this mailing list) but figure there must be
some way to do this.  Any help and/or insights would be appreciated.




	Noe

	          \\\
	         (@v@)  W
	          (  O )  //
	            |  | //
	          /  ? |/
	         //     |
	         |||     \
	         M| /\ |
	            ||   ||
	            ||   ||
	            LL  LL
		



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

------------------------------

Date: Fri, 12 Mar 1999 13:35:31 -0400 (AST)
From: Arved Sandstrom <Arved_37@chebucto.ns.ca>
Subject: [MacPerl] Re: More General XML Help

Hi, all

I just wanted to add, to follow up to earlier posts, and to round out an
earlier reply to something Greg Aiken asked, that there are 2 approaches
to parsing XML - tree-based (DOM), and event-based.

SAX is _the_ event-based XML parser. The advantages of this approach are
that a tree is NOT built; events (start of element, for example) are
reported through callbacks. Much less memory intensive.

As things stand, if you are going to do SAX, it's Java. There is some good
stuff out there for SAX. I recommend looking at
<http://www.megginson.com/SAX>.

Python is also considerably further advanced with SAX support than is
Perl.

In other words, if you're interested in XML, you have to be more concerned
about the what ("let me do useful stuff with XML"), and choose your
implementations (Perl, Tcl, Python, Javav) accordingly, than try to
shoehorn everything into "let's do all of this with Perl". An advantage of
Java is that things are more likely to work on Macs. :-)

Hope this helps info-wise. Arved




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

------------------------------

Date: Fri, 12 Mar 1999 15:05:05 -0500 (EST)
From: rjk@linguist.dartmouth.edu (Ronald J. Kimball)
Subject: Re: [MacPerl] Another elementary question

Noe Dinnerstein:  President, BodhiSoftWare wrote:
> 
> When I run it I get the following output:
> 
> # Value of <HANDLE> construct can be "0"; test with defined().
> File 'DorjeJigje:Programming:MacPerl Ÿ:Noe's Perl Stuff:addRpt3'; Line 8

You should fix that...


> starting loop
> end of loop
> 1376 records read
> ******
> The problem with this result is that there are only 989 records.  This is a
> text file exported from a Hypercard stack and it seems that whenever there
> is a <RET> in a large text field, MacPerl interprets that as a record
> delimiter.

That _is_ a record separator.

How do you distinguish between a newline as a record separator and a
newline in the middle of a record?


> Is there some reliable data massaging that can get the record
> delimiter to be properly perceived by MacPerl?

Don't use the record separator in the middle of a record.


> I have WordPerfect and
> Microsoft Word, as well SimpleText (although that can't handle such a large
> file) but don't know if soft vs. hard returns is the relevant issue when
> saving   as a text file.   I'm not aware of the internals of Hypercard
> (which is beyond the scope of this mailing list) but figure there must be
> some way to do this.  Any help and/or insights would be appreciated.

You can either:

Change your script so it can tell the difference between the two uses of
newlines

or

Replace the unwanted newlines before giving the file to your script.


Ronald

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

------------------------------

Date: Fri, 12 Mar 99 13:07:12 -0800
From: Brian McNett <webmaster@mycoinfo.com>
Subject: Re: [MacPerl] Another elementary question

> # Value of <HANDLE> construct can be "0"; test with defined().
> File 'DorjeJigje:Programming:MacPerl Ÿ:Noe's Perl Stuff:addRpt3'; Line 8

I know this isn't really your problem, but when using "strict":

while ($line = <IN>) {

should be

while (defined($line = <IN>)) {

so that you rule out cases where "<IN>" is undefined.

- --Brian

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

------------------------------

Date: Fri, 12 Mar 1999 17:07:12 -0500 (EST)
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: [MacPerl] Another elementary question

> 
> > # Value of <HANDLE> construct can be "0"; test with defined().
> > File 'DorjeJigje:Programming:MacPerl =9F:Noe's Perl Stuff:addRpt3'; Lin=
> e 8
> 
> I know this isn't really your problem, but when using "strict":
> 
> while ($line = <IN>) {
> 
> should be
> 
> while (defined($line = <IN>)) {
> 

The diagnostic is not emitted from the strict pragma, but rather by
the "-w" switch. The strict pragma concerns itself with symbolic
references, unqualified package variables, and barewords that might
actually be subroutines. It doesn't do anything about things that have
an undefined value.

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

------------------------------

Date: Fri, 12 Mar 1999 15:46:08 -0800
From: Rich Morin <rdm@cfcl.com>
Subject: Re: [MacPerl] Another elementary question

At 12:05 PM -0800 3/12/99, Ronald J. Kimball wrote:
>Replace the unwanted newlines before giving the file to your script.

That gets me wondering.  What if he doesn't want to have to run two
scripts?  What's the easiest way to perform

  cr_filter < infile | analysis_program

under MacPerl?  Winners, if any, by concensus...

- -r
- --
Rich Morin:          rdm@cfcl.com, +1 650-873-7841, http://www.ptf.com/~rdm
Prime Time Freeware: info@ptf.com, +1 408-433-9662, http://www.ptf.com
MacPerl: http://www.ptf.com/macperl,   http://www.ptf.com/ptf/products/MPPE
MkLinux: http://www.mklinux.apple.com, http://www.ptf.com/ptf/products/MKLP

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

------------------------------

Date: Fri, 12 Mar 99 16:20:03 -0800
From: Brian McNett <webmaster@mycoinfo.com>
Subject: Re: [MacPerl] Another elementary question

>The diagnostic is not emitted from the strict pragma, but rather by
>the "-w" switch. The strict pragma concerns itself with symbolic
>references, unqualified package variables, and barewords that might
>actually be subroutines. It doesn't do anything about things that have
>an undefined value.

My bad.  I know what I *meant*! ;-)

- --Brian

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

------------------------------

Date: Fri, 12 Mar 1999 19:21:40 -0500
From: Chris Nandor <pudge@pobox.com>
Subject: Re: [MacPerl] Another elementary question

At 18.46 -0500 1999.03.12, Rich Morin wrote:
>At 12:05 PM -0800 3/12/99, Ronald J. Kimball wrote:
>>Replace the unwanted newlines before giving the file to your script.
>
>That gets me wondering.  What if he doesn't want to have to run two
>scripts?  What's the easiest way to perform
>
>  cr_filter < infile | analysis_program
>
>under MacPerl?  Winners, if any, by concensus...

Depends.  Do you know what is in the file?  If you know you are on a Mac,
and the file is either Mac, DOS, or Unix format, you can do:

    sub get_text {
        my $file = shift;
        local($/, *F);
        open F, "< $file\0" or die $!;
        (my $text = <F>) =~ s/\015?\012/\n/g;
        $text;
    }

If you are not sure what platform you will be on, then you need to do
something else.  It should work, I think, for DOS, Unix, or Mac files, on
DOS, Unix, or Mac platforms.

    sub get_text {
        my($file, $c, $text) = (shift, 0);
        local($/, *F);
        open F, "< $file\0" or die $!;
        $text = <F>;
        until ($/) {
            seek(F, $c++, 0);
            read(F, my $b, 1);
            if ($b eq "\012") {  # is Unix
                $/ = $b;
            } elsif ($b eq "\015") { # is DOS or Mac
                seek(F, $c++, 0);
                read(F, my $b, 2);
                $b =~ /^(\015\012?)/;
                $/ = $1;
            }
        }
        $text =~ s|$/|\n|g unless $/ eq "\n";
        $text;
    }

I did not test any of the above code.  :)

- --
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

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

------------------------------

End of MacPerl-Digest V1 #11
****************************


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