[10520] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4112 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 30 14:07:18 1998

Date: Fri, 30 Oct 98 11:00:23 -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           Fri, 30 Oct 1998     Volume: 8 Number: 4112

Today's topics:
        close() and the file pointer <d.m.proffitt@mds.qmw.ac.uk>
    Re: DBD:ODBC Question (remote access?) <ahongun@ecsysinc.com>
    Re: Dumping all input to a CGI <rootbeer@teleport.com>
    Re: Dumping all input to a CGI dave@mag-sol.com
    Re: Easy Question: Rounding Numbers <webmaster@topproducer.com>
    Re: Easy Question: Rounding Numbers <chris@starkmedia.com>
    Re: Easy Question: Rounding Numbers (Larry Rosler)
    Re: easy way to learn perl? <jeff@webdesigns1.com>
        FTP from Win32 <tmcgee@bondmarkets.com>
    Re: FTP from Win32 (Randy Kobes)
        How to run Perl/CGI under NT? <topper@virginia.edu>
    Re: List of files to an array... (Sean McAfee)
    Re: List of files to an array... <michael_mongeau@stratus.com>
    Re: named arguments <jorendorff@ixl.com>
    Re: named arguments <jorendorff@ixl.com>
    Re: new to perl (maybe) (M.)
    Re: Not to start a language war but.. (Alan Barclay)
    Re: Not to start a language war but.. (William Tanksley)
    Re: Not to start a language war but.. (Dave Kirby)
    Re: Not to start a language war but.. (Dave Kirby)
    Re: Not to start a language war but.. <jorendorff@ixl.com>
    Re: Perl & Y2K - booby trap code (Joergen W. Lang)
        Perl DCOM Question -- setting property (Charles Aulds)
        perl news per Email? <dmitri@compuserve.com>
        Problem with installing modules sybperl & Data-Dumper nguyen.van@imvi.bls.com
    Re: Python fun <jorendorff@ixl.com>
        Regex Problem <george@tapestry.net>
        regexp question - re: {n} <jedev@visarc.com>
        Short term, remote PERL project techtest@knowitallinc.com
    Re: Size of JPEG and GIF (John Beppu)
    Re: Style Guides <tchrist@mox.perl.com>
    Re: Very Large DBM file: Finding Number of keys (Mark-Jason Dominus)
    Re: Very Large DBM file: Finding Number of keys (Mark-Jason Dominus)
    Re: Very Large DBM file: Finding Number of keys (Bob Stewart)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Fri, 30 Oct 1998 17:22:01 -0000
From: "David Proffitt" <d.m.proffitt@mds.qmw.ac.uk>
Subject: close() and the file pointer
Message-Id: <71csvu$loi$1@beta.qmw.ac.uk>

Hello All

Has anyone come across any circumstances where an explicit close on a file
handle doesn't reset the file pointer to the first line?

I have the following (simplified) subroutine:

sub getcase {
    open(DB,$dbfile) or die "couldn\'t open $dbfile : $!";
    while (<DB>) {
          # assign various variables from file data
  }
close(DB);
}

this works fine the first time it is called but any subsequent calls exit
immediately - i did get it to print out the value of $. and it is reading
through the correct number of lines on the first pass then none at all on
the second so i am assuming that the problem is related to the pointer
sticking at eof

any ideas appreciated?

David







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

Date: Fri, 30 Oct 1998 08:07:44 -0800
From: "A. H. Ongun" <ahongun@ecsysinc.com>
Subject: Re: DBD:ODBC Question (remote access?)
Message-Id: <71cob8$gbt$1@news-2.news.gte.net>

The DSN (data source name) is what you call your ODBC connection.  The
remote access is done via the ODBC control panel when you select the driver.
(e.g. for SQL server it will ask you for the server - any one on the network
that can be seen.).

Once you have the ODBC source set-up, the rest should work as advertised.

Hope this helps.

Andy.

