[10125] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3718 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 15 09:08:15 1998

Date: Tue, 15 Sep 98 06:00:18 -0700
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, 15 Sep 1998     Volume: 8 Number: 3718

Today's topics:
        [Perl] How to find the Perl FAQ <rootbeer&pfaq*finding*@redcat.com>
    Re: C++ extensions nickgl@my-dejanews.com
    Re: Comments on my Code? <rra@stanford.edu>
    Re: Determine NT Logon Server? (Markus Geish|ttner)
    Re: Edit in place problem with ActivePerl 5.005_002 dave@mag-sol.com
    Re: finding out yesterdays date <sam@peritas.com>
        Getting multiple scripts to read same configuration fil (Jauder Ho)
    Re: HTTP-Proxy written in Perl - Possible? How? <duff@duffduff.com>
        Installation help ! <panciera@sodalia.it>
    Re: Is it better to use one big script that can do 5 ta (I.J. Garlick)
        ISAM access (Thomas Weller)
    Re: milliseconds? miho21@yahoo.com
        multiple buttons (Tri Tram)
    Re: multiple buttons (David A. Black)
    Re: NT Login Script via PERL? <sneaker@sneex.fccj.org>
        online library of regexps ? <pardh001@tc.umn.edu>
    Re: Perl & Java - differences and uses <webmaster@fccjmail.fccj.cc.fl.us>
    Re: Perl & Java - differences and uses <borg@imaginary.com>
        reading float and integers form binary file <Christian.Zwach@nho.hydro.com>
        script: scriptMangle! (Jauder Ho)
    Re: Searching a File for String <ajohnson@gpu.srv.ualberta.ca>
    Re: Sending E-mail from Prel CGI in on NT4 dejaffa@my-dejanews.com
    Re: Web Chat <mlopez@greenbit.es>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Tue, 15 Sep 1998 10:24:02 GMT
From: Tom Phoenix <rootbeer&pfaq*finding*@redcat.com>
Subject: [Perl] How to find the Perl FAQ
Message-Id: <pfaqmessage905855042.5654@news.teleport.com>

Archive-name: perl-faq/finding-perl-faq
Posting-Frequency: weekly
Last-modified: 10 Sep 1998

[ That "Last-modified:" date above refers to this document, not to the
Perl FAQ itself! The last major update of the Perl FAQ was in Summer of
1998; of course, ongoing updates are made as needed. ]

For most people, this URL should be all you need in order to find Perl's
Frequently Asked Questions (and answers).

    http://cpan.perl.org/doc/FAQs/

Please look over (but never overlook!) the FAQ and related docs before
posting anything to the comp.lang.perl.* family of newsgroups.

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

Beginning with Perl version 5.004, the Perl distribution itself includes
the Perl FAQ. If everything is pro-Perl-y installed on your system, the
FAQ will be stored alongside the rest of Perl's documentation, and one
of these commands (or your local equivalents) should let you read the FAQ.

    perldoc perlfaq
    man perlfaq

If a recent version of Perl is not properly installed on your system,
you should ask your system administrator or local expert to help. If you
find that a recent Perl distribution is lacking the FAQ or other important
documentation, be sure to complain to that distribution's author.

If you have a web connection, the first and foremost source for all things
Perl, including the FAQ, is the Comprehensive Perl Archive Network (CPAN).
CPAN also includes the Perl source code, pre-compiled binaries for many
platforms, and a large collection of freely usable modules, among its
560_986_526 bytes (give or take a little) of super-cool (give or take
a little) Perl resources.

    http://cpan.perl.org/
    http://www.perl.com/CPAN/
    http://cpan.perl.org/doc/FAQs/FAQ/html/
    http://www.perl.com/CPAN/doc/FAQs/FAQ/html/

You may wish or need to access CPAN via anonymous FTP. (Within CPAN,
you will find the FAQ in the /doc/FAQs/FAQ directory. If none of these
selected FTP sites is especially good for you, a full list of CPAN sites
is in the SITES file within CPAN.)

    California     ftp://ftp.cdrom.com/pub/perl/CPAN/
    Texas          ftp://ftp.metronet.com/pub/perl/
    South Africa   ftp://ftp.is.co.za/programming/perl/CPAN/
    Japan          ftp://ftp.dti.ad.jp/pub/lang/CPAN/
    Australia      ftp://cpan.topend.com.au/pub/CPAN/
    Netherlands    ftp://ftp.cs.ruu.nl/pub/PERL/CPAN/
    Switzerland    ftp://sunsite.cnlab-switch.ch/mirror/CPAN/
    Chile          ftp://ftp.ing.puc.cl/pub/unix/perl/CPAN/

