[10559] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4151 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 4 18:07:58 1998

Date: Wed, 4 Nov 98 15:00:19 -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           Wed, 4 Nov 1998     Volume: 8 Number: 4151

Today's topics:
    Re: -w (was Re: It works , but why) (Tye McQueen)
        Array problems for a newbie <tim.hicks@lineone.net>
    Re: camel races on CNN <earlw@kodak.com>
    Re: Decimal to Hex conversion <rootbeer@teleport.com>
    Re: Decimal to Hex conversion <barnett@houston.Geco-Prakla.slb.com>
        DSN connect string syntax for DBI:ODBC <beadles@nortel.com>
    Re: Echoing multi-line text to the DOS shell (Tye McQueen)
        HELP: perl script fails on setuid binary (Robert S. Campbell)
    Re: How do you delete files in a directory? (John Moreno)
        Locale warning messages (Jeff Patterson)
    Re: Locale warning messages (K. Krueger)
    Re: making an executable under win95 <indy@NOSPAMdemobuilder.com>
    Re: making an executable under win95 <indy@NOSPAMdemobuilder.com>
    Re: making an executable under win95 <indy@NOSPAMdemobuilder.com>
    Re: Not to start a language war but.. <arcege@shore.net>
    Re: Not to start a language war but.. <tchrist@mox.perl.com>
    Re: Not to start a language war but.. <merlyn@stonehenge.com>
    Re: PERL manual - html (Tad McClellan)
    Re: perl5 make fails (Tye McQueen)
    Re: Raw socket programming in Perl ecki@lina.inka.de
        Sending a file to a printer m.adam@libr.canterbury.ac.nz
    Re: seperating paragraphs (kind of like $/) (Tad McClellan)
    Re: seperating paragraphs (kind of like $/) <ckuskie@cadence.com>
    Re: Why is perl better than shell scripting language? (Ben Coleman)
        win32::ole docs--where? java@josho.net
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 4 Nov 1998 15:22:50 -0600
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: -w (was Re: It works , but why)
Message-Id: <71qgja$kvs@fohnix.metronet.com>

) > Jarle H Knudsen <no.unsolicited.mail.please@jarle.com> wrote:
) > 
) > > If this is so important, why isn't this on by default? Then there
) > > could be a switch to turn it of instead.

) Ronald J Kimball wrote:
) >    BUGS
) >      The -w switch is not mandatory.

Tk Soh <r28629@email.sps.mot.com> writes:
) 
) Is this bug intentional?

"-w" is usually not desired by default for quicky, one-off scripts
[like one-liners], nor is C<use strict>.  But these are both
usually desirable for larger scripts.  For larger scripts, it
is very easy to add "#!/usr/bin/perl -w" and C<use strict> [just
like "#include <stdio.h>" for C code].

But then, there are people who have many scripts where "-w" and/or
C<use strict> are not desirable to them.

So, it is the newbie who doesn't read all of the documentation [who
does?] that suffers.  Somehow making "-w" the default when you
first install Perl and then letting you make it not the default when
you start writing a lot of one-liners...  Well, that just seems
too complicated and prone to even worse problems.

Perhaps the real reason is that originally there was no "-w" nor
C<use strict> and so making either the default would suddenly
change how lots of old scripts function.  This is frowned upon.

Backward compatibility is important but requires compromises of
those not needing it.
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

Date: Wed, 4 Nov 1998 16:01:43 -0000
From: "Tim Hicks" <tim.hicks@lineone.net>
Subject: Array problems for a newbie
Message-Id: <sD402.17539$357.360@news-reader.bt.net>

Hi all,

I am currently reading through 'Learning Perl' for Unix (despite running
Win95, which was a mistake!) and trying to do the exercises at the end of
chapters.  Can anyone tell me what is wrong with this solution to chapter 6,
question 1.  It is supposed to have someone enter a list of words, and then
print out those words in reverse order.  The problem is, it doesn't print
the last word that has been entered.  Here is the code.