NightWolf/Michael Starling wrote in message
<71ahqi$30l$1@news0-alterdial.uu.net>...
>Hi, all...
>I was hoping someone might be able to help with this question.  I've been
>experimenting with database access using DBI and DBD:ODBC, and it's working
>on my local machine here.  Is it possible to access a database on another
>machine/host, however?
>
>The ODBC "connect" function's $data_source string seems to only accept one
>format (at least, I can't find anything else...) - "DBI:ODBC:<dsn-name>",
>where <dsn-name> is the DSN I've set up from the ODBC control panel.  Is
>there a way to say something like:
>
>$dbh->connect("DBI:ODBC:host=foo.bar.com;port=x;dsn=<dsn-name>",$user,$pass
)
>; ?
>
>I'd like to have some database access from another machine.  Any help would
>be appreciated - thanks!
>Mike.
>
>
>
>




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

Date: Fri, 30 Oct 1998 16:35:19 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Dumping all input to a CGI
Message-Id: <Pine.GSO.4.02A.9810300827400.3421-100000@user2.teleport.com>

On Fri, 30 Oct 1998, Morten wrote:

> I can understand that use of CGI.pm is encouraged. Well, the server I
> need to put my scripts on has some early version of Perl 5 that
> doesn't seem to support this, instead I use require("cgi-lib.pl");

If your ISP still is using a version of Perl that's older than the Spice
Girls, consider upgrading to a better ISP.

> When such libraries/modules are used, is there a way to still check
> all the data that is sent to the script? Like when you use
> read(STDIN,$buffer,... you can write the buffer to a file "as is". I
> need to look at all the input to the script, something is rotten
> somewhere and I'm lost.

If your library or module isn't handling the input data properly, you
shouldn't use it. Fix it or replace it with something that works. Good
luck!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 30 Oct 1998 17:25:03 GMT
From: dave@mag-sol.com
Subject: Re: Dumping all input to a CGI
Message-Id: <71cspf$3as$1@nnrp1.dejanews.com>

In article <Pine.A41.3.95.981030143659.20506B-100000@aix5.kbar.dtu.dk>,
  Morten <c960901@aix5.kbar.dtu.dk> wrote:
>
> Hi
>
> I can understand that use of CGI.pm is encouraged. Well, the server
> I need to put my scripts on has some early version of Perl 5 that
> doesn't seem to support this, instead I use require("cgi-lib.pl");

If you can puts scripts on the server, then you can put a copy of CGI.pm on
the server. Just put it in the same directory as your scripts. Perl has '.'
int @INC by default.

> When such libraries/modules are used, is there a way to still
> check all the data that is sent to the script? Like when you
> use read(STDIN,$buffer,... you can write the buffer to a file
> "as is". I need to look at all the input to the script, something is
> rotten somewhere and I'm lost.

CGI.pm has a dump function which prints a formatted list of all of the
parameters.

hth,

Dave...

--
dave@mag-sol.com
London Perl M[ou]ngers: <http://london.pm.org/>
[Note Changed URL]

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 30 Oct 1998 09:27:46 -0800
From: "Alistair Calder" <webmaster@topproducer.com>
Subject: Re: Easy Question: Rounding Numbers
Message-Id: <71csue$hnu$1@supernews.com>

Alright, works fine now.  Thanks to all those who helped.

Alistair Calder.


Alistair Calder wrote in message <71b0bv$lu6$2@supernews.com>...
>I have looked through the Camel book, but I could not find an answer to
this
>question:
>
>I have a variable that is the result of a division, and I want to round it
>to 1 or 2 decimal places.
>
>The only thing I have at my disposal is INT(), but it just truncates, it
>doesn't round up or down.
>
>How do I turn this number:
>
>12.591237489
>
>Into this one:
>
>12.6
>
>
>
>Thanks,
>Alistair Calder
>
>




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

Date: Fri, 30 Oct 1998 12:21:24 -0600
From: <chris@starkmedia.com>
Subject: Re: Easy Question: Rounding Numbers
Message-Id: <Bon_1.38$0t.33053@homer.alpha.net>

$a = 123.4567;
$b = int(($a*100)+.5)/100;
#$b now = 123.46;

print $b;



Change the 100 the be What you need.
10 .1
100 .11
1000 .111
10000 .1111

May not be as nice as sprintf bit i think it is a little easyier to get

>How do I turn this number:
>
>12.591237489
>
>Into this one:
>
>12.6






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

Date: Fri, 30 Oct 1998 10:56:21 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Easy Question: Rounding Numbers
Message-Id: <MPG.10a3abac5152773e989851@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <Bon_1.38$0t.33053@homer.alpha.net> on Fri, 30 Oct 1998 
12:21:24 -0600, chris@starkmedia.com <chris@starkmedia.com> says...
> $a = 123.4567;
> $b = int(($a*100)+.5)/100;
> #$b now = 123.46;
> 
> print $b;
 ...
> May not be as nice as sprintf bit i think it is a little easyier to get

And works incorrectly for negative numbers.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 30 Oct 1998 10:28:11 -0600
From: "Jeff Oien" <jeff@webdesigns1.com>
Subject: Re: easy way to learn perl?
Message-Id: <71cp7i$6q3$1@oak.prod.itd.earthlink.net>

I have a Web site called Perl Primer which may be of help:

http://www.webdesigns1.com/perl/
--
Jeff Oien, WebDesigns
http://www.webdesigns1.com/
jeff@webdesigns1.com

Bibliotek wrote in message <3638c49c.0@d2o204.telia.com>...
>is it any web sites wher newbies can learn peral eas`?






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

Date: Fri, 30 Oct 1998 12:36:32 -0500
From: Tom McGee <tmcgee@bondmarkets.com>
Subject: FTP from Win32
Message-Id: <3639F920.27FA@bondmarkets.com>

I'm pulling out the little hair I have left trying to automate ftp-ing
files to my external server, by passing commands to the shell. 

It's my understanding (and experience) that Net::FTP doesn't work on
Win32; has anyone been able to come up something that does?

I've tried filehandles, pipes, and backticks. They've all compiled OK,
but don't completely pass commands in to the point where I can actually
log in.

Grrrr. I hate Windows!


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

Date: 30 Oct 1998 17:46:19 GMT
From: randy@theory.uwinnipeg.ca (Randy Kobes)
Subject: Re: FTP from Win32
Message-Id: <slrn73jvbu.fbr.randy@theory.uwinnipeg.ca>

On Fri, 30 Oct 1998 12:36:32 -0500, Tom McGee <tmcgee@bondmarkets.com> wrote:
>I'm pulling out the little hair I have left trying to automate ftp-ing
>files to my external server, by passing commands to the shell. 
>
>It's my understanding (and experience) that Net::FTP doesn't work on
>Win32; has anyone been able to come up something that does?
>

Hi,
   Net::FTP works fine for me on Win32 - what errors does it give
for you? What perl distribution are you using? Could it be a problem
with firewalls?
-- 
		Best regards,
		Randy Kobes

Physics Department		Phone: 	   (204) 786-9399
University of Winnipeg		Fax: 	   (204) 774-4134
Winnipeg, Manitoba R3B 2E9	e-mail:	   randy@theory.uwinnipeg.ca
Canada				http://theory.uwinnipeg.ca/


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

Date: Fri, 30 Oct 1998 13:39:02 -0500
From: "David J. Topper" <topper@virginia.edu>
Subject: How to run Perl/CGI under NT?
Message-Id: <363A07C6.4F9D1D0E@virginia.edu>

Hey there folks,

I'm a Unix Perl dude.  But now I have to run some code off MSIS under
NT.  So I've set up things with the NT Explorer to associate all files
with .pl and .cgi to launch perl.  But unfortunately, I can't seem to
get stuff to launch.  Here's a test script that simply prompts my
Netscape to download:

#!D:/Perl/bin/perl

print "Content-type:  text/html\n\n";
print "<FONT SIZE = +1><CENTER>Perl Works!</CENTER></FONT>";

Anybody?

Thanks y'all,

Dave Topper
--
David Topper
Technical Director - Virginia Center for Computer Music
Programmer Analyst - School of Arts and Sciences
http://www.panix.com/~topper
(804) 924-6887




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

Date: Fri, 30 Oct 1998 18:24:11 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: List of files to an array...
Message-Id: <fvn_1.4287$fS.13928260@news.itd.umich.edu>

In article <3639D36D.B4D6AAB5@ketchum.com>,
Pete Donina  <pete.donina@ketchum.com> wrote:
>I am lookling for an easy way to get a directory structure (path and
>filename) into an array.  I can do with a FOR loop and a GLOB but, it
>seems kind of slow.  I'm using Perl 5 on NT.

use File::Find;

find sub { push @structure, $File::Find::name }, '/top/level/path';

@structure now contains the directory structure below /top/level/path.

"perldoc File::Find" to learn about the magic of the File::Find module.

-- 
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
            | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
            | tv+ b++ DI++ D+ G e++>++++ h- r y+>++**          | umich.edu


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

Date: Fri, 30 Oct 1998 13:43:47 -0500
From: "Michael Mongeau" <michael_mongeau@stratus.com>
Subject: Re: List of files to an array...
Message-Id: <71d19s$okv@transfer.stratus.com>


Pete Donina wrote in message <3639D36D.B4D6AAB5@ketchum.com>...
>I am lookling for an easy way to get a directory structure (path and
>filename) into an array.  I can do with a FOR loop and a GLOB but, it
>seems kind of slow.  I'm using Perl 5 on NT.


How about File::Find ?

  use File::Find;
  find (sub { push @files,$File::Find::name }, "c:/temp");

After this runs the array @files will contain the full pathnames of all
files below c:/temp.

  Mike Mongeau





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

Date: Fri, 30 Oct 1998 11:47:04 -0800
From: Jason Orendorff <jorendorff@ixl.com>
Subject: Re: named arguments
Message-Id: <363A17B8.41F3E649@ixl.com>

> >This type of syntax might be annoying in Perl; I guess that's one
> >reason Perl doesn't have it.
> 
> What Abbagale wrote is valid perl.

Whoa-- I made a statement out of context; my mistake--

Here's the slow-motion replay, for those of you I've lost (I
apologize):

Python doesn't require ; at the end of a statement; a newline is
just fine.  Python uses () and [] and {} to decide whether your newline
represents an end-of-statement or not.  For example, Python will
understand this as one statement:

  call_ridiculous_MFC_function(this, has, about, 3352003,
                               arguments & theyre, _ALL,
                               required)

Abigail just mentioned that multiline statements can be used in a lot
of ways that don't have ()s or []s to give the parser a clue, so ;s
seem like a necessity.

What I meant by this:

> >This type of syntax might be annoying in Perl; I guess that's one
> >reason Perl doesn't have it.

is that Python's whitespace-is-significant tokenizer isn't a feature
you can just graft onto Perl... or if you do, don't complain to me
about the results!

-- 
Jason


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

Date: Fri, 30 Oct 1998 12:07:43 -0800
From: Jason Orendorff <jorendorff@ixl.com>
Subject: Re: named arguments
Message-Id: <363A1C8F.8B7A441B@ixl.com>

> I'm not sure what that buys you, when the language already supports
> dictionaries/hashes as first-class objects.

It's not a big deal, to be honest, but it's nice:

  def make_window(title='', size=(300,200), content=None, style=None):
      win = Frame(title)
      win.size = size
      # insert content or whatever...
      # do whatever "style" is supposed to do...
      win.visible = 1
      win.toFront()
      return win

and the function can be called thus:

  make_window('Hello, world!', (320, 200), nonsense_2)
  make_window(title='Hello, world!', size=(640,400))
  make_window(content=phat_gui)

but this is a non-silent error:

  make_window(name="foo")  #no argument called "name"

-- 
jason


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

Date: Fri, 30 Oct 1998 16:02:49 GMT
From: pub @ alma . ch (M.)
Subject: Re: new to perl (maybe)
Message-Id: <3639e23d.124042955@news.urbanet.ch>

>> Lacking functionality is mainly fork() and alarm(), as far as I have
>> been concerned. It hasn't really bothered me so far. (And there are
>> workarounds)
>
>Please be more specific about the workarounds.  I haven't seen any 
>posted here.

There is a module called something like Win32::CreateProcess, and the
new Perl has threads. I never used either, but I suppose they offer
ways to do the equivalent of fork(). I don't know about alarm().

I'm afraid I can't be of much help since I never really needed any of
these. I guess the Perl-Win32-Users mailing list would be a good place
to investigate further.



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

Date: 30 Oct 1998 16:37:46 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: Not to start a language war but..
Message-Id: <909765463.833966@elaine.drink.com>

In article <F1nBr7.MDw@world.std.com>,
Andrew M. Langmead <aml@world.std.com> wrote:
>gorilla@elaine.drink.com (Alan Barclay) writes:
>
>>Therefore I deduce that perl has had exceptions since day 1, or at least
>>at the patch level I have (perl v1.0.1.3 Patch level 10).
>
>I remember once looking around various comp.sources.unix archives for
>older versions of perl one of the patches for perl1 said something
>like "I finally found a reason to want an eval function".
>
>Ok, so I searched around a bit and found
><URL:ftp://ftp.uu.net/usenet/comp.sources.unix/voluem13/perl/patches6-10.Z>
>and found this descritption included in patch #8.
>
>>Subject: perl 1.0 patch #8
>>Message-ID: <1174@devvax.JPL.NASA.GOV>
>>Date: 28 Jan 88 19:44:05 GMT

Thanks for that correction. I knew that the patches added some functionality,
but I didn't think eval was added. Certainly though, the eval die functionality
was in there for perl1, which was 1 heck of a long time ago now, in computing
terms.




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

Date: Fri, 30 Oct 1998 17:58:52 GMT
From: wtanksle@cx930311-b.ocnsd1.sdca.home.com (William Tanksley)
Subject: Re: Not to start a language war but..
Message-Id: <slrn73jvir.ubi.wtanksle@cx930311-b.ocnsd1.sdca.home.com>

In article <714p7r$qf23@fido.engr.sgi.com>, Paul Jackson wrote:
>"Garrett G. Hodgson" <garry@sage.att.com> wrote:
>|> > I have not found a SINGLE real world computing problem ...
>|> one could say the same for assembly language.

>I'm finding the prospect of coding MicroSoft's Office suite in
>assembler amusingly improbable.

http://www.newdealinc.com has a (somewhat limited) office suite written
almost entirely in (Intel) assembler (with drivers to run under DOS,
although it's also been an NT app).  The word processor (which is by far the
most useful component) is 80K big.  You can download a shareware version
which includes only the WP.

What would that be like if written in Perl or Python?  Slow but portable.
:-) Now that I've brought this back off topic, I can go.

>Paul Jackson (pj@sgi.com; pj@usa.net) 3x1373 http://sam.engr.sgi.com/pj

-Billy


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

Date: Fri, 30 Oct 1998 18:08:56 GMT
From: dkirby@see.sig.for.addr (Dave Kirby)
Subject: Re: Not to start a language war but..
Message-Id: <36398c21.160788@read.news.global.net.uk>

On 29 Oct 98 01:05:58 GMT, Zenin <zenin@bawdycaste.org> wrote:

>Dave Kirby <dkirby@see.sig.for.addr> wrote:
>	>snip<
>: Yes python is OO, and so is perl. However creating a class in perl is
>: frankly a pain in the ass,
>
>	Huh?  What ya been smoking?
>
>		package Foo;
>		sub new { bless {}, shift }
>
>	Or even shorter:
>
>		sub Foo::new { bless {}, shift }
>
>	Want a sub class?
>
>		package Bar;
>		use base qw(Foo);
>
>	Want that in a one liner?
>
>		perl -e 'sub Foo::new { bless {}, shift }'

Hmmmnn... this is what perlobj.pod says:

---------------------------------------------------------------
if you care about inheritance (and you should; see Modules: Creation,
Use, and Abuse), then you want to use the
two-arg form of bless so that your constructors may be inherited: 

    sub new {
        my $class = shift;
        my $self = {};
        bless $self, $class
        $self->initialize();
        return $self;
    }

Or if you expect people to call not just CLASS->new() but also
$obj->new(), then use something like this. The
initialize() method used will be of whatever $class we blessed the
object into: 

    sub new {
        my $this = shift;
        my $class = ref($this) || $this;
        my $self = {};
        bless $self, $class
        $self->initialize();
        return $self;
    }
---------------------------------------------------------------

to me this is somewhat more complex and less readable than

class Foo:
    def __init__(self):
        #do whatever initalisation u need here

Since I have the virtue of being a Lazy Programmer, I know which I
prefer.

>[snip]

>: Here are a few reasons why I prefer python (in no particular order):
>:
>: * its cleaner and simpler.
>
>	Perl is complex, it's a feature.

No, power is a feature. Complexity is a price that perl pays to get
that power. I believe that python has (approximately) equivalent power
without the complexity.
>
>	Java is simple too.  Yet that same "simplicity" makes even the
>	simplest tasks a highly complex project.

Irrelevant. We are discussing python here, not java. Java is still way
more complex than python, while lacking many of the things that python
has.  Java 'simplified' C++ by throwing out much of the stuff that
made C++ powerful, while keeping much of the stuff that made it
complex.

>
>: This makes it easier to learn, but it does
>: not sacrifice any power for that simplicity.
>
>	That is highly arguable.
I and many others have stated that they found python easier to learn
than perl, but no-one who has learnt both languages has said they
found perl easier to learn.  As for not sacrificing any power, can you
provide an example of something that can be done easily in perl that
cannot be done easily in python? There are some things (such as
regexes) that perl has in the core language which have been moved into
the python libraries so using them is a little more verbose, but they
still are easy to use.

>
>: * better OO - see earlier comments.
>
>	Different and much more limited OO.  If you want Python style
>	OO in Perl you have only to use your own self control to limit
>	yourself to it.

In what way is it more limited? Do you mean in the number of different
ways that you can write the same thing (in which case I agree with
you) or in what you can do with the OO? If the latter can you give an
example?
Python supports multiple inheritance, operator overloading and
metaclasses. Classes are also objects in their own right and can be
passed to functions, stored in arrays etc just as in smalltalk. Whats
missing?

>
>: * better cross platform support. Since I work in Windows/NT this is a
>: biggie.
> [snip]
>: and with PythonWin I can create COM objects, do Active
>: Scripting, access the windows API & MFC etc.
>
>	And there goes your praised "truely cross-platform" argument. :-)
>
>	Seriously, you really should check out the Win32::* modules.

I've just had a look at the latest CPAN listing. I dont see any
mention of COM, ActiveX, Active Scripting, calling the C or MFC API
etc. With PythonWin you can write a full blown Windows application
using all of these.

>
>: * better interactive support. The interactive consol is a joy to use,
>: particularly via PythonWin or PTUI.
>
>	Ever try 'perl -d'?  Inside Emacs and similar debugger enabled
>	editors?  Or ptkdb for a pretty GUI interface?

Yes I have tried using the debugger, though not under emacs or ptkdb.
It only lets you enter a single line at a time - useless for adding
functions and classes on the fly, and (under Windows at least) doesn't
let you go back and edit previous lines. 

>
>: * JPython. I can write java applets in python (or a python/java mix)
>: that can be downloaded and run in a browser.  I can create a java
>: class and then subclass it in python, and if I want can compile the
>: new class and subclass it again in java.
>
>	This is a nice feature to have, I admit.
>
>	Useless, but nice. :-)
True you are unlikely to need to do that very often, but it does
illustrate how seamlessly java and JPython are integrated. If you have
to work in Java then you can still use python for writing test
scripts, rapid prototyping, glueing java code together etc.  You can
create a complete java app or applet using AWT, swing etc without
having to write a single line of Java - a big plus in my opinion.

>
>	>snip<
>: * Exceptions. These make error handling far easier and greatly
>: simplify the code.
>
>	Perl has had exceptions for dog years, before it even had
>	OO.  We just call try, throw, and catch "eval", "if", and "die"
>	respectively:
>
>	sub MyException::new { bless {}, shift() }
>	eval {
>	    trySomething()
>	        or die new MyException ();
>	};
>	if ($@) {
>	    if (ref $@ eq 'MyException') {
>	        cleanUp();
>	    }
>	    else {
>	        die; // propagate the exception
>	    }
>	}

Perl has _not_ had exceptions for dog years - AFAIK the ability to
pass an object to die has been added to 5.005 since it is not
mentioned in my 5.004 docs. Also perl does not have a heirachy of
pre-defined exception classes that are thrown consistently by the
language and by all the libraries used by the language. Unhandled
'die's in perl do not give a full stack trace to help you pinpoint the
source of the problem - I know the Carp module can give a stack trace
but is useless if the module that is dying doesnt use it. Is carp used
consistently throughout the standard perl libraries? In all the CPAN
modules? (A quick grep though the lib directory indicates that it is
not.)

The python equivalent of the above code is:

class MyException(Exception): pass

try:
    if not trySomething(): raise MyException
except MyException:
    cleanup()

Note that untrapped exceptions are automatically propagated upwards.
The python version is shorter and (in my eyes at least) more readable.

N.B. It would be better for trySomething to throw an exception rather
than return an error code, and in python more likely to be the case.
In that case it becomes:

try:
    trySomething()
except trySomethingException:
    cleanup()


[stuff on embedding & extending and block structure (including
irrelevant java example) snipped]

If you are happy using perl then fine, carry on using it. I used it
happily for years. However for _me_ python is a better alternative - I
spend far less time wrestling with the intricacies of the language and
more time solving the problems I want to solve.  Who knows, if you try
it out with an open mind then you may find the same.

	Dave K

----------------------------------------------------------------------------
One reason life is complex is that it has a real part and an imaginary part.
                                                       - Andrew Koenig
      
dkirby@   <-figure this out, spambots!
bigfoot.   My opinions are my own,        
com        but I'm willing to share.      


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

Date: Fri, 30 Oct 1998 18:08:58 GMT
From: dkirby@see.sig.for.addr (Dave Kirby)
Subject: Re: Not to start a language war but..
Message-Id: <363aad2a.8619276@read.news.global.net.uk>

On 29 Oct 1998 16:48:34 GMT, Zenin <zenin@bawdycaste.org> wrote:

>John Porter <jdporter@min.net> wrote:
>	>snip<
>:   @Widget::ISA = ('Frob');
>:   sub Widget::new { bless {} }
>:
>: 'package' doesn't actually relate to Perl's OO in any special way;
>: it just changes the default namespace for any following unqualified
>: declarations.
>
>	It also affects the single argument form of bless() in ways that
>	will make the above example fail:
>
>	$ perl
>	@Widget::ISA = ('Frob');
>	sub Widget::new { bless {} }
>	my $widget = new Widget;
>	print ref $widget;^D
>	main
>
>	Since the object is now blessed into package main::, it will never
>	search @Widget::ISA to find Frob or borrow any of Frob's methods.
>
>	Better to code that constuctor:
>
>	sub Widget::new { bless {}, shift }

Doesnt the fact that two (presumably) experienced perl programmers can
disagree on this blow the foot off your assertion that creating a
class in perl is as easy as creating one in python?

	Dave
--------------------------------------------------
All great ideas start as heresy and end as dogma.

dkirby@   <-figure this out, spambots!
bigfoot.   My opinions are my own,
com        but I'm willing to share.


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

Date: Fri, 30 Oct 1998 12:12:53 -0800
From: Jason Orendorff <jorendorff@ixl.com>
Subject: Re: Not to start a language war but..
Message-Id: <363A1DC5.1AEAA981@ixl.com>

> Therefore I deduce that perl has had exceptions since day 1, or at
> least at the patch level I have (perl v1.0.1.3 Patch level 10).

*frown*  Calling this behavior "exception handling" neglects most of
what modern exception handling is.

-- 
Jason


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

Date: Fri, 30 Oct 1998 17:02:09 +0100
From: jwl@_munged_worldmusic.de (Joergen W. Lang)
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <1dhpz28.5rwcvm1zg5moN@host042-210.seicom.net>

cc'd to cited author.

Randal Schwartz <merlyn@stonehenge.com> wrote:

> Joergen> my $four_digit_year = ((split / /, localtime)[4]);      
> 
> I don't think you want either "4" or / / there. Witness:
> 

<snip>

> 
> One solution would be using -1 there.  Another would be using /\s+/
> so that the multiple spaces don't make multiple delimiters.
> 
> In any case, your code wasn't tested.  Just like some of mine that
> later turns out to be wrong. :)

I have to admit, I didn't test it thoroughly. I was using a variation on
that theme to get the short month string via

print ((split / /, localtime)[1]); 

so I thought, well fine, could do that same thing for getting the year.
I simply did not know that localtime returns /\s\d/ as the day of the
month if the day of the month is smaller than 10. Is there any
underlying reason why this is not /\d\d/ in all cases ?
Aesthetics, I suppose. :-)

print ((split /\s+/, localtime)[4]); 
# works just fine, though, thanks ! 

Still, I'm a bit puzzled on how the -1 solution mentioned above would
have to be done. 
Hints appreciated.

Joergen
-- 
  To reply by email please remove _munged_ from address Thanks !
-------------------------------------------------------------------
   "Everything is possible - even sometimes the impossible"
             HOELDERLIN EXPRESS - "Touch the void"


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

Date: Fri, 30 Oct 1998 16:52:38 GMT
From: caulds@mindspring.com (Charles Aulds)
Subject: Perl DCOM Question -- setting property
Message-Id: <3639e8ca.8600158@news.mindspring.com>

Working through the examples in the Perl Utilities Guide and Dr. GUI's ATL
discussion; I've created an ActiveX object that I can reference with Visual C++,
Visual Basic, and Perl (using Win32::OLE).  All the pieces appear to be in
place; straight out of the book:

		use Win32::OLE;
		$clsid='{E3A0A760-6E8B-11D2-9DDC-00C0E3251B6F}';
		$ctrl=Win32::OLE->new( [KIOSK,$clsid] );
		if (not defined $ctrl ) {
		  print Win32::OLE->LastError;
		  exit;
		}

I can call a method "foo" as:

		$ctrl->foo;

I can read the value of a property:

		$value=$ctrl->Count;

Why can I not set the value of that same property, using either of the
following?

		$ctrl->Count=5;
	or	$ctrl->put_Count(5);

What am I missing??  I trust you guys to know!  ;-)


---
Charles Aulds, MCSE
<charles@connectware-hsv.com>
Systems Analyst,  Connectware Solutions
Huntsville Solution Center, Huntsville, Alabama
Voice: 256-536-0812           Fax: 256-536-0872


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

Date: Fri, 30 Oct 1998 19:57:50 +0100
From: Dmitri Levitin <dmitri@compuserve.com>
Subject: perl news per Email?
Message-Id: <363A0C2E.6EA33AB4@compuserve.com>

Hello!

I don4t have a possibility to read perl news directly, so I would like
to become comp.lang.perl.misc,
comp.lang.perl.tk and perl.lang.perl.module per Email. How can I do it?

Thanks,
Dmitri



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

Date: Fri, 30 Oct 1998 17:34:29 GMT
From: nguyen.van@imvi.bls.com
Subject: Problem with installing modules sybperl & Data-Dumper
Message-Id: <71ctb5$440$1@nnrp1.dejanews.com>

Hi guys,

I tried to install these two mudules but got some errors; so please help
me:

for module sybperl, I got the following errors:
________________________________________________________________________

acc -c -I/opt/net/solaris/sybase/include  -O     -DVERSION=\"2.09\"
-DXS_VERSION=\"2.09\" -Kpic -I/opt/lib/perl5/sun4-solaris/5.00404/CORE
-DCTLIBVS=100 -DSYBPLVER='"2.09"' -DDO_TIE CTlib.c
sh: acc: not found
*** Error code 1
make: Fatal error: Command failed for target `CTlib.o'
Current working directory /opt/lib/sybperl-2.09/CTlib
*** Error code 1
make: Fatal error: Command failed for target `subdirs'
________________________________________________________________________

for module Data-Dumper, I got the following errors:
________________________________________________________________________

cp Dumper.pm ./blib/lib/Data/Dumper.pm /opt/net/solaris/bin/perl
-I/opt/lib/perl5/sun4-solaris/5.00404 -I/opt/lib/perl5
/opt/lib/perl5/ExtUtils/xsubpp	-typemap /opt/lib/perl5/ExtUtils/typemap
Dumper.xs >Dumper.tc && mv Dumper.tc Dumper.c acc -c  -O  -DVERSION=\"2.09\" 
-DXS_VERSION=\"2.09\" -Kpic -I/opt/lib/perl5/sun4-solaris/5.00404/CORE 
Dumper.c sh: acc: not found *** Error code 1 make: Fatal error: Command
failed for target `Dumper.o'
________________________________________________________________________

Please help me to get through.

Thanks
Van Nguyen

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 30 Oct 1998 11:26:53 -0800
From: Jason Orendorff <jorendorff@ixl.com>
Subject: Re: Python fun
Message-Id: <363A12FD.41331E56@ixl.com>

> > In Tcl, ML, Python, or Lisp, you'll find it's much more fun.  Sorry
> > to say it, 'cos I like Perl too... but it's true.
> 
> Speak for yourself, monkey boy.  :-)

A lot of stuff is fun in Perl, but if you get a kick out of
dereferencing variables, you need help.  ;-)

-- 
Jason
not evolutionarily challenged


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

Date: 30 Oct 1998 16:28:04 GMT
From: "George H" <george@tapestry.net>
Subject: Regex Problem
Message-Id: <01be0421$5f45e2c0$6296cdcf@hp-customer>

I am trying to remove chunks of a query string from the middle of
QUERYSTRING for some regexp practice.  The following works fine for
removing '&movie=Star+Wars&' and replacing it with a '&' (yes, I know this
misses items at the end or beginning of the query ... this is just an
exercise).  However, if the query string looks like '&movie=&' it doesn't
work.  I thought '*' would work because it is 0 or more ... but I am
missing something.

Any ideas?

foreach $remove (@removals) 
 {
  	if($jobinfo{$remove})
	{
	$querystring =~ s/\&$remove\=[^\&]*\&/\&/g;
	}	
}

Thanks,

George H


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

Date: Fri, 30 Oct 1998 11:57:33 -0500
From: Jack de Valpine <jedev@visarc.com>
Subject: regexp question - re: {n}
Message-Id: <3639EFFC.6595B164@visarc.com>

Hi:

If this is FAQ somewhere please let me know where, but I have tried to
investigate as much as possible before sending out this question
(O'Reilly - "Programming Perl" and "Perl Cookbook").

Here is what I would like to do. I have data that is generally of the
form:

arg_count arg1 arg2 arg3 ... argn

where the first term indicates the number of parameters to follow and
what follows are the actual parameters. (note the parameters can also
span lines)

for example:

5 1 1 1 0 0

or

4
    red green blue fname

I would like to be able to use regexps to find these parameter sets. I
have discovered a few ways to do this. It seems that the following
should work, but it does not. I expect that this has something to do
with how backreferences my be interpreted. What am I missing?

/^(\d+)\s+((\S+\s+){\1})/gom

ie - find a number at the beginning of the line, then find what follows
that many times again

Thanks for your help.

Regards,

-Jack de Valpine

ps: please cc me in the reply to the newsgroup, thanks.




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

Date: Fri, 30 Oct 1998 16:46:08 GMT
From: techtest@knowitallinc.com
Subject: Short term, remote PERL project
Message-Id: <71cqgg$e2$1@nnrp1.dejanews.com>

Know It All, Inc, a Philadelphia based software company, is looking for
a PERL "expert" for a very short term, non-programming, remote project.
If interested, please contact by November 13, 1998.

e-mail techtest@knowitallinc.com.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 30 Oct 1998 16:41:18 GMT
From: beppu@rigel.oac.uci.edu (John Beppu)
Subject: Re: Size of JPEG and GIF
Message-Id: <71cq7e$ife@news.service.uci.edu>


In article <712o2v$tb7$1@nnrp1.dejanews.com>,
 <parab0la@my-dejanews.com> wrote:

>Hi all,

    hey.

>I'm writing a small HTML generator in PERL, and wants to find out the size of
>GIF and JPEG images.  So that I can write the HEIGHT= and WIDTH= options in
>the <IMG> tag.	What is the most suitable way to do it?  Should I use PERL to
>parse the header of those files?  Or is there any external command that I can
>call?

    I wrote a script to do exactly this task last week.  I called
    the external command indentify(1) that comes with ImageMagick
    to find the width and height of images.

>Thx!
>--
>Parabola - the famous curve.
>URL:       http://parabola.home.ml.org/

    This is how I did it.  It's my first Perl script, so be gentle.

#!/usr/bin/perl -w


# Lazy HTML writers often ignore putting width && height tags in their
# <img> tags which unnecessarily increases the loading time of a page.
# This can be a bitch if the page is image-heavy.  

# This perl script deals with this problem by taking HTML from <STDIN>,
# and spitting out HTML with proper <img> tags to <STDOUT>


#_____________________________________________________________________function
sub imagetag_create_from_string()
{
    my @parameter;
    my $tmp;
    my @imagetag;
    my $ndx;

    $ndx = 0;
    foreach $string (@_) {
        my %imagetag;

        @parameter = ($string =~ m/\w+= /sxig);
        foreach $parameter (@parameter) {
            $tmp = $string;
            $tmp =~ s/(<img *)(.*?)${parameter}("?\w+"?)(.*>)/$3/si;
            if (($tmp =~ /^"/) && ($tmp !~ /"$/)) {
                $tmp = $string;
                $tmp =~ s/(<img *)(.*?)${parameter}(".+?")(.*>)/$3/si;
            }
            $parameter =~ s/=$//;
            $tmp =~ s/(^"|"$)//g;
            $imagetag{lc $parameter} = $tmp;
        }
        $imagetag[$ndx++] = \%imagetag;
    }
    return @imagetag;
}


# By taking the src out of an %imagetag and feeding it to identify(1),
# the images proper width && height will be determined and placed in 
# the %imagetag.  
#_____________________________________________________________________function
sub imagetag_insert_wd_hi ()
{
    my %imagetag;
    my $width;
    my $height;
    my $tmp;

    %imagetag = %{$_[0]};
    if ( -f $imagetag{src} ) {
        $tmp = `identify $imagetag{src}`;
        ($width,$height) = ($tmp =~ m/.*? (\d+)x(\d+) (.*)/sx);
        $imagetag{width} = $width;
        $imagetag{height} = $height;
    }
    return %imagetag;
}



# Converts an %imagetag into an HTML <img> tag
#_____________________________________________________________________function
sub imagetag_print()
{
    my %imagetag;
    my $imghtml;
    my $param;

    %imagetag = %{$_[0]};
    $imghtml = '<img';
    if (exists $imagetag{src}) {
        $imghtml = $imghtml . qq| src="$imagetag{src}"|;
        delete $imagetag{src};
    }
    if (exists $imagetag{width}) {
        $imghtml = $imghtml . qq| width="$imagetag{width}"|;
        delete $imagetag{width};
    }
    if (exists $imagetag{height}) {
        $imghtml = $imghtml . qq| height="$imagetag{height}"|;
        delete $imagetag{height};
    }

    foreach $param (sort keys %imagetag) {
        $imghtml = $imghtml . qq| $param="$imagetag{$param}"|;
    }
    $imghtml = $imghtml . ">";
    return $imghtml;
}



# _______________________________________________________________________ main

my $text = "";
my %imghash;
my $ndx;
my @imghtml;

@file = <STDIN>;
foreach $line (@file) {
    $text = $text . $line;
}

@imgtag_raw = ($text =~ /<img.*?>/sxig);
@img = &imagetag_create_from_string(@imgtag_raw);
$ndx = 0;
foreach $img (@img) {
    %imghash = %{$img};
    %imghash = &imagetag_insert_wd_hi(\%imghash,0);
    $imghtml[$ndx++] = &imagetag_print(\%imghash);
}

# I've got all the modifications in @imghtml...
# now what?

$ndx = 0;
$unique_string="wOep3fTasdk23";
$text =~ s/<img.*?>/$unique_string/sxig;
while ( $text =~ /$unique_string/ ) {
    $text =~ s/$unique_string/$imghtml[$ndx++]/x;
}
print $text;

exit 0;



-- 
/** beppu@uci.edu ......................................................... */


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

Date: 30 Oct 1998 16:00:26 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Style Guides
Message-Id: <71cnqq$ohf$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, "Arjan Huijzer" <arjan.huijzer@capgemini.nl> writes:
:Currently I am reworking some Perl Scripts so they are more readable. I have
:read the Style Guide contained in the Perl Documentation, but was wondering
:if there are more such documents. Could someone point me to relevant
:material.

http://language.perl.com/style/

--tom
-- 
Common sense is the collection of prejudices acquired by age 18.
      --Einstein


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

Date: 30 Oct 1998 12:43:05 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <71ctr9$a12$1@monet.op.net>

In article <8ck91iqciu.fsf@gadget.cscaper.com>,
Randal Schwartz  <merlyn@stonehenge.com> wrote:
>>>>>> "Bob" == Bob Stewart <rstewart@vmirror.com> writes:
>
>Bob> $num_keys = keys %LINES;
>
>Bob> 8.04u   0.48s   0:12.19   69.8%
>Bob> 7.87u   0.45s   0:11.00   75.6%
>
>Bob> $num_keys = scalar keys %LINES;
>
>Bob> 8.02u   0.57s   0:12.69   67.6%
>Bob> 7.85u   0.52s   0:12.30   68.0%
>
>These are *precisely* the same thing.  "scalar" is not a function.  It
>does nothing.  It does not have an opcode.  It does not have a runtime
>speed.

That's what I thought too, but we're mistaken.  Try

	perl -Dx -e '$s = keys %h'
	perl -Dx -e '$s = scalar keys %h'

and you'll see that the second one contains a call to the pp_scalar opcode.
However, if you look at the code (around line 117 of pp.c) you'll see
that it's probably the fastest opcode there is.

It seems as though an sassaign(scalar(...)) is a good candiate for the
peephole optimizer.





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

Date: 30 Oct 1998 13:00:18 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <71curi$a6n$1@monet.op.net>

In article <1dhosmo.18v4ldup07o4iN@bay1-402.quincy.ziplink.net>,
Ronald J Kimball <rjk@coos.dartmouth.edu> wrote:
>First, reread the original poster's question, quoted above.  Note the
>phrase 'without using the keys function'.  :-)

I think that comes under the heading of `questions that don't need to
be answered'.  Like ``I want some kind of device to put on my wrist
that will tell me what time it is.  But no watches, I don't want to
wear a watch.  Can anyone help?''  (``Sure.  Try wearing a watch.'')

>  In a scalar context, keys returns the number of elements of the hash
>  (and resets the each iterator).  However, to get this information for
>  tied hashes, including DBM files, Perl must still walk the entire
>  hash, so it's not very efficient in that case.

Just because it's not efficient doesn't mean you can do any better.
If you want to count something, you have to count it.

In the case of internal hashes, Perl can count it as it goes along,
but it still takes time.  The only reason it's a win is because Perl
has to keep track of the count whether you want it or not.  It's like
a nightclub with a free buffet.  The buffet is included in the cost of
the admission, and you might as well eat it because you've already
paid for it whether you wanted to or not.

In tied hashes, someone has to count them all over again.
You could follow Russ'  suggestion:

	while ($key = each %hash) {
	  if (! $seen{$key}++) {
	    $total++;
	  }
	}

or some such, but I bet a nickel that that takes a lot longer than
letting Perl count them using `keys':

	while ($key = each %hash) {
	  $seen{$key}++;
	}
	$total = keys %hash;




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

Date: Fri, 30 Oct 1998 18:18:50 GMT
From: rstewart@vmirror.com (Bob Stewart)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <363a0275.3579600@news.digex.net>


>I doubt the time the programs took to run was even slightly influenced by
>the extracted single statements (building the hash probably took all the
>time)...
>

Actually, it was already loaded. All this really did was open it, add
10 keys to the 100,000 already there, and then run that statement to
determine the number of keys.

It still takes a while, but it's faster than what I had. ;-)

Bob Stewart






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

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


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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