If you have no connection to the Internet at all (so sad!) you may wish
to purchase one of the commercial Perl distributions on CD-Rom or other
media. Your local bookstore should be able to help you to find one.
Another possibility is to use one of the FTP-via-email services; for
more information on doing that, send mail to <mail-server@rtfm.mit.edu>
(not to me!) with these lines in the body of the message, flush left:

    setdir usenet-by-group/news.announce.newusers
    send Anonymous_FTP:_Frequently_Asked_Questions_(FAQ)_List

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

Comments and suggestions on the contents of this document
are always welcome. Please send them to the author at
<pfaq&finding*comments*@redcat.com>. Of course, comments on
the docs and FAQs mentioned here should go to their respective
maintainers.

Have fun with Perl!

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


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

Date: Tue, 15 Sep 1998 12:29:08 GMT
From: nickgl@my-dejanews.com
Subject: Re: C++ extensions
Message-Id: <6tlmij$p3o$1@nnrp1.dejanews.com>

In article <m367es72os.fsf@glencros.demon.co.uk>,
  Nick Glencross <nickg@glencros.demon.co.uk> wrote:
> I've had a Perl extension written in C++ statically linked (it was on
> a platform on which gcc didn't support shared libs) with Perl and it
> has worked very well. I now have Linux and want it dynamically loaded.
>
> Unfortunately it core dumps whenever a call to a stream (including a
> newly created one) is made. My hunch over the last few days has been
> that there is a static object or buffer which doesn't initialise since
> the top-level file doesn't do it's C++ startup. I've tried to study
> the source for libg++ but I can't find good reason for it.
>

Right, I've done what I reasoned I might need to do and linked libg++ again
the perl main (which I can do even without the source distribution). It still
crashed, but removing -lc did the business.

I now have things working as required. Thanks all!

Nick

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 15 Sep 1998 00:50:24 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Comments on my Code?
Message-Id: <ylogsholvj.fsf@windlord.stanford.edu>

Scratchie <upsetter@ziplink.net> writes:

> The business has a bunch of business contacts that are being stored in a
> custom-built intranet (not Perl) app. We needed to send out a form
> letter to ~50-60 of them. These are people who we already have a
> business relationship with, so it's not spam. However, we're unlikely to
> want to send out more than a few of these mass-mailings a year, so it's
> really not worth setting up a full-featured mailing list manager like
> majordomo.  Since the names and addresses are being stored in a non-perl
> app that I didn't write, the easiest thing to do was to export a list of
> email addresses into a text file and run it through my mailgun app.
> This may have not been the most elegant solution, but seemed to be the
> quickest and most practical for our purposes.

        export_addrs /some/database/somewhere > /etc/mail/addrs.txt
        echo "outgoing: :include:/etc/mail/addrs.txt" >> /etc/aliases
        echo "owner-outgoing: root" >> /etc/aliases
        newaliases
        /usr/lib/sendmail -oi -oem outgoing < form_letter

Then delete the aliases again and rerun newaliases.  sendmail takes care
of the rest for you.

Perl was overkill, in my opinion.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Tue, 15 Sep 1998 10:19:03 GMT
From: Markus.Geishuettner@Allianz.de (Markus Geish|ttner)
Subject: Re: Determine NT Logon Server?
Message-Id: <35fe3efb.97508409@lspxyp1>


Win32::NetAdmin::GetDomainController( $Server, $Domain, $PDC );

I hope this is what you are searching for.


On Tue, 08 Sep 1998 23:36:07 GMT, mgjv@comdyn.com.au (Martien
Verbruggen) wrote:

>In article <35f5420b.331546843@newshost.unx.sas.com>,
>	snorjb@wnt.sas.com (RonBo) writes:
>> How would I determine the NT Logon Server under Perl?



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

