[10204] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3796 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 23 11:08:57 1998

Date: Wed, 23 Sep 98 08:00:21 -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           Wed, 23 Sep 1998     Volume: 8 Number: 3796

Today's topics:
    Re: any way to encrypt my script? <sauvin@osmic.com>
    Re: any way to encrypt my script? (Paul David Fardy)
    Re: Argh! NT Perl (Eisen Chao)
        Array of hashes: a better way? <awrobinson@amoco.com>
    Re: Can't locate any modules <jdw@dev.tivoli.com>
    Re: How to implement (efficiently) an X minute cycle ? <qdtcall@esb.ericsson.se>
    Re: in-place-edit regex substitution in multiple files <jdporter@min.net>
    Re: Learning Perl Advice <jdf@pobox.com>
    Re: Learning Perl Advice (brian d foy)
    Re: Learning Perl Advice (Matt Knecht)
    Re: multi expression unless statement? <qdtcall@esb.ericsson.se>
        ORACLE database access problem (DBI) <m.morrison@mailexcite.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Wed, 23 Sep 1998 09:04:21 -0400
From: Ben Sauvin <sauvin@osmic.com>
Subject: Re: any way to encrypt my script?
Message-Id: <3608F1D5.455A22C0@osmic.com>


    I've told Tom I believed he misread me, and his reaction was "Oh, crap.
Cancel." Such frustration is quite understandable; I am often vexed by my
inability to express myself clearly.

Ronald J Kimball wrote:

> Tom Christiansen <tchrist@mox.perl.com> wrote:
>
> > In comp.lang.perl.misc,
> >     Ben Sauvin <sauvin@osmic.com> writes:
> > :    Nobody who has never written or maintained a compiler, interpreter
> > :or other computer language translator should really be commenting in
> > :this thread.
> >
> > Why's that -- because we're the only ones who know what we're talking
> > about? :-)
>
> Hmm.....  :-)
>
> > More seriously, there is a reason that professional computer scientists
> > go to school for 4-8 years studying and researching these things, and
> > why we have specific words with precise technical meanings.  Telling us
> > we're not allowed to participate is biting the hand that feeds you.
> > Without us, the world would be stuck with nothing more than a bunch of
> > mere [insert Scott Adams accent voice here]  ``IT Professionals''. :-)
>
> Tom, you've got his meaning backwards.
>
> He said 'nobody who has *never* written or maintained, etc.'  An
> unfortunate double negative.  To rephrase, 'Only people who have ever
> written or maintained a compiler, interpreter, or other computer
> language translator should really be commenting in this thread.'
>
> --
>  _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
> ( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
>     /                                  http://www.ziplink.net/~rjk/
>         "It's funny 'cause it's true ... and vice versa."



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

Date: 23 Sep 1998 13:12:14 GMT
From: pdf@morgan.ucs.mun.ca (Paul David Fardy)
Subject: Re: any way to encrypt my script?
Message-Id: <6uas3e$obr$1@coranto.ucs.mun.ca>

Okay, I've failed to make my point.  Let's try one more time.

This thread was about secreting Perl source code.  Doesn't the
digression into implementation as compiler or interpreter miss
that fundamental point?

I included notes from the man pages to show that there is a reasonably
authoritative group that views my /local/bin/perl as an interpreter.
There was no intent (at that point in my article) to make any technical
argument out of this.  I simply meant Unix seems to consider Perl to
be an interpreter.

[ I don't think it's my place to defend the writing of Digital UNIX
  and FreeBSD man pages.  Can you find any man page on execve(2) that
  uses another term?  If you do take issue with it, let me know
  when you've convinced the maintainers of the docs to rewrite the
  relevant text.  -- pdf ]

Turf the terminology: it's not relevant.  An openly readable copy of
the original Perl source is the only persistent form of the program.
That's the central point here.

Indeed, it does not _have_ to be that way.  And, finally, if you
explain how that can be done, you'll at least be going one step closer
to answering the question: is there "any way encrypt my script?"
 ... because we know that what the writer really wants is to protect
the source.  It may not be encryption, but it's closer to what's
desired than distributing the Perl source.

If you just want to argue the semantics of "compiler" vs "interpreter",
how about changing the "Subject:"?

Paul Fardy (japh)


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

Date: 23 Sep 1998 14:34:22 GMT
From: echao@interaccess.com (Eisen Chao)
Subject: Re: Argh! NT Perl
Message-Id: <6ub0te$3qj$1@supernews.com>

I did the same exact thing!!

Did you remember to:

1) include #!<path-to-perl-executable> as your first line ?
2) print "Context-type: text/plain","\n\n";
3) format *ALL* your output as HTML output, and not
   just simple text-to-screen I-O ? Plain text output
   gets interpeted as non-HTML and must then be
   downlaoded, not interperted.