#!/usr/bin/perl -w
print "Enter your word list followed by 'control' Z\n";
while (<>) {
push (@array, $_);
}
@arrayr = reverse (@array);
print @arrayr;


Incidentally, the same thing happens with this bit of code as well.

#!/usr/bin/perl -w
print "Enter your column width...\n";
chomp ($width = <STDIN>);

print "Enter your word list...\n";
while (<>) {
 push (@array, $_);
}
foreach (@array) {
printf "%${width}s", $_;
}


I wonder if it's the same problem?!?

Thanks to anyone who can help.


Tim







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

Date: Wed, 04 Nov 1998 17:10:16 -0500
From: Earl Westerlund <earlw@kodak.com>
Subject: Re: camel races on CNN
Message-Id: <3640D0C8.493@kodak.com>

Uri Guttman wrote:
> 
> last night i was watching cnn headline news and after the sports report
> they showed the play of the day. to my surprise it was a camel race in
> some country where that is common. it was total chaos and nothing like
> the order of a thouroughbred horse race. the camels seem to do what they
> wanted to do regardless of their jockey's guidance. seems like our
> favorite language has not only the architecture but the personality of
> its mascot.
> 
> did anyone else catch this? i doubt it will be on again as they use each
> POTD clip for only a few broadcasts.
> 
> uri

And this morning's subject on "The Nature of Things," a 5-minute show
from Vermont Public Radio, was... camels.  Just a general overview of
them, how they've been domesticated for years (way longer than 10), how
they're used for food, milk and wool.

Is there something going on I haven't heard...?
-- 
+-----------------+----------------------------------------+
| Earl Westerlund | Kodak's Homepage: http://www.kodak.com |
+-----------------+----------------------------------------+
|  The opinions expressed herein are mine and mine alone   |
|     (most people don't seem to want them anyway)         |
+----------------------------------------------------------+


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

Date: Wed, 04 Nov 1998 21:00:42 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Decimal to Hex conversion
Message-Id: <Pine.GSO.4.02A.9811041253540.7431-100000@user2.teleport.com>

On 4 Nov 1998, Eric Hagen wrote:

> What I would like to do is to take a number string like 2345678 and
> then turn that into the hex value.  Which should be 23CACE.

> My understanding of printf is that it allows you to print out the
> 23CACE, but not translate it from 2345678 to 23CACE.

So, use sprintf, instead of printf. 

    $ perl -lwe '$fred = sprintf "%06x", 2345678; print $fred'

Hope this helps!

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



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

Date: Wed, 04 Nov 1998 15:41:08 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
To: Eric Hagen <ehagen@Hawaii.Edu>
Subject: Re: Decimal to Hex conversion
Message-Id: <3640C9F4.B85739BE@houston.Geco-Prakla.slb.com>

[courtesy cc  to cited author]

Eric Hagen wrote:
> 
> Hate to say no, but I don't.
> 
> What I would like to do is to take a number string like 2345678 and then
> turn that into the hex value.  Which should be 23CACE.
> My understanding of printf is that it allows you to print out the 23CACE,
> but not translate it from 2345678 to 23CACE.  Please correct me if I'm
> wrong.
<snip>

You are correct in the fact that printf will print them for you, but not
convert them.

perldoc -f sprintf might be of some assistance to you.

HTH.

Cheers,
Dave

-- 
Dave Barnett	Software Support Engineer	(281) 596-1434


If work is so terrific, how come they have to pay you to do it?


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

Date: Wed, 04 Nov 1998 15:45:49 -0600
From: John Beadles <beadles@nortel.com>
Subject: DSN connect string syntax for DBI:ODBC
Message-Id: <3640CB0D.8529F6C0@nortel.com>

I've been searching the docs all day and can't find the answer. I'm
working on using DBI to connect to a remote Sybase database and I can't
find detailed docs on the DBI connect syntax.  What I don't understand
is where the Sybase database should go. 

The dbd and dbi docs included with the perl ports don't seem to discuss
this, and I can't find it anywhere else either.

The following code works fine as long as I specify the database in the
connect string.  In fact, it won't work without it.

**************************
use Win32::ODBC;

print "hello\n";

if (!($db=new Win32::ODBC("DSN=Test;UID=foo;PWD=bar;DATABASE=temp"))){
	print "Error: ".Win32::ODBC::Error()."\n";
}

$query="SELECT * FROM Customer";
if ($db->Sql($query)){
	print "LocationSQL failed\n";
	print "Error: ".$db->Error()."\n";
	$db->Close();
	exit;
}

*************************

The code below also works without the database entry, and I can see no
place where I could put the name of the database; ie "temp".  Since
there could be multiple databases with the table "Customer", how can I
specify which one is correct?

*************************
use DBI 0.89;

print "hello\n";

$dbh= DBI->connect('dbi:ODBC:Test','foo','bar',{RaiseError=>1});
$cursor=$dbh->prepare("SELECT * FROM Customer");
$cursor->execute;

while (@row = $cursor->fetchrow_array) {
	print "$row[0]\t$row[1]\t$row[2]\n\n";
}

------------------------------------------------
John T. Beadles   Nortel Technology Applications                       
Office: 972-685-7813           Fax: 972-684-3767 
Email (office):    beadles@nortel.removethis.com  
Any opinions are mine and to do not represent
             those of my employer
------------------------------------------------


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

Date: 4 Nov 1998 15:58:09 -0600
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: Echoing multi-line text to the DOS shell
Message-Id: <71qilh$2b4@fohnix.metronet.com>

unixdba@aol.com (UnixDBA) writes:
) @output = `isql -whatever << EOF
) sp_who
) go
) EOF`;
[...]
) How would I do this in DOS?

    @output= `perl -e "print qq{sp_who\ngo\n}" | isql -whatever`;