Date: Tue, 15 Sep 1998 08:15:56 GMT
From: dave@mag-sol.com
Subject: Re: Edit in place problem with ActivePerl 5.005_002
Message-Id: <6tl7nq$9pv$1@nnrp1.dejanews.com>

In article <6tjvrv$p4o$1@nnrp1.dejanews.com>,
  benday@c-bridge.com wrote:
> I've used the following command a billion times but never with ActivePerl
> for NT.
>
> perl -p -i.bak -e "s/foo/bar/g;" *.htm
>
> It says "Can't open *.htm: Invalid argument"
>
> I'm baffled.
>
> Does anyone what what I'm doing wrong?

Ben,

This isn't a Perl problem. You're using a shell that doesn't do automatic
wildcard expansion before passing the command line to a program. This is a
*bad* thing.

Use Unix.

hth,

Dave...

--
dave@mag-sol.com
London Perl M[ou]ngers: <http://www.mag-sol.com/London.pm/>

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 15 Sep 1998 09:49:57 +0100
From: Simon Matthews <sam@peritas.com>
To: "Steve ." <syarbrou@ais.net>
Subject: Re: finding out yesterdays date
Message-Id: <35FE2A35.ADC93813@peritas.com>

Steve . wrote:
> 
> I have a system that outputs a comma delimited file and then is passed
> to my linux box.  The first field is the date like 09/14/98.  The date
> is actually the next days date since it passes the data at midnight.
> The program has to do this because that's how it works so I can't set
> it to send at 11:59.  I want to be able to reset the dates that are
> sent to one day less.  Is there somthing to do this?  So if the date
> is stamped 09/14/98 I want it to be 09/13/98.  Thanks.
> 
> Steve


I find Date::Manip most usefull for processing dates and Date Deltas

Hope this helps

SAM


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

Date: 15 Sep 1998 09:11:04 GMT
From: jauderho@transmeta.com (Jauder Ho)
Subject: Getting multiple scripts to read same configuration file
Message-Id: <6tlav8$sp0$1@palladium.transmeta.com>

I have a slight dilemma trying to figure out the best way to get multiple 
scripts to read from the same configuration file no matter where they are run
from. Might be impossible but what the heck I'll ask for suggestions.

I have a dir let's call it /var/foo and in /var/foo are the subdirs bin, etc
and tools. now what I want to be able to do is to keep the bar.conf file in
etc where all changes are edited. However I have scripts in bin/ and tools/
that depend on ../etc/bar.conf and I need a way to make them automagically
figure out where they are being called from and read the conf file accordingly
right now it's all hardcoded in which kinda defeats the purpose of having a
conf file in the first place. 

Secondly, formatting of the conf file, should I actually write something to
extract the variables to be set or should I be lazy, do a bad thing and just
using require have stuff like

$ENV{PATH} =            "/bin:/usr/bin";
$date =                 `/bin/date '+%m-%d-%y.%H:%M:%S'`;
$etcdir =               "/etc";

just pre defined and ready to go? Suggestions/solutions urgently needed.
Can't decide what do about this... Thanks

--Jauder



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

Date: Tue, 15 Sep 1998 11:55:12 +0100
From: "Gary Mc Closkey" <duff@duffduff.com>
Subject: Re: HTTP-Proxy written in Perl - Possible? How?
Message-Id: <6tlh4t$ift$1@ezekiel.eunet.ie>

Yes - see other answers.
As an alternative, try the Xitami web server, free, OpenSource, multiple
platform, easy to use, small footprint.

See  http://www.imatix.com/   . I  have no connection, apart from being a
very happy user.

Gary

--
NOTICE TO BULK E-MAILERS: Pursuant to US Code, Title 47, Chapter 5,
Subchapter
II, 227, and all unsolicited commercial e-mail sent to this address is
subject
to a download and archival fee in the amount of $500 US.

A. Beckmann wrote in message <35FD8015.FF96B459@gmx.de>...
>I need an own HTTP Proxy in some different Unix
>machines. Is it easily possible with Perl?
[snip details of request]



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

Date: Tue, 15 Sep 1998 11:50:30 +0200
From: Oscar Panciera <panciera@sodalia.it>
Subject: Installation help !
Message-Id: <35FE3866.51E0@sodalia.it>