It took me 2-days to notice my error, I'm so dumm...

Eisen

Jeff Riffle (webadmin@bigo.net) wrote:
: I've installed Win32 Perl and PerlScript and Perl for IIS and don't know
: where to go from here, the batch files ran without error and the
: associations are there, the read/execute has been set on the cgi-bin dir
: and the files run from the command line but not from the web, .pl files
: when typed in the browser actually open the prompt box "save file or
: open"
: 
: Would appreciate any help.
: 
: Please cc reply to webadmin@bigo.net
: 


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

Date: Wed, 23 Sep 1998 09:32:22 -0500
From: "Andrew W. Robinson" <awrobinson@amoco.com>
Subject: Array of hashes: a better way?
Message-Id: <36090676.871794DA@amoco.com>

The code I have here works, but I was wondering if there was a
better way. I have a data file that consists of multiline
records, each line consisting of key-value pairs. The keys may
vary between records and some may be missing values. I list an
example below the code.

My question concerns the section where I split the line, test the
number of pieces and assign the hash accordingly. This seems
clumsy. In the spirit of furthering my perl knowledge, is there a
better, more elegant way of extracting the key-value pair from
the line?

Thanks!

Andrew Robinson 
-- 
Offshore Business Unit           email: awrobinson@amoco.com
Amoco Corporation                      phone: (504) 586-6888
New Orleans, LA                          fax: (504) 586-2637
-----
The events depicted herein are fictional. Any similarity to 
persons living or dead is entirely...oops, wrong disclaimer


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

$i = 0;
open FIN, "test.dat" ;
while ( $line = <FIN> ) {
    chomp $line;
    if ( $line =~ /^$/ ) {
        $i++;
        next;
    }
    @items = split /\s*=>\s*/, $line;
    if ( scalar @items == 2 ) {
        ${$records[$i]}{$items[0]} = $items[1];
    } else {
        ${$records[$i]}{$items[0]} = "";
    }
}
close FIN ;

foreach $record ( @records ) {
    foreach $key ( keys %{$record} ) {
        print "$key=>${$record}{$key}; ";
    }
    print "\n";
}

########  data file   ########
eyes => blue
hair => brown
height => 70
weight =>

eyes => brown
hair => blonde
height => 62

eyes => blue
hair => red
weight =>

hair => ash brown
height => 65
weight => 120


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

Date: 23 Sep 1998 07:12:33 -0500
From: Jim Woodgate <jdw@dev.tivoli.com>
Subject: Re: Can't locate any modules
Message-Id: <obg1djyqmm.fsf@alder.dev.tivoli.com>


