[7927] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1552 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 30 16:07:33 1997

Date: Tue, 30 Dec 97 13:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 30 Dec 1997     Volume: 8 Number: 1552

Today's topics:
     Building perl XSUBs (Cory C. Albrecht)
     Can't find WIN32::MsgBox <mike.battaglia@pricer.com>
     cgi script for binary images <skwong@slip.net>
     Re: chomp ($&) to remove specific \n <joema @nospam.microsoft.com>
     ex-ish or sed-ish regexp manipulation <dfetter@shell4.ba.best.com>
     Re: flock Not Available in MacPerl 5? (Chris Nandor)
     handling interrupts <jrt@llnl.gov>
     handling interrupts <jrt@llnl.gov>
     Help converting perl4 code to perl5 <mfriend@mind.net>
     Help converting perl4 code to perl5: Example 1 <mfriend@mind.net>
     Re: http socket programming <aas@sn.no>
     Re: learning perl <bwb@concentra.com>
     list as a hash value? (Yung-Hsiang Lu)
     Re: MIME::Base64 troubles <aas@sn.no>
     Re: Mysterious FileHandle + fork() behavior; possible P <rootbeer@teleport.com>
     Re: Passing short int arrays between Perl and C (Tye McQueen)
     Re: perl on a mac? (Chris Nandor)
     Perl runs slowly on Win32 platform... (Brian DeRosa)
     PerlScript: Using the Command Object <swood@microsoft.com>
     Range (was: overloading in function) <xah@best.com>
     Removing "last" reference to an Object <mkahn@vbe.com>
     The To-Do List ??? <jdporter@min.net>
     Re: Which language pays most? Smalltalk, not C++ nor Ja <crmartin@connix.com>
     Re: Which language pays most? Smalltalk, not C++ nor Ja <jwaxman@ymail.yu.edu>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 30 Dec 1997 20:22:57 GMT
From: coryalbrecht@hotmail.com (Cory C. Albrecht)
Subject: Building perl XSUBs
Message-Id: <68bl71$18s_002@news.sentex.ca>

Hello all,

OK, I need a few helps (well, perhaps mor ethan a few) and hints here as=20
this is my first try at building XSUBs for perl.

What I have:
        Perl 5.004_02 for Win32
        Watcom C/C++ 11.0 (which has programmes to run to look like MSC)
        Windows95

My problem:
        The makefile which 'perl Makefile.PL' produces is always set    =20
        for the Borland defaults, even if I change the config.mk so that=20
        OS =3D win32 and OSRELEASE =3D microsoft. I can't get the CC, LIB, =
 =20
        etc. defaults in the makefile to change to the Microsoft=20
        defaults.

        Things like tlib, tlink32, bcc32, stuff like that is easy to=20
        change by hand and rather obvious. However, I have not the=20
        slightest idea what the cw32mti.lib library does in Borland's=20
        scheme of things, and you know, I'd really rather not have to go=20
        and edit by hand any XSUB makefile that I produce because that  =20
        would waste too much time.

        So, if somebody could tell me how to do this for the MSC=20
        environment, I'd be eternally grateful.

Thanks,

--
Cory C. Albrecht
GCS d-(+) s+: a- C++ U+ P++ E--- W++ N++ K? w O++ V-- PS+ PE- Y+ PGP(+) t+
    5+(++) X(+) tv(+) b+++ DI(+) D(+) G e>++ h! r++ y?


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

Date: Tue, 30 Dec 1997 12:50:05 -0600
From: "Michael A. Battaglia" <mike.battaglia@pricer.com>
Subject: Can't find WIN32::MsgBox
Message-Id: <34A9425C.B3FB0155@pricer.com>

I am a newbe perl users, so please be kind :)

I am having a problem with one of my perl scrips, so I needed a debug
version of perl.  I am working with NT 4.0.  So I down loaded the
source, including all of the win23 packages.  I compiled and build
them.  However, when I run my program I get a 'undefined subrutine
WIN32::MsgBox call at ....".  I looked at my precompiled copy of
perl.exe and I see calls in it (OK, they look like calls since I only
looked with a text editor).  However, in the copy I compiled I don't see
any of the calls.

Here is what I used to build it:

perl5.004_04
libwin32-0.09

Here is the precompiled version I have

Pw32i306.exe

Is this something that isn't in the newer source?  Should I go back and
get an older copy of the source?  Do I need to compile something else? I
have looked at all the win32 src archives I can find (on CPAN) and I
don't find it anywhere.