And someone said this isn't a Perl question!
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

Date: 4 Nov 1998 22:17:36 GMT
From: rsc@snipe.scd.ucar.edu (Robert S. Campbell)
Subject: HELP: perl script fails on setuid binary
Message-Id: <71qjq0$dde$1@ncar.ucar.edu>


I've run into a problem with a perl script that I can't seem to get around.

The script formats print jobs for a kodak printer, adds a banner page with
some specific info, and creates specific postscript function calls the 
printer understands for duplex, stapling, collating, etc, and wraps those
postscript commands around a postscript print job.
ie:  k1580 -d long -p kodak report.ps   
will print the file report.ps on the kodak printer with duplex folded along 
long edge of the paper.

The script pipes the job to lpr:
# Send the output to the printer, unless no printer is specified.
open (STDOUT, "|lpr -P $printer") unless ($printer eq "");

Now, on my Solaris 2.5.1 machines, lpr is separate from lp.  On the one 
machine that has Solaris 2.6 and is really the one machine I really need
this script to work, lpr is a link to /bin/lp, which, for some reason, 
is setuid root.

The script works fine on it's own, and works fine if called from within a
bourne-shell script:
# more /tmp/test.sh
#!/bin/sh

rptid=$1

/usr/local/bin/enscript -r -o - $rptid | eval /usr/local/bin/k1580 -d long -p k1580


Now, here's the rest of the scenario:  My users run a program that generates
reports for them.  That program writes reports to a file and calls a 
bourne-shell script which then grabs the file and calls enscript and the 
perl script, just like what you see above.  
So, program -> bourne script -> perl -> lp.

Which fails with the following error:
Insecure $ENV{PATH} while running setuid at /usr/local/bin/k1580 line 199.
(line 199 is the "open (STDOUT..." above)

I'm running:
# perl -v
This is perl, version 5.004_04 built for sun4-solaris

Is there any way around/fix to this?  Is perl generating the above error? 
(I assume so, but...)  