I have got some problem during installation of perl 5.00404 on hpux.
Test 102 fail but I dont know how I can solve it !

I try to find "exec,``,system" command and the values of LC_ALL ecc.
but without success 


	--thanks for help


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

Date: Tue, 15 Sep 1998 08:26:03 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
Subject: Re: Is it better to use one big script that can do 5 tasks or 5 smaller scripts for each task?
Message-Id: <EzBGrF.33u@csc.liv.ac.uk>

In article <905783991.17802@thrush.omix.com>,
Zenin <zenin@bawdycaste.org> writes:
> I.J. Garlick <ijg@csc.liv.ac.uk> wrote:
[snipped]
>: I think Form.pm pulls in (uses) other modules that are built in to CGI.pm,
>: since each new package needs to be interpreted and then compiled, this takes
>: longer as each file/package must be found and read in. CGI.pm however is
>: found once and read in.
> 
>         It's more magical then that.  CGI.pm uses a non-standard, but very
>         quick, autoload system.  Very little is actually compiled unless you
>         use it.  Unlike the more standard systems, CGI.pm's autoloader never
>         requires multiple file reads or the "all or nothing" __END__ system.
>         It's pretty slick, if funky to look at. :-)

As I said, I did suspect it was more complicated than that. I think I have
looked into the bowels of CGI.pm once or twice to try and confirm my
suspicions but ran quickly decided that if it worked leave it to get on with
it.  I'll get back to it when I have learnt enough Perl to consider my self
no longer a newbie. Probably in about 2 years the way things look now :-)

Any way thanks Zenin, I now know a little more about why CGI.pm loads faster,
enough to convince me not to use Form.pm etc... unless there is an extremely
good reason for it.

-- 
--
Ian J. Garlick
ijg@csc.liv.ac.uk

You probably wouldn't worry about what people think of you if you could
know how seldom they do.
                -- Olin Miller.



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

Date: 15 Sep 1998 12:08:48 GMT
From: 101.34191@germanynet.de (Thomas Weller)
Subject: ISAM access
Message-Id: <6tllcg$9s0$1@newshost.germany.net>

Hello,

does anybody have a script to access - or even better, convert into anthing else - ISAM (Cobol) files??

Thanks in advance!!

Thomas Weller
101.34191@germany.net








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

Date: Tue, 15 Sep 1998 11:59:29 GMT
From: miho21@yahoo.com
Subject: Re: milliseconds?
Message-Id: <6tlkr1$n20$1@nnrp1.dejanews.com>

Huh? can anyone explain that please? what does qw has to do with anything???
qw is a built in function? how come i never heard of it?

anyway, you can use the win32::Timer module to do just that.


mihoko.

In article <6t04c3$8fi$1@sunnews.cern.ch>,
  ddurand@hpplus14.cern.ch (Jean-Damien Durand) wrote:
>
>   An also in `man perlfaq8`, "How can I measure time under a second?".
>
> > > How do get the milliseconds unit of current time using Perl?
> > >
> > > Joe Petrow
> > > poyopoyo@gol.com
> >
> > use builtin qw(clock);
>
>   Cheers,                              Jean-Damien.
> --
>        *******************************************************
>        *   Jean-Damien Durand (Jean-Damien.Durand@cern.ch)   *
>        *        www : http://wwwinfo.cern.ch/~ddurand/       *
>        *******************************************************
>

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 15 Sep 1998 07:48:56 GMT
From: tram@olympic.seas.ucla.edu (Tri Tram)
Subject: multiple buttons
Message-Id: <EzBF1K.CxM@seas.ucla.edu>


sub f1
{
  print "you came from sub*"
  print button to call f1
  print button to call f2
  print button to call f3
}
sub f2
{
  print "you came from sub*"
  print button to call f1
  print button to call f2
  print button to call f3
}
sub f3
{
  print "you came from sub*"
  print button to call f1
  print button to call f2
  print button to call f3
}

Thanks.

--
-----------------------------------------------------------------
Tri Tram, Computer Science and Engineering at UCLA
http://www.seas.ucla.edu/~tram


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

Date: Tue, 15 Sep 1998 06:57:02 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: multiple buttons
Message-Id: <6tlh5u$1b8$1@earth.superlink.net>