Any help would be appreciated.

Mike Battaglia
mike.battaglia@pricer.com





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

Date: Tue, 30 Dec 1997 12:27:29 -0800
From: sam wong <skwong@slip.net>
Subject: cgi script for binary images
Message-Id: <34A95931.40005D9A@slip.net>

I'm running into a problem having a perl cgi script send a adobe pdf
file to the browser, the browser receives the header and launches
acrobat reader, but the acrobat reader complains about no data in
document.  I telneted into the webserver to issue the same request, and
all the webserver returned was the headers.  On the command-line the
script returns the appropriate Content-type of application/pdf with the
binary pdf file following.  After a week of frustration, I coded a C
program to do the same thing, it worked fine after I had to set the
filemode of stdout to Binary.  Examples that I have gotten from books,
do the same thing for other binary files.  Is this a quirk with NT?  Do
I have to set the Stdout stream for this perl script to be Binary
somehow?

Currently running Perl 5.004 on Windows NT with Netscape Enterprise 3.0
Server on NT.

Any help would be appreciated.

-sam-

Code snippet:

   print "Content-type: application/pdf\n\n";

   open (BL, "6341258.pdf");
   binmode(BL);
   while (read(BL, $str, 255) ) {
      print $str;
   }






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

Date: Tue, 30 Dec 1997 11:56:59 -0800
From: "Joe Marler" <joema @nospam.microsoft.com>
Subject: Re: chomp ($&) to remove specific \n
Message-Id: <68bjm6$9m5@news.microsoft.com>

Thanks -- I'd tried $1, but didn't think to put only the match pattern
minus the \n in parens.

================
 Eric Bohlman wrote:

>It's best to avoid using $& if you can; using it greatly slows down *all*
>regex matching in your script.  Fortunately, there's a simple way to do
>what you want:
>
> s/(matchpattern.*)\n/$1/i;
>
>if $_ contains only one newline.  If it contains more than one newline,
>use the g and s modifiers as well and put a ? after the *.
>
>This makes uses of the $n facility for remembering matched portions of a
>string; you can find out more about it by reading perlre.
>





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

Date: 30 Dec 1997 20:14:32 GMT
From: David Fetter <dfetter@shell4.ba.best.com>
Subject: ex-ish or sed-ish regexp manipulation
Message-Id: <68bkn8$gka$1@nntp1.ba.best.com>

Kind perl gurus,

I'd like edit files in place and do things to a range of lines
delimited by regular expressions, for example:

[pseudo-code]

frobnicate (/BeginFrob/+1,/EndFrob/-1) # by line

How do I get perl to grok between-ness?

Thanks in advance for any tips, pointers or specific RTFM's.
-- 
            David Fetter         888 O'Farrell Street Apt E1205
   shackle@ren.glaci.com          San Francisco, CA 94109-7089 USA
  http://www.best.com/~dfetter     +1 415 567 2690 (voice)
print unpack ("u*",q+92G5S="!!;F]T:&5R(%!E<FP@2&%C:V5R"@``+)

Duct tape is like the force: it has a light side, and a dark side, and
it binds the universe together.
                                       Carl Zwanzig


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

Date: Tue, 30 Dec 1997 14:04:27 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: flock Not Available in MacPerl 5?
Message-Id: <pudge-3012971404280001@ppp-48.ts-1.kin.idt.net>

In article <NO_SPAM_acs-2712971842220001@acs.bitstream.net>,
NO_SPAM_schneider@pobox.com wrote:

# VikR@aol.com wrote:
# > A client of mine is running MacPerl 5.1.5r4 on a Mac, and reports that flock
# > is unavailable. He's getting a 
# > "# The flock() function is unimplemented." error. I can see in the MacPerl
# > docs that flock seems to be present in MacPerl. What could explain this?
# 
# I can't answer your primary question, but I do have a small morsel of
# info: most of the docs that comes with MacPerl are identical to the UNIX
# Perl docs.  So just because you can look something up using Command-H,
# doesn't mean you can use it.  :^(

Correct.  There is no flock() in MacPerl; however, there is an
FSpSetFLock/FSpRstFLock available via the Mac::Files module (using the Mac
OS toolbox calls of the same name).  You can see my draft chapter on the
Toolbox Modules for the upcoming MacPerl book at the URL below for more
information.