"Raza Muzaffar" <nospam@nospam.com> writes:
> Can someone please give me some advice or clue as to what possibly can be
> wrong with my perl. I cannot use any perl modules/library. For example when
> I say use File::Find, after compiling I get the error:
> 
> Can't locate the module File::Find etc
> 
> I am unable to use any modules. I have also tried to enter correct path in
> the @INC variable in the program(push(@INC,/my/library/directory) but it
> does not seem to work either.

perldoc -q 'How do I keep my own module/library directory?'

You can't push to @INC, as that would happen at run time, use
directives need to be found at compile time.  Here's the relevant
section of the faq:

"...then either set the PERL5LIB environment variable before you run
scripts that use the modules/libraries (see L<perlrun>) or say

    use lib '/u/mydir/perl';

See Perl's L<lib> for more information.
"

-- 
Jim Woodgate 
Tivoli Systems
E-Mail: jdw@dev.tivoli.com


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

Date: 23 Sep 1998 16:07:59 +0200
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: How to implement (efficiently) an X minute cycle ?
Message-Id: <isaf3q2a80.fsf@godzilla.kiere.ericsson.se>

aharon@deltathree.com (Aharon (Al) Schkolnik) writes:

> while (1)
> 	{set timer to expire in 10 minutes;
> 	 do some stuff;
> 	 wait for timer
> 	}

> Is there a better way ?

while(1)
	{
	 fork();
	 if(in_child)
	    do some stuff;
	    exit;
	 else
	    sleep 600;
	}

 ...perhaps? Provided you're on a platform with an existing and
sufficiently cheap fork(), that is.
-- 
                    Calle Dybedahl, UNIX Sysadmin
       qdtcall@esavionics.se  http://www.lysator.liu.se/~calle/


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

Date: Wed, 23 Sep 1998 09:07:30 -0400
From: John Porter <jdporter@min.net>
Subject: Re: in-place-edit regex substitution in multiple files
Message-Id: <3608F292.9BB5B3B1@min.net>

Dr. Waldmann:

Here is a complete perl program which does exactly what you want.
After that, please read the comments I have made on your code.

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

use File::Find;
use strict;

$/ = undef;

my $start_dir = 'Waldmann';

File::Find::find( \&each_file, $start_dir );

sub each_file {
  if ( -T $_ ) {              # ignore non-Text files
    print "processing $File::Find::name\n";
    if ( open F, "< $_" ) {   # open for reading
      my $s = <F>;            # slurp in the entire file
      close F;
      if ( open F, "> $_" ) { # open again for writing
        # perform the desired substitution globally
        $s =~ s/www(?=\.fire)/samson/g;
        print F $s;           # write out the changed text
        close F;
      }
      else {
        print "Error opening file for write: $!\n";
      }
    }
    else {
      print "Error opening file for read: $!\n";
    }
  }
}


Dr. H.-Christian Waldmann wrote:
> 
> #!/usr/local/bin/perl
> 
> @list=`du /START-DIRECTORY/ | expand | cut -c  9-100`;

In fact, you don't need to spawn external processes to get
the list of directories you want.
You can use the module 'File::Find' to traverse a directory
tree and perform some task on each entry encountered.
This saves a lot of work and is far less error-prone.

>  #   THIS FRAGMENT FITS "HERE" BUT FILE HAS 0 BYTE AFTER THE "CHANGE". MAYBE
>  #   THERES SOMETHING WRONG WITH THE WAY I PERFORM THE "OPEN" OF THE FILE
> 
>  #   open(CHANGE,">$name") || die "no open on $name: $!";
>  #   while (<CHANGE>) {
>  #      s/www\.fire/samson\.fire/g;
>  #   }
>  #   close(CHANGE)         || die "no close on $name: $!";

Notice that you are opening the file for writing.
Whenever you do that, the existing file is wiped out, and you're
"starting from scratch".  Furthermore, you can't expect to
read meaningfully from a file which has been opened for writing.

Since alternately reading and writing the same file is a non-trivially
difficult problem in byte-structured filesystems (such as Unix and NT),
it is better to just read the entire file, change it, and write it
back.

>   #   foreach $line (open(CHANGE,">$name")) {

That is not valid.
open() does not return the contents of the file in any way.

-- 
John "Many Jars" Porter


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

Date: 23 Sep 1998 15:43:54 +0200
From: Jonathan Feinberg <jdf@pobox.com>
To: dcochran@earthlink.net (David Cochran)
Subject: Re: Learning Perl Advice
Message-Id: <m3ogs7ndut.fsf@joshua.panix.com>

dcochran@earthlink.net (David Cochran) writes:

> I am interested in learning perl and was wondering if anyone could
> recommend a good learning source.

It really depends on your learning style. I'll wager that most of the
Perl hackers around learned Perl from the O'Reilly book _Learning
Perl_, which is now in its second edition. If you're an experienced
programmer in general, but are new to Perl, you might consider _PERL
The Programmer's Companion_, by Nigel Chapman, which gets high marks
from one of the principle authors of Perl's documentation.

If you feel like you'll need more guidance, then I'd recommend paying
for training.

You'll find detailed book reviews and other pointers at www.perl.com.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Wed, 23 Sep 1998 10:10:22 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Learning Perl Advice
Message-Id: <comdog-ya02408000R2309981010220001@news.panix.com>
Keywords: from just another new york perl hacker

In article <36087e18.52332034@hermosa>, dcochran@earthlink.net (David Cochran) posted:

>I am interested in learning perl and was wondering if anyone could
>recommend a good learning source.  I was in Fry's today and saw a
>package entitled "The Complete PERL Training Course" by Ellie Quigley.
>Has anyone used this source and if so is it any good.  If it is bad,
>any recommendations on a different source?

Anything that says "Complete" or gives some time span in the title
is most likely trying to cram to much into one book.  Learning Perl [1]
gives one enough skills to do some really cool things, and also gives
one a basis for going on to learn new things.   listed in the "Fine 
Books" section of Camel Critiques [2].

good luck :)