tram@olympic.seas.ucla.edu (Tri Tram) writes:


>sub f1
>{
>  print "you came from sub*"
>  print button to call f1
>  print button to call f2
>  print button to call f3
>}
>sub f2
>{
>  print "you came from sub*"
>  print button to call f1
>  print button to call f2
>  print button to call f3
>}
>sub f3
>{
>  print "you came from sub*"
>  print button to call f1
>  print button to call f2
>  print button to call f3
>}

>Thanks.


No, no - thank *you*.


David Black
dblack@saturn.superlink.net


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

Date: Tue, 15 Sep 1998 05:43:53 -0400
From: Bill 'Sneex' Jones <sneaker@sneex.fccj.org>
To: snorjb@unx.sas.com
Subject: Re: NT Login Script via PERL?
Message-Id: <35FE36D9.5AD4D0C7@sneex.fccj.org>

Ronnie Bouchon wrote:
> 
> I'm  working on coding our login script under Windows NT using PERL
> (ActiveState) , and need to know:
> 
> 1)  which DLLs and\or EXEs are needed to be placed in then netlogon
> share for all the clients to use, so they can run this script when
> they log in.
> 
> 2)  If I compile the code, which I've done using PS2EXE from the PRK,
> the compile EXE still is looking for DLLs, and I need to know what
> these are, and where to store them so all the clients have access.
> 
> Thanks.
> Ronnie Bouchon.

What code?  Was it something I wrote?

Since I know next to ZERO about winders, nothing I 
write in Perl should ever work under winders; so, with 
that in mind, I have forwarded your question as appropriate.


Read future follow-ups in comp.lang.perl.misc, follow-ups set.

PS - What I do know about security tells I wouldn't mess with
re-writing the NT Log-in functions with Perl, it isn't safe.

-Sneex- 
__________________________________________________________________
Bill Jones | FCCJ Webmaster | http://webmaster.fccj.org/Webmaster
__________________________________________________________________
We are the CLPM... Lower your standards and surrender your code...
We will add your biological and technological distinctiveness to 
our own... Your thoughts will adapt to service us...
 ...Resistance is futile...


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

Date: Tue, 15 Sep 1998 03:43:06 -0500
From: Sameer Pardhy <pardh001@tc.umn.edu>
Subject: online library of regexps ?
Message-Id: <35FE289A.12EE@tc.umn.edu>

Hi !
	Is there any web page where I can lookup standard regexps for
1. extracting function prototypes from C files
2. extracting web addresses from text files

and so on?

I am a new to Perl and looking at the regexps scares me! I need to
study  some tested expressions and fiddle with them.

Thank you for any suggestions,

Sameer.


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

Date: Tue, 15 Sep 1998 06:40:16 -0400
From: "Bill Jones, FCCJ Webmaster" <webmaster@fccjmail.fccj.cc.fl.us>
Subject: Re: Perl & Java - differences and uses
Message-Id: <35FE4410.BB8D998C@fccjmail.fccj.cc.fl.us>

Abigail wrote:
> 
> ++ You overestimate perl's pervasiveness.  Perl's evolution 
> ++ beyond system
> ++ administration is an accident of being in the right place 
> ++ at the right
> ++ time.  It is also an accident that is being rectified.
> 
> By you and which army?
> 

[Reformatted by Sneex]

I agree with Abigail, why rectify something 
that isn't broken???

Why do these long threads perpetuate?

-Sneex-  :]
__________________________________________________________________
Bill Jones FCCJ Webmaster | http://www.fccj.org/cgi/mail?webmaster
__________________________________________________________________
We are the CLPM... Lower your standards and surrender your code...
We will add your biological and technological distinctiveness to 
our own... Your thoughts will adapt to service us...
 ...Resistance is futile...


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

Date: Tue, 15 Sep 1998 12:48:54 GMT
From: George Reese <borg@imaginary.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <WmtL1.1734$E9.5965190@ptah.visi.com>

In comp.lang.java.programmer Felix S. Gallo <fsg@newsguy.com> wrote:
: The indefatigable George Reese writes:
:>Freedom has no place in programming.  Period.