--
Chris Nandor               pudge@pobox.com           http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])
#==                    MacPerl: Power and Ease                     ==#
#==    Publishing Date: Early 1998. http://www.ptf.com/macperl/    ==#


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

Date: Tue, 30 Dec 1997 12:45:50 -0800
From: John Tannahill <jrt@llnl.gov>
Subject: handling interrupts
Message-Id: <34A95D7C.D938603C@llnl.gov>

In the cshell I used to handle interrupts as follows:

onintr catch

catch:
  onintr -
  do something
  exit 1

How can I do this in perl?

Thanks,
John Tannahill
jrt@llnl.gov



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

Date: Tue, 30 Dec 1997 12:46:18 -0800
From: John Tannahill <jrt@llnl.gov>
Subject: handling interrupts
Message-Id: <34A95D99.BD653020@llnl.gov>

In the cshell I used to handle interrupts as follows:

onintr catch

catch:
  onintr -
  do something
  exit 1

How can I do this in perl?

Thanks,
John Tannahill
jrt@llnl.gov



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

Date: 30 Dec 1997 19:12:19 GMT
From: "Christopher James" <mfriend@mind.net>
Subject: Help converting perl4 code to perl5
Message-Id: <01bd1553$e27306e0$dc3010ac@172.16.48.201.172.16.48.201>

I was just wondering if anyone knew of a site or a FAQ that might help me
in
converting subroutines and .conf files from perl4 to perl5 modules so that
I can start
loading wasteful routines on demand.

This is the shopping system code in action to any interested:
http://www.musiciansfriend.com/cgi-bin/shop.dll

It is about 8500 lines in all, counting all of the 'require...d' files.
It is running with perl5.004 now, but the subroutines need to be converted.



Thanks so much.

Christopher James
mailto:webmaster@musiciansfriend.com


ps: please Cc: a copy of your message posted here to 
mailto:webmaster@musiciansfriend.com so that I will
know that you have responded.



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

Date: 30 Dec 1997 19:25:59 GMT
From: "Christopher James" <mfriend@mind.net>
Subject: Help converting perl4 code to perl5: Example 1
Message-Id: <01bd1555$cb7e56e0$dc3010ac@172.16.48.201.172.16.48.201>


I do one of these:
require "/usr/local/www/cgi-bin/module/fonts.list";

This file is just filled with things like this....

#!/usr/local/bin/perl
$font1 = qq|<font size=1 face="arial,helvetica">|;
$font2 = qq|<font size=2 face="arial,helvetica">|;
$font3 = qq|<font size=3 face="arial,helvetica">|;
$font4 = qq|<font size=4 face="arial,helvetica">|;
$font5 = qq|<font size=5 face="arial,helvetica">|;
$font6 = qq|<font size=6 face="arial,helvetica">|; 
$font7 = qq|<font size=7 face="arial,helvetica">|;
$font8 = qq|<font size=8 face="arial,helvetica">|;
$font9 = qq|<font size=9 face="arial,helvetica">|;
$font10 = qq|<font size=10 face="arial,helvetica">|;

Then I use the code like this:
print qq|$font3 Hello, is this the real world?\n|;

This really is just a time and space saver for writing code.
This file is used by about 20 programs throught the server...

1.) How would one convert this so that it would not 
smash some other name space

2.) How would I make all of these variables available to all
of the modules that 'use'

3.) Is there an easier way of doing this that I need to look at.



Questions like this, is what I am baffled with.

Thanks,
Christopher James	
mailto: webmaster@musiciansfriend.com







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

Date: 30 Dec 1997 20:38:29 +0100
From: Gisle Aas <aas@sn.no>
Subject: Re: http socket programming
Message-Id: <m3wwgm4o5m.fsf@furu.g.aas.no>

Jim Bowlin <bowlin@sirius.com> writes:

> Actually HTTP/1.1 allows Connection: Keep-Alive to use one connection
> for multiple requests.

Not really.  It allows 'Connection: close' if you don't want to send
multiple requests on a connection.

>  The latest browsers (and latest Apache) now
> support this protocol.

and hopefully libwww-perl too soon.

-- 
Gisle Aas


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

Date: Tue, 30 Dec 1997 14:50:57 -0500
From: "Brent Benson" <bwb@concentra.com>
Subject: Re: learning perl
Message-Id: <68bjfe$9j5$1@icadnewshost.concentra.com>