I'll read any replies once I've killed the person who installed Solaris 2.6
on this machine (note: upgrading to 2.5.1 or 2.7 is not an option).


Thanks,
Bob Campbell			Unix System Administrator
Scientific Computing Division	National Center for Atmospheric Research
rsc@ucar.edu			(303) 497-1815


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

Date: Wed, 4 Nov 1998 16:19:00 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: How do you delete files in a directory?
Message-Id: <1dhz990.12gyws61ea17vcN@roxboro0-020.dyn.interpath.net>

Dariush <dazimi@oradev.csis.csd.metrotor.on.ca> wrote:

> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML>
> How can I 

First you don't post in html, then you read the perl man pages.

-- 
John Moreno


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

Date: 4 Nov 1998 22:39:45 GMT
From: jpat@sonic.net (Jeff Patterson)
Subject: Locale warning messages
Message-Id: <71ql3h$n31$1@ultra.sonic.net>

Ever since I installed redhat 5.1 (linux) which updated perl, everytime I
run a perl script I get the annoying message

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LC_ALL = (unset),
        LANG = "EN"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

my LANG="EN" and LC_ALL is unset. 

I neither want or care about locale. I just want perl to shut about it. Any
clues?

Thanks



-- 
Jeff Patterson
Site Administrator
The Melanoma Patients' Information Page
http://www.mpip.org/


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

Date: 4 Nov 1998 14:51:01 -0800
From: kirbyk@best.com (K. Krueger)
Subject: Re: Locale warning messages
Message-Id: <71qlol$qf9$1@shell2.ba.best.com>

In article <71ql3h$n31$1@ultra.sonic.net>,
Jeff Patterson <jpat@sonic.net> wrote:
>Ever since I installed redhat 5.1 (linux) which updated perl, everytime I
>run a perl script I get the annoying message
>
>perl: warning: Setting locale failed.
>perl: warning: Please check that your locale settings:
>        LC_ALL = (unset),
>        LANG = "EN"
>    are supported and installed on your system.
>perl: warning: Falling back to the standard locale ("C").
>
>my LANG="EN" and LC_ALL is unset. 
>
>I neither want or care about locale. I just want perl to shut about it. Any
>clues?
>
I don't think this is really a perl-specific problem, but it's one that I've
had, too.  (Specifically, when ssh-ing from a CDE machine to a non-CDE 
Solaris machine.)  For me, doing 'unsetenv LC_CTYPE' makes it shut up - I'd
look through your environment variables for something similar.

-- 
Kirby Krueger      O-     kirbyk@best.com 
<*> "Most .sigs this small can't open their own jump gate."


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

Date: Wed, 4 Nov 1998 17:22:14 -0500
From: "Indy" <indy@NOSPAMdemobuilder.com>
Subject: Re: making an executable under win95
Message-Id: <71qjmg$1hv$1@nntp2.uunet.ca>

Check out www.perl2exe.com



Avshi Avital wrote in message <71k1l4$bos$1@cnn.cc.biu.ac.il>...
>hi,
>suppose i have a perl-script 'foo', how do I  turn it into an executable
>(so that another user does not need perl to be installed on his
>computer)? that is: 'foo.exe'.
>
>thanx,
>
>--
>Avshalom Avital
>Information Retrieval Laboratory
>Bar-Ilan University, Israel
>avitala@macs.biu.ac.il
>
>
>




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

Date: Wed, 4 Nov 1998 17:22:14 -0500
From: "Indy" <indy@NOSPAMdemobuilder.com>
Subject: Re: making an executable under win95
Message-Id: <71qjo7$1if$1@nntp2.uunet.ca>

Check out www.perl2exe.com



Avshi Avital wrote in message <71k1l4$bos$1@cnn.cc.biu.ac.il>...
>hi,
>suppose i have a perl-script 'foo', how do I  turn it into an executable
>(so that another user does not need perl to be installed on his
>computer)? that is: 'foo.exe'.
>
>thanx,
>
>--
>Avshalom Avital
>Information Retrieval Laboratory
>Bar-Ilan University, Israel
>avitala@macs.biu.ac.il
>
>
>




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