: Here we discover the crux of the problem: George Reese
: believes that hilariously nonsensical dogma, stated in an
: authoritative way, is a feasible substitute for a forebrain.

[ad hominem diatribe deleted]

It seems my claim that freedom has no place in programming has really
struck a nerve with several perl programmers.  This one went on to
talk about all the places where freedom does belong and then attribute
to me the belief that because I want freedom gone from programming,
that I want it gone from all aspects of life.

ROFL

-- 
George Reese (borg@imaginary.com)       http://www.imaginary.com/~borg
PGP Key: http://www.imaginary.com/servlet/Finger?user=borg&verbose=yes
   "Keep Ted Turner and his goddamned Crayolas away from my movie."
			    -Orson Welles


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

Date: Tue, 15 Sep 1998 12:58:05 +0200
From: Christian <Christian.Zwach@nho.hydro.com>
Subject: reading float and integers form binary file
Message-Id: <35FE483D.8579CC3@nho.hydro.com>

Hi,
has anyone a quick description of how to read a (UNIX) binary file with
Perl5?
Is it best to read a big binary file as one into memory and split it
afterwards?
My files include both integers and floats (first 2 int's: byte 12 and
15, then floats: byte 24 to EOF).
So I cannot unpack them as either integer or floats right away...

I tried getc(), which seems rather slow, and read(), but it didn't work.

Any help?
Christian



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

Date: 15 Sep 1998 09:18:42 GMT
From: jauderho@transmeta.com (Jauder Ho)
Subject: script: scriptMangle!
Message-Id: <6tlbdi$t1f$1@palladium.transmeta.com>


something I wrote a long time ago. it almost works, the last I remmeber is
that it didn't handle print statements all that well. Hopefully someone will
take this and fix it up. Just a little exmaple of what too much time on your
hands can do to you...

---<snip>---

#!/usr/bin/perl -wT
# 
# scriptMangle
#
# This will hopefully render a perl script mostly unreadable so
# that others can't easily steal your code.
# 
# Copyright (C) 1997 Jauder Ho
#
# $Id: scriptMangle,v 1.9 1997/07/22 22:52:53 jauderho Exp jauderho $
#
# 052797 jauderho [created]
# 052897 jauderho [hack hack hack]
# 060197 jauderho [rewrote the variable extraction and string parsing code]
# 061397 jauderho [wrote the variable replacement stuff and randomizing]
#		  [functions. subroutines are randomized too]
# 070197 jauderho [need to change s/print\s*(\S)/print $1/; to use lookbehind]
#		  [code to ignore lines with print statements including]
# 		  [multiline prints]
#

#use strict;
use Text::Wrap;

# Declare my subroutines and variables
sub stripComments;
sub stripSpace;
sub subsVars;
sub randString;
sub printOutput;

my @slurp;
my $fileInput;
my $fileOutput;

srand(time ^ ($$ + ($$ << 15)));	# Initialize the rand()