noe1joe@geocities.com wrote:
>
>hi im interested in getting started on learning perl/cgi scripts can
>any1 point me to some good sites on the net to help me out or anything
>else i may be interested in?


Buying a book about Perl is one way to start.  Here is a sight that has
Perl book reviews and recommendations based on programmer experience
level.

  http://www.flathill.com/languages/perl/






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

Date: 30 Dec 1997 20:24:31 GMT
From: luyung@leland.Stanford.EDU (Yung-Hsiang Lu)
Subject: list as a hash value?
Message-Id: <68bl9v$qhv$1@nntp.Stanford.EDU>

Hi,

Is there a way to store a list as a hash value?  It seems a very
useful thing.  Here is an example to show the power of this feature:

$Sports{John} = ("swimming", "tennis", "football");
$Sports{James} = ("tennis", "jogging");
 ......

It seems much easier to find a partner with this feature.

Guess the result of this code?

$Sports{John} = ("swimming", "tennis", "football");
$Sports{James} = ("tennis", "jogging");
print "$Sports{John}\n";
print "$Sports{James}\n";

answer: 
football
jogging

We are not able to find out that John and James can play tennis
together. :-(

Thank you very much.
-- 
Yung-Hsiang Lu                luyung@computer.org
Electrical Engineering Dept.  Stanford University


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

Date: 30 Dec 1997 21:05:49 +0100
From: Gisle Aas <aas@sn.no>
Subject: Re: MIME::Base64 troubles
Message-Id: <m3u3bq4mw2.fsf@furu.g.aas.no>

brian moseley <brian@criticalpath.net> writes:

> i'm writing a web-based mail client. for some reason, my base64-encoded 
> 
> attachments aren't being decoded properly by other clients, although
> they are handled correctly by my client.
> 
> as an example, i attached the same jpg to a composition in eudora and a 
> 
> composition in my client and sent both messages to a shell account so i
> could save each message as a folder with pine. interesting results.
> 
> these are the headers for and the first few lines of the attachment, for
> each message.
> 
> from eudora:
> 
> --=====================_882595579==_
> Content-Type: application/octet-stream; name="Bridesmd.jpg"
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename="Bridesmd.jpg"
> 
> /9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
> HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy
> MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAFlAMgDASIA
> AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA
> 
> and from my web client:
> 
> ------------=_882566924-17652-3
> Content-Type: image/jpeg; name="Bridesmd.jpg"
> Content-Disposition: attachment; filename="Bridesmd.jpg"
> Content-Transfer-Encoding: base64
> 
> LzlqLzRBQVFTa1pKUmdBQkFRRUJMQUVzQUFELzJ3QkRBQWdHQmdjR0JRZ0hC
> d2NKQ1FnS0RCUU5EQXNMCkRCa1NFdzhVSFJvZkhoMGFIQndnSkM0bklDSXNJ
> eHdjS0RjcExEQXhORFEwSHljNVBUZ3lQQzR6TkRMLwoyd0JEQVFrSkNRd0xE
> QmdORFJneUlSd2hNakl5TWpJeU1qSXlNakl5TWpJeU1qSXlNakl5TWpJeU1q
> 
> notice that the encoded lines generated by MIME::Base64 (60 chars) are
> much shorter than those generated by eudora (76 chars). (incidentally,
> also notice that eudora sent a jpg as application/octet-stream. ugh.)
> 
> my assumption is that the line length is the problem. this seems to be 
> 
> hard-coded into Base64.pm so i don't want to muck with it if i don't
> have to. i'm sure others have been able to deliver correctly-encoded
> attachments .. do you have any insight? if not, i guess i'll be fwd'ing
> to comp.lang.misc.perl.

I think you will have to show us the code the generates the attachment
above.  The MIME::Base64 module should also generate lines which are
76 characters long, but I don't think your short lines is the problem.
The encoded stuff itself should be equal in the two examples above.

-- 
Gisle Aas


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

Date: Tue, 30 Dec 1997 12:38:06 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Allen Chen <achen@nssdc.gsfc.nasa.gov>
Subject: Re: Mysterious FileHandle + fork() behavior; possible Perl bug?
Message-Id: <Pine.GSO.3.96.971230123536.7945C-100000@user2.teleport.com>

On Mon, 29 Dec 1997, Allen Chen wrote:

> if ((defined($pid = fork)) && ($pid==0)) {    #child

That's a start, but I'd try this.

    {
	if (not defined($pid = fork)) {
	    # Assume harmless fork failure
	    sleep 1;
	    redo;
	}
    }

After that block, the fork must have succeeded, so you need only check
whether it's true or false. Does that fix the problem? 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: 30 Dec 1997 12:57:27 -0600
From: tyde@medtrodnet.cdom (Tye McQueen)
Subject: Re: Passing short int arrays between Perl and C
Message-Id: <68bg6n$f76@fiinix.metronet.com>

Rob Maniatis <robm@transmeta.com> writes:
[...]
) The C function expects three arguments--two pointers to arrays
) (C-arrays) of short ints (and it assumes that the calling function has
) taken care of the space allocations) and a length argument (an int). 
) [...]  The problem is that when I get back to perl if the returned
) array happened to contain a 0 within the array the output string in perl
) ends at the embedded.
[...]
) @data = 1, 2, 3;