Date: Wed, 4 Nov 1998 17:22:14 -0500
From: "Indy" <indy@NOSPAMdemobuilder.com>
Subject: Re: making an executable under win95
Message-Id: <71qjuk$1jr$1@nntp2.uunet.ca>

Check out www.perl2exe.com



Avshi Avital wrote in message <71k1l4$bos$1@cnn.cc.biu.ac.il>...
>hi,
>suppose i have a perl-script 'foo', how do I  turn it into an executable
>(so that another user does not need perl to be installed on his
>computer)? that is: 'foo.exe'.
>
>thanx,
>
>--
>Avshalom Avital
>Information Retrieval Laboratory
>Bar-Ilan University, Israel
>avitala@macs.biu.ac.il
>
>
>




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

Date: Wed, 04 Nov 1998 21:01:44 GMT
From: "Michael P. Reilly" <arcege@shore.net>
Subject: Re: Not to start a language war but..
Message-Id: <Yg302.93$We.6267@news.shore.net>

In comp.lang.python Zenin <zenin@bawdycaste.org> wrote:
: Michael P. Reilly <arcege@shore.net> wrote:
: : In comp.lang.python Sam Holden <sholden@pgrad.cs.usyd.edu.au> wrote:
: : : On Mon, 02 Nov 1998 17:24:17 -0800, Jason Orendorff <jorendorff@ixl.com> wrote:
:        >snip<
: : : Except of course that warn does not have to output to stderr...
: : : $SIG{__WARN__} can do whatever it likes with it (useful in things such
: : : as CGI (though you should just use CGI.pm)).
: : : This leaves the caller free to handle the warning however it wants.
: : : So the equivelant python is...?
: :
: : import sys, cStringIO
: : real_stderr = sys.stderr
: : sys.stderr = cStringIO.StringIO() # can be any object that mimics a
: :                                   # file object (with a write method)
: : Then the internal commands that write to stderr will be redirected to
: : this new object.  The "real_stderr" is to revert back, if necessary.
: : This is better for CGI script, because you can do:
: :   sys.stderr = sys.stdout

:        This is still not equivalent at all.

:        You're just mucking with the global sys.stderr, which then affects
:        all calls to stderr.  This would be the same as dup()ing and
:        re-open()ing STDERR in perl with a tied filehandle class, and just
:        as simple. -Same with C or shell for that matter.

Then I think the question should have been stated better, because I
believed that the "how is this done in Python" was to explain "I want
to change where warnings are redirected to."   This is not the same as
asking "If I want some type of user warnings to be handled differently,
then how do I do that?"

You seem to be asking what the equivalent of warn() is (which needs to
be called explicitly in the user code).  And there is no equivalent of
the warn function.  Considering that warn does not do anything except
write to stderr (by default), there is NO difference between that and
writing to sys.stderr in Python.  And if you place a handler in
$SIG{__WARN__}, it is no different than creating a callable object
and placing it in the shared module, like thus:

class Debug:
  from string import join
  output = sys.stderr
  switch = 0  # no debug by default
  def on(self):  self.switch = 1
  def off(self): self.switch = 0
  def __call__(self, *args):
    self.output.write(self.join(map(str, args))+'\n')
    self.output.flush()
import __builtin__
__builtin__.warn = Debug(); warn.on()

And then calling the now-global warn() method in whatever module you
wish.  And the __call__ method can be replaced:
   warn.__call__ = lambda self, *args: warn.list.append(args)
exactly as __WARN__ can be OR the output can be redirected by changing
warn.output.  But both this and the $SIG{__WARN__} handler are user
code - no difference, semantically.

There is no warn() function in Python because it probably wasn't worth
putting on in, just like it wasn't worth putting "die" in.  Python can
handle the exceptions itself.