[1]
Learning Perl
Randal L. Schwartz & Tom Christiansen
ISBN 1-56592-284-0 
<URL:http://www.oreilly.com>

[2]
Camel Critiques
<URL:http://language.perl.com/critiques/index.html>

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers needs volunteers! <URL:http://www.pm.org/to-do.html>


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

Date: Wed, 23 Sep 1998 14:08:03 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: Learning Perl Advice
Message-Id: <7h7O1.596$XP2.5036497@news3.voicenet.com>

Jonathan Feinberg <jdf@pobox.com> wrote:
>It really depends on your learning style. I'll wager that most of the
>Perl hackers around learned Perl from the O'Reilly book _Learning
>Perl_, which is now in its second edition.

I'll take that bet.  I'm placing my money on the online docs, with
_Programming_Perl_ as a side companion.

-- 
Matt Knecht - <hex@voicenet.com>


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

Date: 23 Sep 1998 16:01:57 +0200
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: multi expression unless statement?
Message-Id: <isd88n0vxm.fsf@godzilla.kiere.ericsson.se>

"Dan Bassett" <dan@bns.com> writes:

> unless ($in{'fname'} & $in{'lname'} & $in{'pass'} & $in{'page'} eq "1") {
> print "test";
> }

I'm not at all sure that this is what's giving you problems, but I
would put some parantheses in that to make it explicit if I meant

   ($in{'fname'} & $in{'lname'} & $in{'pass'} & $in{'page'}) eq "1"

or

   $in{'fname'} & $in{'lname'} & $in{'pass'} & ($in{'page'} eq "1")

If nothing else, consider the sanity of the poor bastard who'll have
to maintain your code five years from now when you have long ago moved
to greener pa$ture$.
-- 
                    Calle Dybedahl, UNIX Sysadmin
       qdtcall@esavionics.se  http://www.lysator.liu.se/~calle/


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

Date: Wed, 23 Sep 1998 16:52:47 +0200
From: Mike Morrison <m.morrison@mailexcite.com>
Subject: ORACLE database access problem (DBI)
Message-Id: <36090B3F.8029A21D@mailexcite.com>

Hi!

I have a problem with gaining access to an ORACLE database.
The Code look as follows:



#!/usr/local/bin/perl 

use DBI;

#############################
### Setting the variables ###
#############################
$db="aircrews_sts_trg";
$user="user";
$pass="pass";
$query="A";
$query2="";
$field="p.staff_num, p.empl_dt, p.staff_code, c.surname, c.first_name,
c.home_phone_num, c.alt_stby_cnt_num, c.mobile_phone_num, c.fax_no,
c.street, c.post_cd, c.city, b.base, r.rank_cd";
$table="crew_v p, contact_v c, crew_base_v b, crew_rank_v r";
$condition="p.staff_code=c.staff_code and trunc(sysdate) between
trunc(c.eff_dt) and nvl(trunc(c.exp_dt),trunc(sysdate)) and
p.staff_code=b.staff_code and trunc(sysdate) between trunc(b.eff_dt) and
nvl(trunc(b.exp_dt),trunc(sysdate)) and p.staff_code=r.staff_code and
trunc(sysdate) between trunc(r.eff_dt) and
nvl(trunc(r.exp_dt),trunc(sysdate)) and p.staff_code like '$query\%' and
p_surname like '$query2\%'";


### Install the Oracle driver
$drh = DBI->install_driver( 'Oracle' );

### Connect to the database
eval "\$dbh = \$drh->connect( \'$db\', \'$user\', \'$pass\', \'Oracle'\
);";
die "Cannot connect: $DBI::errstr\n" unless $dbh;

### Fetch data out of the database
$cursor = $dbh->prepare( "select $field from $table where $condition" );

$cursor->execute;

while ( $field = $cursor->fetchrow ) {
    print "Field: $field\n";
  }

$cursor->finish;

$dbh->disconnect;

exit;



Whenever I try to execute the Perl script I get the following message:
"Can't call method "execute" without a package or object reference at
ora.pl line 31."                                                  

Can everyone help?
Thanks!

Bye, MM


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

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

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