@data= ( 1, 2, 3 );

) $input = pack("s$length", @data);
) $output = $input;     #allocate space for output.
) &mypackage::c-library-call($input, $length, $output);
[...]
) XS(XS_c-library-call)
) {
)     dXSARGS;
)     if (items != 3)
)         croak("Usage: mypackage::c-library-call(arg0, arg1, arg2)");
)     {
)         short * arg0 = (short *)SvPV(ST(0),na);
)         int     arg1 = (int)SvIV(ST(1));
)         short * arg2 = (short *)SvPV(ST(2),na);
)         int     RETVAL;
) 
)         RETVAL = c-library-call(arg0, arg1, arg2);
)         sv_setpv((SV*)ST(2), arg2);

The above line is the problem.  sv_setpv looks for a trailing '\0'.
The easiest fix based on the code you have here is to not list
"arg2" as an "OUTPUT" parameter:

) XS CODE:
) int
) c-library-call(arg0, arg1, arg2)
)         short * arg0
)         int     arg1
)         short * arg2
)         OUTPUT:
)         arg2

That is, drop the last two lines above.

But that requires that the Perl code that calls your XS
code to be very careful.  I'd advocate something like
the following:

XS code expects input which is result of pack("s*",@array)
and uses Perl's notion of the string's length to either 1)
determine the number of elements in the array [that is,
don't bother having the array length passed in as a separate
argument] or, more flexible, 2) verify that the array length
passed in is not too large for the input string.  Then XS code
makes sure the output parameter has sufficient buffer space
for matching output array and calls C code:

XS CODE:
int
c_library_call( asInput, iCount, asOutput )
        short * asInput
        int     iCount
        SV *	svOutput
    CODE:
	if(  iCount*sizeof(short) < SvCUR(ST(0))  ) {
	    errno= EINVAL;	/* SETERRNO( EINVAL, -1 ); with my patch */
	    RETVAL= -1;		/* Or whatever the error return is */
	} else {
	  short *asOutput;
	    /* [The following steps taken from Perl's sysread()] */
	    /* If svOutput is undef, SvPV_force() isn't enough... */
	    if(  ! SvOK(svOutput)  )   sv_setpn( svOutput, "", 0 );
	    /* Force svOutput to have a string buffer allocated to it: */
	    (void) SvPV_force( svOutput, na );
	    /* Ensure that the string buffer is large enough: */
	    asOutput= (short *) SvGROW( svOutput, iCount*sizeof(short)+1 );
	    /* [the above "+1" is for the "safety" trailing '\0'] */
	    RETVAL= c_library_call( asInput, iCount, asOutput );
	    /* In case user accidentally passes string to some C function: */
	    ((char *)asOutput)[iCount*sizeof(short)]= '\0';
	    /* Let Perl know the length of the output buffer: */
	    SvCUR_set( svOutput, iCount*sizeof(short) );
	}
    OUTPUT:
        RETVAL

Unfortunately, I haven't found a way to get the "typemap" stuff
to handle these types of length-dependant initialization issues. 
Note that the automatic connection between "ST(0)" and "asInput"
is lost in the above code and you have to be very careful to keep
the mapping correct if you change the arguments to the function.
--
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)
       Remove d's from address to reply (sorry for the inconvenience).


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

Date: Tue, 30 Dec 1997 14:01:48 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: perl on a mac?
Message-Id: <pudge-3012971401480001@ppp-48.ts-1.kin.idt.net>

In article <goatholl-2612971503570001@d69.pm9.sonic.net>,
goatholl@sonic.net (Chris) wrote:

# How do I get ahold of a program to run and compile perl on a macintosh?
# (performa 630cd)
# I want to learn how to use perl to write simple cgi scripts to use with
# web pages, where do I start???
# thanks, and happy holidays  - Karen

In addition to the others' notes, you can check out my draft chapter on
CGI Programming with MacPerl for my upcoming book with Vicki Brown (URL
below).

It does not teach CGI programming, only gives information on how to do it
with MacPerl.

--
Chris Nandor               pudge@pobox.com           http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])
#==                    MacPerl: Power and Ease                     ==#
#==    Publishing Date: Early 1998. http://www.ptf.com/macperl/    ==#


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

Date: 30 Dec 1997 17:46:35 GMT
From: derosbr@cig.mot.com (Brian DeRosa)
Subject: Perl runs slowly on Win32 platform...
Message-Id: <68bc1r$put$1@trotsky.cig.mot.com>

Has anyone else had a similar problem?
I have a P166 and am running Win95.
Has anyone found a way to optimize CPU usage for Perl under Win95?
Thanks.

Brian
---
Brian De Rosa                        OFFICE PHONE: +1-847-632-3803
Software Engineer (Motorola)         OFFICE FAX: +1-847-435-9636
"We accept arguments as a drunken man leans against a lamppost...
 for support, not illumination."


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

Date: Tue, 30 Dec 1997 11:57:33 -0800
From: "Stephen Wood" <swood@microsoft.com>
Subject: PerlScript: Using the Command Object
Message-Id: <68bjoi$924@news.microsoft.com>

Can anyone point me to an example that uses the Command object in
ActiveWare's PerlScript?

They have ADO samples, but all of them use the Recordset and Connection
objects.




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

Date: Tue, 30 Dec 1997 11:23:35 -0800
From: "Xah" <xah@best.com>
Subject: Range (was: overloading in function)
Message-Id: <68bheu$fk3$1@nntp1.ba.best.com>

Thanks for all the help on writing a Range function. Here are full
implementation of Range in Mathematica, in Perl, and in Scheme.

Btw, they are not representative of best coding in each language, and I have
not taken the pains to varify that they all behave exactly alike under all
possible inputs. Nor are they coded to show as much analogy as possible.
(but they all use recursion) They are here purely for fun.

------------------------------------------------
(*Mathematica code*)

range::"usage"= "range[a,b,dx] returns a list from a to b with increment dx.
dx can be negative if a > b. range[n] is equivalent to range[1,n,1].
range[a,b] is equivalent to range[a,b,1].";

range[a_/;N@a<=0]:={};
range[a_]:=range[1,a,1];
range[a_,b_]:=range[a,b,1];

range[a_,b_,dx_]/;(Not@MatchQ[dx,0|0.]):=rangeInternal[a,b,dx];

rangeInternal[a_,b_,_]/;(Abs@N@(b-a)==0||a===b):={a};
rangeInternal[a_,b_,dx_]/;(Sign@N@(b-a)=!=Sign@N@dx):={};
rangeInternal[a_,b_,dx_]/;((N@a<N@b)&&N@(b<a+dx))||((N@a>N@b)&&N@(b>a+dx)):=
{
    a};
rangeInternal[a_,b_,dx_]/;(Sign@N@(b-a)===Sign@N@dx):=
  Prepend[range[a+dx,b,dx],a];

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

# perl code

sub range {
return &rangeInternal(1,$_[0],1) if scalar @_ == 1;
return &rangeInternal($_[0],$_[1],1) if scalar @_ == 2;
return &rangeInternal($_[0],$_[1],$_[2]) if scalar @_ == 3;
};

sub rangeInternal {
my ($a1, $b1, $dx) = @_;

if ($dx == 0) {print "increment cannot be zero."; return ()} elsif
($a1 == $b1) {return $a1;} elsif
( ((($b1 - $a1) > 0) && ($dx < 0)) || ((($b1 - $a1) < 0) && ($dx > 0)) ) {
print "bad argument order."; return ();};

if ((($a1 < $b1) && ($b1 < ($a1 + $dx))) ||
	(($a1 > $b1) && ($b1 > ($a1 + $dx))))
{$a1;} else
{ ($a1, &rangeInternal ($a1 + $dx, $b1, $dx) );};
};

------------------------------------------------
;and here are two versions of Range in Scheme

; by John David Stone <stone@math.grin.edu>
; Date: 27 Dec 1997 11:32:38 -0600
;stone@math.grin.edu - http://www.math.grin.edu/~stone/