But (and this is promoted in the Perl world as well), it is bad style
to go into __builtin__ and CORE (which means that use of __WARN__ might
not be something that should be condoned).

:        It is however, still nothing close to a $SIG{__WARN__} handler for
:        warn().  A warn() (and die() for that matter (ie $SIG{__DIE__})
:        handler is very much like a normal OO exception handler (eg, a Java
:        catch{} or Python except block), with the *extra* ability to
:        *return* from the exception handler to the location where warn() or
:        die() was called.  This is why it is handled by a %SIG handler, as
:        it is an asynchronous and arbitrary handler with the same
:        functionality, form, and power of a sigaction() handler.

How is warn() ANYTHING like an exception handler?  The manpage
(perlfunc) for Perl 5.004_4 states (since Perl 5.005 is a development
release, it is unavailable for comment in these debates, just as Python
1.5.2):

perlfunc(1)
  warn LIST
          Produces a message on STDERR just like die(), but
          doesn't exit or throw an exception.

          No message is printed if there is a $SIG{__WARN__}
          handler installed.  It is the handler's
          responsibility to deal with the message as it sees
          fit (like, for instance, converting it into a
          die()).  Most handlers must therefore make
          arrangements to actually display the warnings that
          they are not prepared to deal with, by calling
          warn() again in the handler.  Note that this is
          quite safe and will not produce an endless loop,
          since __WARN__ hooks are not called from inside one.

          You will find this behavior is slightly different
          from that of $SIG{__DIE__} handlers (which don't
          suppress the error text, but can instead call die()
          again to change it).

perlvar(1)
  $@      The Perl syntax error message from the last eval()
          command.  If null, the last eval() parsed and
          executed correctly (although the operations you
          invoked may have failed in the normal fashion).
          (Mnemonic: Where was the syntax error "at"?)

          Note that warning messages are not collected in this
          variable.  You can, however, set up a routine to
          process warnings by setting $SIG{__WARN__} as
          described below.
 ...
          Certain internal hooks can be also set using the
          %SIG hash.  The routine indicated by $SIG{__WARN__}
          is called when a warning message is about to be
          printed.  The warning message is passed as the first
          argument.  The presence of a __WARN__ hook causes
          the ordinary printing of warnings to STDERR to be
          suppressed.  You can use this to save warnings in a
          variable, or turn warnings into fatal errors, like
          this:
              local $SIG{__WARN__} = sub { die $_[0] };
              eval $proggie;

It does not throw an exception, so how can it be equated to raising
one? (unless the warn handler then uses die).  Warn is called
explicitly in the user code, so it is again unlike Java or Python
built-in exceptions.  The documentation also implies that it is not
asynchronous, otherwise the "sub {die...}" solution wouldn't work
correctly within that eval.

But the asynchronous handling could be done in threads if you needed
it.  That seems like a poorly designed application to me, especially
since there are packages like syslog() to handle that for you.

:        So we ask again, the equivalent Python code would be what, exactly?

Thankfully, there isn't an equivalent to warn... I never needed warn in
four+ years of perl programming.  But maybe you should redefine what you
are asking for.

  -Arcege



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

Date: 4 Nov 1998 21:15:58 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Not to start a language war but..
Message-Id: <71qg6e$m31$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, "Michael P. Reilly" <arcege@shore.net> writes:

I agree with virtually everything you've said, but this tiny
part is simply not the case:

:The manpage (perlfunc) for Perl 5.004_4 states (since Perl 5.005 is a
:development release, it is unavailable for comment in these debates,
:just as Python 1.5.2):

Perl 5.005 is certainly not in beta.  The 5.005_02 release
is a bug-fixing/update/maintenance release for 5.005; but
the 5.005_53 version is indeed the development/experimental release.

--tom
-- 
Let us be charitable, and call it a misleading feature  :-)
        --Larry Wall in <2609@jato.Jpl.Nasa.Gov>


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