die "Usage: scriptMangle <script>\n" unless ($#ARGV == 0);
$fileInput = $ARGV[0];
chomp($fileInput);
$fileInput =~ /^(\S+)$/;		
$fileOutput = "$1.mangle"; # Untainted!

# Open them files up
open(INPUT,"$fileInput") or die "Cannot open file $fileInput\n"; 
open(OUTPUT,">$fileOutput") or die "Cannot open file $fileOutput\n";

# Get ready to rumble!
for (<INPUT>) {
	chomp();
	push(@slurp,$_);
}

# Make sure that we are mangling a perl script
die "ERROR: $fileInput is not a perl script\n" unless ($slurp[0] =~ /perl/);

# Strip out the fluff
stripComments;
stripSpace; 

subsVars;

# Give it to me, baby!
printOutput;

# Clean up after myself
close(INPUT);
close(OUTPUT);
chmod(0755,$fileOutput) or die "Cannot change permissions for $fileOutput\n";

sub stripComments {
	for (@slurp) {
		next if /^#!.+perl/;	# Save the first line :)
		s/^\s*#.*$//; 
		s/(\{|\||\=|\;)\s*#.*/$1/;
		s/(\w)\s*#.*/$1/;
	}
}

sub stripSpace {
	my $last;
	my $lineCont = 0;
	my @tempArray;

	$tempArray[0] = shift(@slurp);	# Grab the first line

	# Close the gaps as much as possible.
	# The following should take care of most of the spaces, we can try 
	# harder but it is not worth the effort
	for (@slurp) {
		if (/\bprint\b/) {
			s/\t/ /g unless /".*?\t.*"/;
			s/^\s*(?=\S)//;
			s/\s*$//;
			s/print\s*(\S)/print $1/;	# shrink spaces down
			
			$_ = $_ . "\n";
			unless (/print.*\;/) {
				$_ = "\n" . $_;
				$lineCont = 1;
				print;
			}

			push(@tempArray,$_);
			next;
		}

		print "";
		print "";
		print "";
		print "";
		
	
		s/\t/ /g unless /".*?\t.*"/;	# Replace tabs with spaces
		s/^\s*(?=\S)//;			# Suck in the front!
		s/\s*$//;			# Suck in the back!

		if ($lineCont == 1) {
			$_ = $_ . "\n";
			$lineCont = 0 if /\;/;
		}

		next if /^\s*$/;

		push(@tempArray,$_) if /\S/ or !$last;
		$last = /^\s*$/;
	} 
	
	@slurp = @tempArray; # Swap swap swap!
}

sub subsVars {
	my @tempslurp = @slurp;
	my @keyVarArray;
	my @keyArrayArray;
	my @keyAssocArray;
	my @keySubs;
	#my @randRefAssocArray = \qw(randVars randArray randAssoc);
	my %randVars;
	my %randArray;
	my %randAssoc;
	my %randSubs;
	my %seen;
	my %seenSubs;

	# We have to do this for the arrays first.
	for (@tempslurp) {
		my @list;

		s/(\"|\`).*(\"|\`)//g;	# Throw away stuff between quotes
		$_ = $_ . " ";		# Hack to match something like
					# <string>[end-of-line]

		# Now the arrays...
		(@list) = /\@(\w+)(?=\W)/g;
		for (@list) {
			print if /args/;
			next if /^\d+$/;
			next if 
			/^(\_|ARGV$|EXPORT(_OK)$|INC$|ISA$)/;
			push(@keyArrayArray,$_) unless $seen{$_}++;
		}

		# And finally the associative arrays
		(@list) = /\%(\w+)(?=\W)/g;
		for (@list) {
			next if /^\d+$/;
			next if /^(\_|ENV$|SIG$|INC$|OVERLOAD$)/;
			push(@keyAssocArray,$_) unless $seen{$_}++;
		}

		# Pick up subroutine names too
		(@list) = /sub\s+(\w+)\W/g;
		for (@list) {
			push(@keySubs,$_) unless $seenSubs{$_}++;
		}
	}

	# Do this again to extract the just the plain variables
	for (@tempslurp) {
		my @list;

		# Hit me for variable names
		# We want to ignore {} and [] type variables coz they are
		# array references	
		# Use a lookahead to match $var1$var2 situations
		(@list) = /\$(\w+)(?=[^(\w|\{|\[|::)])/g;
		for (@list) {
			next if /^\d+$/;
			next if /^(\_|ARGV$)/;
			push(@keyVarArray,$_) unless $seen{$_}++;
		}
	}

	#print join("\n", @keyVarArray), "\n\n";
	#print join("\n", @keyArrayArray), "\n\n";
	#print join("\n", @keyAssocArray), "\n\n";
		
	#print $#keyVarArray+1, " variables, ", $#keyArrayArray+1, " arrays, ",
	#      $#keyAssocArray+1, " associative arrays\n";

	#print "Variables\n\n";

	for $string (@keyVarArray) {
		my $tempvar;

		$tempvar = randString($string);
		$randVars{$string} = $tempvar;
	#	printf "%-24s$randVars{$string}\n", $string;
	}

	#print "\n";
	#print "Arrays\n\n";

	for $string (@keyArrayArray) {
		my $tempvar;

		$tempvar = randString($string);
		$randArray{$string} = $tempvar;
	#	printf "%-24s$randArray{$string}\n", $string;
	}

	#print "\n";
	#print "Associative Arrays\n\n";

	for $string (@keyAssocArray) {
		my $tempvar;

		$tempvar = randString($string);
		$randAssoc{$string} = $tempvar;
	#	printf "%-24s$randAssoc{$string}\n", $string;
	}
	
	for $string (@keySubs) {
		my $tempvar;

		$tempvar = randString($string);
		$randSubs{$string} = $tempvar;
	}

	# Replace all strings with the new randomized strings
	for (@slurp) {
		my $string; 

		for $string (reverse sort keys %randArray) {
			s/\@$string/\@$randArray{$string}/g;
			s/\$$string\[/\$$randArray{$string}\[/g;
		} 
		
		for $string (reverse sort keys %randAssoc) {
			s/\%$string/\%$randAssoc{$string}/g;
			s/\$$string\{/\$$randAssoc{$string}\{/g;
		}
		
		for $string (reverse sort keys %randVars) {
			s/\$$string/\$$randVars{$string}/g;
		}

		for $string (reverse sort keys %randSubs) {
			s/$string/$randSubs{$string}/g;
		}
	}
}

sub randString {
	($_) = @_;
	my $tempvar = ""; 
	my @temparray;
	
	$_ = crypt($_,(substr $_, 0, 2));	# Crypt the string
	s/\W/1/g;				# Get rid of illegal chars

	# Randomize the variable name!
	(@temparray) = split(/ */,$_);
	while (@temparray) {
		$tempvar .= splice(@temparray, rand @temparray, 1);
	}
	
	# Small recursion to ensure that the original is not the same as the 
	# new randomized variable.
	if ($tempvar eq $_) {
		$tempvar = randString($tempvar);
	}

	$tempvar =~ s/^\d/a/;

	return $tempvar;
}

sub printOutput {
	my $pre = "";
	$Text::Wrap::columns = 80;

	# Print the resulting output in a usable script
#	print OUTPUT shift(@slurp), "\n",
#		     join("\n", @slurp);
#		     wrap($pre,$pre, join(" ",@slurp));

	$slurp[0] = $slurp[0] . "\n";
	$_ = join(" ",@slurp);
	s/\n\s/\n/g;
	print OUTPUT wrap($pre,$pre,$_);
}


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

Date: Tue, 15 Sep 1998 03:33:28 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Searching a File for String
Message-Id: <35FE2658.49BBA077@gpu.srv.ualberta.ca>

Steven McPherson wrote:
!
! Hi all-
! 
! I was wondering if anyone might be willing to give me a suggestion of
! how to open and read and file for a particular string and then
! display what is to the right of the search string.

open a file:
    see: 'perldoc -f open'

read a file:
    see: 'perldoc perlop' (search for I/O Operators)

search for a particular string:
    see: 'perldoc perlre'
    and/or: 'perldoc -f index'

display everything to the right of the search string:
    see: 'perldoc -f print'
    see: 'perldoc -f substr'
    see: 'perldoc perlre'

another good place to start would be with the book "Learning Perl"
from O'Reilly and Associates.

here's one way:

perl -wne "?search_string?&&print$'" filename

regards
andrew


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

Date: Tue, 15 Sep 1998 12:04:54 GMT
From: dejaffa@my-dejanews.com
Subject: Re: Sending E-mail from Prel CGI in on NT4
Message-Id: <6tll57$nde$1@nnrp1.dejanews.com>

The simplest way that I know is a shareware program called blat.

Doug Browne
Sarcom
dbrowne@sarcom.com
  "yair schaffer" <yair_sc@netvision.net.il> may have written:
> Hi,
>
> Does anyone know how to send mail from Perl CGI on NT4 ?

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 15 Sep 1998 10:02:37 +0200
From: Marc Lopez <mlopez@greenbit.es>
Subject: Re: Web Chat
Message-Id: <35FE1F1D.E5C7A2DD@greenbit.es>

Hello Martien!

> > Where I can find a Web-based chat in perl that it allows 30 people to
> > talk and the rest only can read the conversation?

> First of all: If you are looking for software, rather than asking a

> question about perl, you are in the wrong place.

Ups!  Sorry, I thought that it was in the correct group

> That said: You could check out www.cgi-resources.com. They probably
> have something there. Alternatively you could check out www.yahoo.com.

I have already checked in these sites but I have not found anything

Thanks for your help!

Marc Lopez   --  mlopez@greenbit.es



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

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

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