(define range
  (lambda args
    (let ((arg-count (length args)))
      (if (not (<= 1 arg-count 3))
          (error 'range "wrong number of arguments"))
      (let ((start (if (= arg-count 1) 1 (car args)))
            (finish (if (= arg-count 1) (car args) (cadr args)))
            (increment (if (= arg-count 3) (caddr args) 1)))
        (let ((beyond (cond ((positive? increment) >)
                            ((negative? increment) <)
                            (else (error 'range "zero increment")))))
          (let loop ((result '())
                     (counter start))
            (if (beyond counter finish)
                (reverse result)
                (loop (cons counter result) (+ counter increment)))))))))

;From: Dmitrii Pasechnik <dima@duti515a.twi.tudelft.nl>
;Date: 27 Dec 1997 17:31:50 +0100

(define (range a . x)
  (if (null? x) (make-range 1 a 1)
      (let ((b (car x)) (dx (cdr x)))
        (if (null? dx) (make-range a b 1)
            (make-range a b (car dx))))))

(define (make-range a b dx)
  (if (= 0 dx) (breakpoint "0 delta in make-range")
      (if (= (sign (- b a)) (sign dx)) 
          (let ((end-range 
                 (if (> dx 0) (lambda (x) (> x b))
                     (lambda (x) (< x b)))))
            (letrec ((really-make-range
                      (lambda (x res)
                        (if (end-range x) (reverse res)
                            (really-make-range (+ x dx) (cons x res))))))
              (really-make-range a '() )))
          '() )))
(define (sign x) (if (>= x 0) 1 -1))

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

 Xah, xah@best.com
 http://www.best.com/~xah/Wallpaper_dir/c0_WallPaper.html
 "(intelligence (lisp (pigs (perl (unix baggage (C (brain tumor)))))))"


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

Date: Tue, 30 Dec 1997 14:08:33 -0600
From: Mark Kahn <mkahn@vbe.com>
Subject: Removing "last" reference to an Object
Message-Id: <34A954C1.35E44E24@vbe.com>

I am using OO constructs in a Perl script, and have the following question:

The process uses a global hash to hold the "current" record that is read in
from a flat file.  Due to business rules, I have to save off this record (I
copy the elements to another hash, making it the "previous" record) and
read the next record in from the flat file.  At a point I can then flush
the "previous" record to an output file.

The problem is that one of the "current" record's elements is the ref that
points to a blessed object that contains data related to that record.  If I
copy all of "current"'s elements to "previous", I'd have an element in each
that points to the same object.  I don't want to overwrite data in that
object, so insead of copying that element (the ref) I create a new object
(and ref, of course) for the new "current" record.  After I finish
processing the "previous" record I'd like to destroy the object that it's
ref points to (I assume that it persists otherwise, and this will slowly
eat memory).

How do I release memory allocated to the object that the "previous"
record's
ref points to?  Do I just re-initialize the hash (%Prev = ();)?

Thanks,

Mark


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

Date: Tue, 30 Dec 1997 15:03:09 -0500
From: John Porter <jdporter@min.net>
Subject: The To-Do List ???
Message-Id: <34A9537D.4E9E@min.net>

I'm sorry but I just can't seem to find the Perl "To-Do List" on
perl.com or my local CPAN site.

Does it still exist!?  What is its canonical location?

'Thanks' x 1_000_000;
John Porter
jporter@logicon.com


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

Date: Tue, 30 Dec 1997 13:15:36 -0500
From: Charles R Martin <crmartin@connix.com>
Subject: Re: Which language pays most? Smalltalk, not C++ nor Java.
Message-Id: <34A93A48.EF116CF9@connix.com>

Patricia Shanahan wrote:
> 
> Jeffrey Templon wrote:
> >
> > "Alicia Carla Longstreet" <carla@ici.net> writes:
> >
> > > No the language is *not* defined by any single compiler, neither is it
> > > defined by any piece of paper.  A language is defined by usage.  A
> > > combination of compilers and the standard.
> >
> > I'd guess this opinion is generated by doing the majority of one's
> > work on the same platform, possibly even using the same development
> > tools, whenever you use C.
> ...
> 
> I sometimes think that every programmer should be required to port a
> large program to its second platform before doing any new code.
> Preferably, the first platform should differ in word size, endianness,
> and general software heritage (e.g. UNIX vs. MSWindows vs. VMS) from
> the new target. There is nothing quite like this experience for an
> enhanced appreciation the value of standards.

Years ago, I helped teach an undergrad software engineering
this-is-what-it's-
like-in-the-real-world-kiddies course at Duke.  We included an
assignment in which the students had to perform maintenance on an
existing PL/I program in order to add new functionality.  (It was a
reasonably well-structured program on which I had [hee hee] removed
almost all comments and somewhat obfuscated the variable names -- a lot
like trying to maintain a lot of C code.)  years later, students I run
in to STILL tell me that it was the only class they had that prepared
them for real life.  (They're wrong -- the data structures class and
other such just aren't as obvious in their effects, but that's another
posting.)

Eventually, the faculty member who owned the course didn't get tenure,
and the course was taken over by a guy who felt that "software
engineering" was best taught by writing the fastest program to find
discontinuities in the REAL type.


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

Date: Tue, 30 Dec 1997 14:46:30 -0500
From: Joshua Waxman <jwaxman@ymail.yu.edu>
Subject: Re: Which language pays most? Smalltalk, not C++ nor Java.
Message-Id: <Pine.A41.3.95.971230143114.19568A-100000@acis.mc.yu.edu>

On Mon, 29 Dec 1997, Guillermo Schwarz wrote:

> very poorlanguage. You can't know how many bits does an int have. Or if long
> is actually bigger
> than int.
You can't? How about sizeof(int) and if(sizeof(int) < sizeof(long))

> You can't ask an structure how many fields does it have. 

True. But structures in C++ tend to have a constant number of fields, no?

> You can't tell an
> structure to write itself into a file.

Yes you can. You just have to include in the definition of the struction a
function the does output. Most overload the << with the ostream operator.

> You can't code an algorithm that works
> with any
> kind of numbers: int, double, big int, etc.

Ever hear of template functions?

> In C++ there is no way to handle overflow of integers.

Check after each addition to see if you reversed signs, and act
accordingly.

> Ask in runtime how many classes do you have in your image.

I'm interested what this means. What is an image that contains classes?

> Or try to figure out which classes descend from which.

I think it is possible to do this. RTTI. Also, can't you do a dynamic_cast
and check if the pointer is null, if not then the class descends?

> Try to make a single general program.

What does this mean?

> Try to create a Set of objects in C++.

#include <set>
using namespace std;
set <int> h; set <set<char> > k;

> Try to create a Bag of objects in C++.

ditto, just replace with multiset.

> Try to create a SortedCollection of objects in C++.

extend it from one of the base containers.

> Convert one collection into another. (SortedCollection as Bag or whatever).

The generic copy algorithm.

> Put a Set inside another Set.

set <set <char > > k;
or do you mean copy the contents? There is a copy.

> Try to create a Dictionary of pairs of objects in C++ using hashing to index
> the keys.

Your speaking about the map type. Maps aren't actually implemented using
hashes, I don't think, but in Stroustrup's book he shows how to quickly do
this.

> Then put a Dictionary and a Set inside a Dictionary with the Dictionary as
> the key.

Can do.

> If you can do a single thing of what I wrote here you are a good C++
> programmer.

Or a programmer who knows the Standard Template Library.

> All this can be done in 10 minutes in Smalltalk (if lazy).
> 
By all, do you mean that in 10 minutes you would have completed EVERY
item, of that each item in turn could be completed in 10 minutes?
In C++, most of the stuff you listed could be done in less than a minute
each. The hash is a bit more complicated, and might take 1/2 an hour. For
a more experienced programmer, possibly shorter.

> I'm sorry if I hurt your feelings, but for the last 3 months I've been
> Smalltalking more than
> keeping up with the C crap.

C++, you mean. And apperently you haven't. :)

 (C++ being the cream of the crap and Java being coffe you  drink with
cream).
> 
> I mean no offense to other languages. Fortran had its time. C had it. C++ had
> it. Java is having it.
> Smalltalk deserves a little respect as the king of OOL. (Maybe CLOS guys will
> not agree with
> me), but trying to say that C++ object model is better than Smalltalk object
> model is saying
> GW BASIC is more structured than Pascal. And claiming you know C++ and
> Smalltalk more
> than me is something to prove, sir!
> 
I don't know Smalltalk at all. C++ did I prove?

Josh Waxman



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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 1552
**************************************

home help back first fref pref prev next nref lref last post