Date: Fri, 30 Oct 1998 18:28:15 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Not to start a language war but..
Message-Id: <8cyapxq4zu.fsf@gadget.cscaper.com>

>>>>> "Dave" == Dave Kirby <dkirby@see.sig.for.addr> writes:

Dave> to me this is somewhat more complex and less readable than

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

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

Then add this:

	sub UNIVERSAL::new {
		my $class = shift;
		my $self = bless { @_ }, $class;
		$self->initialize();
		$self;
	}

	sub UNIVERSAL::initialize { }

Then to have your Foo class, you write (only):

	sub Foo::initialize { "do whatever" }

This is not the default, but it can be YOUR default.  I may not want
all my constructors to be called new, or objects created from hashes.
Perl's more flexible than that.

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Wed, 4 Nov 1998 16:38:08 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: PERL manual - html
Message-Id: <g0lq17.n6g.ln@flash.net>

John Hardy (jhardy@cins.com) wrote:

: http://www.perl.com/CPAN-local/doc/manual/html/pod/perltoc.html

: is there a place that you can "keyword search" through the above HTML document?

   Yes.

   Most browsers have some way to do a keyword search builtin.

   Consult the docs for your browser.



   But a much better approach would be to find the pod/ directory
   (look for it in the directories listed by 'perl -V').

   Then you can search all of the docs at once:

      perl -ne 'print if /my_keyword_here/i' /usr/lib/perl5/pod/*.pod


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 4 Nov 1998 15:52:30 -0600
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: perl5 make fails
Message-Id: <71qiau$sv0@fohnix.metronet.com>

buckyjune@my-dejanews.com writes:
[...]
) 	sh Configure -Dprefix=/services/www/htdocs/srs/perl
[...]
) (Current working directory is /services/www/htdocs/srs/perl) ---
) % make

Don't try to install Perl into the same directory where you are
building it.  I'd probably delete everything, create
htdocs/srs/perl/src and unpack the Perl distribution into there
and start over installing to htdocs/srs/perl.
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

Date: 4 Nov 1998 21:29:44 GMT
From: ecki@lina.inka.de
Subject: Re: Raw socket programming in Perl
Message-Id: <71qh08$9li$2@sapa.inka.de>

In comp.security.unix Marquis de Carvdawg <carvdawg@patriot.net> wrote:
> Thanks for pointing out a spelling error.  However, the same problem persists...
> the script runs fine, but a NetXRay capture reveals that an IP packet, vice TCP,
> is sent.  All of the values read from the packet capture have nothing to do with
> what was included in the script when the packet was constructed...
Network byte order?

Greetings
Bernd


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

Date: 4 Nov 1998 22:10:57 GMT
From: m.adam@libr.canterbury.ac.nz
Subject: Sending a file to a printer
Message-Id: <71qjdh$5m2$1@cantuc.canterbury.ac.nz>

I feel that this is an embarassingly obvious question but I've searched all my
documentation and read all the FAQs I can find without getting an answer.

I am writing perl scripts on Windows NT.  I need to send a file to a printer: 
\\NTServer\printer1.  How do I do this?

Margaret


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

Date: Wed, 4 Nov 1998 16:28:07 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: seperating paragraphs (kind of like $/)
Message-Id: <ndkq17.f5g.ln@flash.net>

rhaig@news.hackboy.com wrote:
: ok, here is the format of the input I'll be dealing with:
: ================
: user1:
: attr1=val1
: attr2=val2
: attr3=val3
: user2:
: attr1=val1
: attr2=val2
: attr3=val3
: ================
: so they're not really paragraphs.  If I set $/ to "\w+:", then I get 3 input
: records from the above input:
: =============
: user1:
: ===========
: attr1=val1
: attr2=val2
: attr3=val3
: user2:
: ===========
: attr1=val1
: attr2=val2
: attr3=val3
: ================


   Sounds like you have found a bug in perl.

   Or you aren't giving us the whole story.

      $/ = "\w+:";  # set the input record separator to a 3 character string

   You should get 1 record, since your file does not have a 'w' followed
   by a plus, followed by a colon...

   And:

      "Remember: the value of $/ is a string, not a regexp."

   But you surely already read that in the description of the $/
   variable that you are having trouble with.


: what I really want is 2 records with the user at the top of each set
: of attributes (yes, I'm dealing with AIX if you haven't guessed it by now)


: any ideas?

------------------------------------
#!/usr/bin/perl -w

$record='';

while (<DATA>) {
   if ( (/^user\d+:/ || eof) && $record ) {
      print "===========\n$record===========\n";

      $record = $_;
   }
   else {
      $record .= $_;
   }
}

__DATA__
user1:
attr1=val1
attr2=val2
attr3=val3
user2:
attr1=val1
attr2=val2
attr3=val3
------------------------------------


: (rtfm is acceptable, if you point me to the right section of the fm)

   'perlvar' describes perl's special variables, such as $/,
   which doesn't help with what you are currently trying to do.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 4 Nov 1998 13:50:39 -0800
From: Colin Kuskie <ckuskie@cadence.com>
To: rhaig@news.hackboy.com
Subject: Re: seperating paragraphs (kind of like $/)
Message-Id: <Pine.GSO.3.96.981104131913.20872B-100000@pdxue150.cadence.com>


<Also emailed to rhaig>

On 4 Nov 1998 rhaig@news.hackboy.com wrote:

> ok, here is the format of the input I'll be dealing with:
> ================
> user1:
> attr1=val1
> attr2=val2
> attr3=val3
> user2:
> attr1=val1
> attr2=val2
> attr3=val3
> ================
>
> what I really want is 2 records with the user at the top of each set
> of attributes (yes, I'm dealing with AIX if you haven't guessed it by now)

I'm not sure that playing with $/ is going to help you much.  I think
you have a few options:

1)If each user record is guaranteed to have the same number of lines
then just read that many lines:

  while (<>) {
    redo if $a++ < 4 and $_ .= <>;
    ##Process your multiline input
    $a = 0;
  }

2) If the number of lines is variable then you could try:

  undef $/;
  $_ = <>;
  s/\nuser/\n\nuser/sg;    ##Insert a token between the records
  @data = split /\n\n/, $_;##Split on the token.

2a) Or, slightly differently:

  undef $/;
  $_ = <>;
  ($empty_record, %hash) = split /(user\d+:)/;
  ##Using parens in a split causes split to return the delimiters, too!
  ##You now have the user records available in a hash!
  ##Use "keys" to iterate over the different key/value pairs.

Good luck,
Colin Kuskie



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

Date: Wed, 04 Nov 1998 22:59:09 GMT
From: tnguru@termnetinc.com (Ben Coleman)
Subject: Re: Why is perl better than shell scripting language?
Message-Id: <3640db8f.597955344@news.mindspring.com>

On Mon, 02 Nov 1998 11:55:24 -0500, John Porter <jdporter@min.net> wrote:

>Kevin Reid wrote:
>> John Porter <jdporter@min.net> wrote:
>> > let me tell you about another language that starts with P.
>> What language?
>Pascal?  Prolog?  PL/1?  PostScript?  Pilot?

I think he meant to limit it to those(like Python and Promal) where special
attention to spaces in source code is needed(in Promal, indentation is used
to delimit code blocks).

Ben
-- 
Ben Coleman
Senior Systems Analyst
TermNet Merchant Services, Inc.
Atlanta, GA


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

Date: Wed, 04 Nov 1998 22:34:09 GMT
From: java@josho.net
Subject: win32::ole docs--where?
Message-Id: <71qkp1$413$1@nnrp1.dejanews.com>

Hi,

Can anyone tell me where I can find some decent, thorough documentation on
Win32::OLE?

Thanks in advance,

-Josh
java@josho.net

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


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

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

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