[6841] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 466 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 13 10:17:19 1997

Date: Tue, 13 May 97 07:00:28 -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, 13 May 1997     Volume: 8 Number: 466

Today's topics:
     [Q] function keys and the Curses module (Bill Mitchell)
     Array of Lists (William D. Reardon)
     Re: Array of Lists <jrs@abiogenesis.com>
     Re: CGI Scripts With MacPerl: How to Handle Multiple Re <B.P.Fowler@rack.demon.co.uk>
     Complex data Structures (SS)
     Re: DB access with Perl <gwhassan@prodigy.net>
     Dumb Perl Question (J. Paul Reed)
     Re: Dumb Perl Question (Abigail)
     Finance Related Scripts <yv50@dial.pipex.com>
     Re: grep pat from multiple files (Honza Pazdziora)
     Re: HELP: Exit code from a CGI-script system call (Lloyd Zusman)
     Re: How do You use perl to Permanently Change a Directo (Abigail)
     Re: I Have a Syntax Problem, Need Help! (Tad McClellan)
     Re: index question (Honza Pazdziora)
     Re: Migration from perl 4 to perl 5 (Raymond Chen)
     More problems with FileHandle (Gene Johannsen)
     Re: More problems with FileHandle (Gene Johannsen)
     Re: need help w/forms and Perl (Geoffrey Hebert)
     Re: New draft of scripting white paper <cimarron@dis.org>
     Re: New draft of scripting white paper <bhouse@dazsi.nospam.com>
     persistent regular expressions (Bill Mitchell)
     Re: persistent regular expressions (Tushar Samant)
     Re: REQ: Perl obfuscator (Paul Marquess)
     Re: Searching NT Network For File ("John Dallman")
     sockets and port 23 <jrs@abiogenesis.com>
     speed up "STDOUT" ? (kim Tan)
     Re: speeding up a regex <owt1@cornell.edu>
     Re: system () won't execute the called program. (SJK)
     Re: system () won't execute the called program. <stephen+usenet@farrell.org>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 11 May 1997 04:20:04 GMT
From: mitchell@leadbelly.math.ufl.edu (Bill Mitchell)
Subject: [Q] function keys and the Curses module
Message-Id: <MITCHELL.97May11002004@leadbelly.math.ufl.edu>


In using the Curses module, how do you read keystrokes so as to
recognize function keys, such as KEY_HOME.  I've been trying to use
&Curses::getch with inconsistent results: sometimes I get the keycode
as in ncurses.h, sometimes I get a escape sequence, and sometimes I
get what seems to be (keycode - 256).  I haven't been able to figure
out in what circumstances I get what.

When posting a reply, please copy to my email address.  I generally
read this group, but it's easy for something to get lost in the
clutter.  
--
    Bill Mitchell
    Dept of Mathematics,        The University of Florida
    PO Box 118105, Gainesville, FL 32611--8105
    mitchell@math.ufl.edu	(352) 392-0281 x284

  


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

Date: Sun, 11 May 1997 07:52:57 GMT
From: wdr1@midway.uchicago.edu (William D. Reardon)
Subject: Array of Lists
Message-Id: <EA0B89.AwC@midway.uchicago.edu>

	I'm trying to create a data structure that is just an array of
lists.  Just to get something to get started, I tried doing something
like this:

for $v (1 .. $vxs) {
	$array[$v] =  (3,2,1) ;	
}

The above, however, just creates an array with each element equal to
1.  What am I doing wrong here?  I read the Lists of Lists thing, but
I'm still stumped.

Thanks,
-Bill


-- 
William Reardon    		 		       wdr1@midway.uchicago.edu
 	      http://student-www.uchicago.edu/users/wdr1/
		     Elegance counts towards credit.



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

Date: Sun, 11 May 1997 03:34:24 -0700
From: "Jonathan R. Seagrave" <jrs@abiogenesis.com>
To: "William D. Reardon" <wdr1@midway.uchicago.edu>
Subject: Re: Array of Lists
Message-Id: <Pine.NXT.3.95q.970511033031.29208B-100000@gandalf>

On Sun, 11 May 1997, William D. Reardon wrote:

> 	I'm trying to create a data structure that is just an array of
> lists.  Just to get something to get started, I tried doing something
> like this:
> 
> for $v (1 .. $vxs) {
> 	$array[$v] =  (3,2,1) ;	
> }
> 
> The above, however, just creates an array with each element equal to
> 1.  What am I doing wrong here?  I read the Lists of Lists thing, but
> I'm still stumped.
> 
> Thanks,
> -Bill

Hi Bill.

You want to do something like this:

my @array = ();
my $v;
for $v (0 .. 5) {
    # push @array, [ (3, 2, 1) ];  I think this is a nice way to do it. 
    $array[$v] = [ (3, 2, 1) ];    # this is closer to what you had.
}

print "@array\n";  # here are the array refs

my $list;
foreach $list (@array) {
    print "\t [ @$list ]";  # here's the whole thing
}

good luck,  Jonathan


Jonathan R Seagrave   <jrs@abiogenesis.com>
pgp public key at     http://www.abiogenesis.com/jrs
                           
The other day I saw a bumper sticker that read "Honk if you passed p-chem".
I honked and the driver flipped me off; I guess he didn't pass!



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

Date: Mon, 12 May 1997 01:02:39 +0000
From: Ben <B.P.Fowler@rack.demon.co.uk>
Subject: Re: CGI Scripts With MacPerl: How to Handle Multiple Requests for the Same Script
Message-Id: <33766BE9.5E7F@rack.demon.co.uk>

stuart wrote:
> 
> I've written a CGI perl script in MacPerl. I need to know how to make
> a Macintosh web server deal with multiple requests for the same perl
> script. Currently the request that gets there first gets executed and
> the second  one gets ignored. I'd thank you for a reply.

I believe that this is the expected behaviour. Many Macintosh 
Web servers follow the Webstar mdoel and send their data in an
AppleEvent.

You need to make a distinction between a .CGI and a .ACGI, and
apply it to your present problem.

I doubt that this is a perl problem, so you may want to take it
to a group where people with Mac infosystem server expertise listen,
such as comp.infosystems.www.servers.mac; or read pages 441 and 442
of Bell & Terell "The Mac Web Server Book".

Ben.


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

Date: 12 May 1997 20:36:29 GMT
From: sscruggs@cucinc.com (SS)
Subject: Complex data Structures
Message-Id: <5l7v0d$fis@news2.widomaker.com>

I am trying to use an array of arrays, and I cannot seem to pull out the 
size of the second array.  
Code would look something like this:
for $towhat ( 0 .. 15 ) {
   for $tohuh (0 ,, 12) {
      $my_array[$towhat][$tohuh] = "Row: $towhat, Column: $tohuh\n";
   }
}
for $counter ( 0 .. (scalar @my_array)) { #This one works;
   for $index (0 .. (scalar @my_array[$counter])) { #But when you try
                              ## to find out how many elements are in
                              ## the array beneath it, it just returns
                              ## the pointer to the array. 
print $my_index[$counter][$index];
}
}

I am fairly new to perl, but I have been able to find answers for all my 
questions up till now. 

Any help would be greatly appreciated...

Thanks, 
	Sam



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

Date: Sun, 11 May 1997 02:45:10 +0000
From: Greg Hassan <gwhassan@prodigy.net>
To: Paul Vermette <prv@beaver.formalsys.ca>
Subject: Re: DB access with Perl
Message-Id: <337532B6.6C392C8D@prodigy.net>

Paul Vermette wrote:
> 
> I am looking for any product that will allow me
> to connect to any database using perl
> 
> I am trying to construct a list of them so that
> I can evaluate them
> 
> Please don't bother mentioning dbPerl or DBI I
> already know about those <g>

You don't like DBI?  I find it fully functional,
I think maybe you should better define what you are looking
for...?

-Greg
-- 
============================================
                Greg Hassan
          The Independent Solution
 Web Developer (CGI, Java, C, Perl, Oracle)
           http://www.hassan.com/        
            gwhassan@prodigy.net
============================================
New:  World-Wide Classified Listings
      (http://www.hassan.com/.classifieds/)
============================================


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

Date: 11 May 1997 03:18:39 GMT
From: preed@psd.k12.co.us (J. Paul Reed)
Subject: Dumb Perl Question
Message-Id: <5l3dqf$hoc$1@mercury.psd.k12.co.us>

Hello perl Wizards:

This is what I'd like to do:

I have an associative array called in (it's from cgi-lib.pl)

I have a bunch of HIDDEN form variables that keep state for the pages.

Everytime the program is run, I want it to automatically collect all the
form variables and then run. So instead of doing it by hand, a foreach
loop would be good, but I can't get it right.

This is what I have now:

foreach (keys %in) {
        $_ = $in{'$_'};
}

Now, I know this doesn't work...

Below is that it's replacing for every variable on the page:

$Username = $in{'Username'};

How do I make a variable name that's a varible; I tried $"$_" and $($_),
but they both didn't work.

Help! :)

Thanks,
Paul
   -----------------------------------------------------------------------
   J. Paul Reed                     preed@psd.k12.co.us || paul@619pro.com
   Borg?!? Sounds Swedish...       --Lily Sloane, Star Trek: First Contact
     Geek Code and various other frivolities at www.psd.k12.co.us/~preed



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

Date: Sun, 11 May 1997 06:05:38 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Dumb Perl Question
Message-Id: <EA069E.2Es@nonexistent.com>

On 11 May 1997 03:18:39 GMT, J. Paul Reed wrote in comp.lang.perl.misc
URL: news:5l3dqf$hoc$1@mercury.psd.k12.co.us:
++ Hello perl Wizards:
++ 
++ This is what I'd like to do:
++ 
++ I have an associative array called in (it's from cgi-lib.pl)
++ 
++ I have a bunch of HIDDEN form variables that keep state for the pages.
++ 
++ Everytime the program is run, I want it to automatically collect all the
++ form variables and then run. So instead of doing it by hand, a foreach
++ loop would be good, but I can't get it right.
++ 
++ This is what I have now:
++ 
++ foreach (keys %in) {
++         $_ = $in{'$_'};
++ }
++ 
++ Now, I know this doesn't work...
++ 
++ Below is that it's replacing for every variable on the page:
++ 
++ $Username = $in{'Username'};
++ 
++ How do I make a variable name that's a varible; I tried $"$_" and $($_),
++ but they both didn't work.


What you want is something like:

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

use vars qw ($foo $bar $baz);        # Keep Perl from complaining :)
$, = ", "; $\ = "\n";
my %a = map {($_ => "${_}_val");} qw (foo bar baz);
foreach (keys %a) {$$_ = $a {$_};}   # Note the $$_
print $foo, $bar, $baz;
__END__

foo_val, bar_val, baz_val


Of course, if you 'use strict;' (which, IMO, you should) this trickery
doesn't work.

However, you can do the same using eval while using strict:

#!/usr/local/bin/perl -w
 
use strict;
use vars qw ($foo $bar $baz);
$, = ", "; $\ = "\n";
my %a = map {($_ => "${_}_val");} qw (foo bar baz);
foreach (keys %a) {eval "\$$_ = \$a {\$_};";}
print $foo, $bar, $baz;
__END__
 
foo_val, bar_val, baz_val



Abigail

REF:
Wall, Christiansen & Schwartz: "Programming Perl, 2n edition" (aka `Camel II')
'Symbolic References', pp 254-255 (Chapter 4).


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

Date: Sun, 11 May 1997 15:13:56 -0700
From: Brian Roberts <yv50@dial.pipex.com>
Subject: Finance Related Scripts
Message-Id: <337644A4.58D7@dial.pipex.com>

Does anyone know of some sites that offer finance related
Perl scripts .

I have a loan amortizer and have modified some other scripts.
I would like to find some based on investment growth -
i.e how much would say $100 per month grow to over x years
at y % interest.

Thanks Brian Roberts yv50@dial.pipex.com



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

Date: Tue, 13 May 1997 11:21:04 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: grep pat from multiple files
Message-Id: <adelton.863522464@aisa.fi.muni.cz>

Query?????? writes:

> Hi,
> 
>     Would appreciate any pointers to the following problem:-
> 
>    I would like to grep a pattern from multiple files. These multiple
>    files are defined in a script as variables with wild-cards(*).
> 
> ###################
>   example:-
> 
>   $listdir="/tmp/searach/dir";
>   $outfile="/tmp/get/file";
> 
>   $greppat=$ARGV[0];
> 
>   ### I want to open all files names ending with "desc" 
>   open (IN , "$listdir/*desc") || die "can't open $listdir to read ($!)\n";
>   open (OUT, ">$outfile") || die "can't open $outfile to write ($!)\n";
> 
>   while <(IN>)
>   {
>     print OUT if /$greppat/;
>   }
> 
> ###################

$listdir="/tmp/searach/dir";
$outfile="/tmp/get/file";
$greppat=$ARGV[0];

open OUR, "> $outfile" or dir "Error writing $outfile: $!\n";
for $file (<$listdir/*desc>)
	{
	open IN, $file or die "Error reading $file: $!\n";
	while (<IN>)
		{
		print OUT if /$greppat/;
		}
	close IN;
	}
close OUT;

__END__

Hope this helps.

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: 13 May 1997 12:20:14 GMT
From: ljz@asfast.com (Lloyd Zusman)
Subject: Re: HELP: Exit code from a CGI-script system call
Message-Id: <slrn5ngmis.oth.ljz@ljz.asfast.net>

On 13 May 1997 11:01:01 GMT, Nikolay Dushev <N.Douchev@iaea.org> wrote:
> Hello all,
> hope someone could has some explanation on this.
> 
> I have the following Perl script:
> 
> ######################################
> #!/usr/local/bin/perl
> print "Content-type: text/html\n\n";
> 
> system("hello");
> $exitcode = $? >> 8;
> print "Exitcode: $exitcode\n";
> ######################################
> 
> "hello" is compiled version of the "Hello world..." C code. 
> 
> If I run this script at the shell prompt the exit status is 0. If I run it from Netscape it 
> returns different exit codes depending on the Perl version used. Perl 5.002 returns 
> 43, Perl 5.002 beta returns 253 and Perl 4 returns 0.
> This happens on:
> IBM SP2 RS/6000
> AIX 4.2
> NCSA HTTPd 1.5.2
> 
> If I do the same on HP-UX 10 or AIX 4 (F40) the result is always correct, ie 0.
> 
> Does anybody have a hint? Any help is gratefully appreciated.

Try it this way:

 #!/usr/local/bin/perl
 print "Content-type: text/html\n\n";
 
 $exitcode = system("hello");
 $exitcode >>= 8;
 print "Exitcode: $exitcode\n";

The 'system' command returns the exit code that was returned by the
invoked command.  The "$?" variable is not mentioned in the 'perlfunc'
documentation for 'system', so you probably should not count on it
containing a meaningful value after 'system' has been called.


-- 
 Lloyd Zusman
 ljz@asfast.com


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

Date: Sun, 11 May 1997 06:12:30 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: How do You use perl to Permanently Change a Directory?
Message-Id: <EA06Ku.2wM@nonexistent.com>

On 11 May 1997 02:31:24 GMT, Kevin M Simonson wrote in
comp.lang.perl.misc URL: news:5l3b1s$4fq@sf18.dseg.ti.com:
++      As you can see below, I'm trying to use the Unix "cd" command inside a
++ "perl" script to change my default directory.  I want to do this because
++ there are a lot of commands I want to execute in the directory I'm "cd"ing
++ to.  However, whether I try to execute the "cd" using the "system ()" com-
++ mand, or within a couple of backtics, the "cd" doesn't appear to take per-
++ manent effect, since the "pwd" afterwards shows I'm still in the directory
++ I started out with.

It's in the FAQ.

<URL:http://www.perl.org/CPAN/doc/manual/html/pod/perlfaq8/I_changed_directory_modified_m.html>



Abigail


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

Date: Sun, 11 May 1997 01:26:20 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: I Have a Syntax Problem, Need Help!
Message-Id: <cqo3l5.074.ln@localhost>

Rick (rwatkins@crosslink.net) wrote:
: I have what I think is a basic syntax problem that I just can't seem to see
: because I looked at it too much.  Can someone take a gander at this short
: Perl Script that just has one subroutine?  I keep getting errors and I
: can't figure out why.  I am using a book called, "CGI Primer Plus for
: Windows" and this is a practical exercise.  Anyway, here is the script:

: #!/usr/local/bin/perl

: exit 0
        ^
        ^  put a semicolon here  ;-)

--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Tue, 13 May 1997 11:52:40 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: index question
Message-Id: <adelton.863524360@aisa.fi.muni.cz>

Allon Henig <ahenig@iil.intel.com> writes:

> Hi I bumped into a very paculier behavior of the index function
> 
> I have the following code:
> 
> $line = "Allon HENIG";
> $word_to_search = "henig"; # notice the lower case 
> $start = index ($line,/$word_to_search/i);
> print $start;
> 
> The out put is $start = 0 (?!?!?!?!?!?!?!)
> I would expect to get 6 or -1 but what the 0 is doing there and how
> can I over come this ?

Hmmm, use index properly. If you used perl -w, you would get

Use of uninitialized value at - line 3.

message. The string /$word_to_search/i is uninicialized and thus
converted to null string (''). And null string can be found and the
zero'th position in you string. You might want to use

$line =~ /^(.*?)$word_to_search/i and the check length of $+.

Hope this helps.

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: Sun, 11 May 1997 07:33:33 GMT
From: raymondc@microsoft.com.--- (Raymond Chen)
Subject: Re: Migration from perl 4 to perl 5
Message-Id: <33776eb2.42080307@157.55.96.156>

One that bit me:

sub get_pop3_response {
  $_ = <S>;
  while (!/^([+-])(.*)/) {
    $_ = <S>;
  }
  ($1, $2);
}

Under perl4, this returned a two element array, the first being
"+" or "-", and the second being the trailer.  Under perl5 this
always returns (undef, undef).

The reason is that perl5 changed the rules on the scope of the $n
variables.  In perl5, they now expire when the enclosing scope is
exited.  In the code above, the loop control is considered to be
part of the loop body, so it goes out of scope once you break the
loop.

--
(My return address is intentionally invalid; delete ".---" to get my real address.)


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

Date: 11 May 1997 09:48:32 GMT
From: gej@spamalot.mfg.sgi.com (Gene Johannsen)
Subject: More problems with FileHandle
Message-Id: <5l44lg$e18$1@murrow.corp.sgi.com>

Hey:

As part of a module I'm writing, I want to return a file handle
when the new function is invoked:

This is how I'm doing it, but it doesn't work:

sub new {
    my $class = shift;
    my $file = shift;

    my $fh = new FileHandle ">>$file";

    return bless \$fh, $class;
}

It's not the right way, I get errors like ``String found where operator
expected'' when I try to write to the file.  What is the correct way to
do this?

Thanks.

gene


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

Date: 11 May 1997 21:51:20 GMT
From: gej@spamalot.mfg.sgi.com (Gene Johannsen)
Subject: Re: More problems with FileHandle
Message-Id: <5l5f0o$rkc$1@murrow.corp.sgi.com>

trs@azstarnet.com (Tim  Smith) writes:

| In article <5l44lg$e18$1@murrow.corp.sgi.com>,
| Gene Johannsen <gej@spamalot.mfg.sgi.com> wrote:
| >    my $fh = new FileHandle ">>$file";
| >
| >    return bless \$fh, $class;
| >
| >It's not the right way, I get errors like ``String found where operator
| >expected'' when I try to write to the file.  What is the correct way to
| >do this?
| 
| You shouldn't need to return a reference to the FileHandle.  Just:
| 
| return bless $fh, $class;
| 
| Tim
| 

Hey:

	I wasn't complete enough in my original query.  I want a set up
	like this:

package Foo;

sub new {
    my $class = shift;
    my $file = shift;

    my $fh = new FileHandle ">>$file";

    return bless \$fh, $class;
}

sub write {
    my $self = shift;
    confess "wrong type" unless ref $self;

    print $fh "This is a test\n";
}


	But this doesn't work.  What gives?

gene


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

Date: Sun, 11 May 1997 04:53:45 GMT
From: soccer@microserve.net (Geoffrey Hebert)
Subject: Re: need help w/forms and Perl
Message-Id: <5l3i97$3sr$1@news3.microserve.net>

Sorry,  

I did supply the URL (see signature below)

Actually, I am developing three sites concurrently.
This is my test site.  To thank those that have helped
me with perl, one of the sites will be a perl help site.

I am working on a perl cross reference.  When that
is working, I will put several working perls scipts
out on the site.  You will be able to check the index
for any perl word.  If you find it, you be able to click
to all the working locations.  

several people seem to have a need for email
and as a test I have put one of my email perl
scripts out.  

Hope this explains.

>>> Check out the Perl site!
>>            ^^^
>>I'd be happy to, if you'd give us its URL.

>>> http://www.microserve.net/~soccer/

>>_THAT's_ "the" Perl site???  

>It's also mildly annoying that the first three email addresses I
>entered caused server errors.  When asked in situations like that, I
>often enter addresses that will work but that I can trace back to the
>site if I start getting junk.  I don't mind the poster asking for my
>email address to enter the site, but simply believe me that it works.
>Whatever "checking" is being done is clearly not working.

>Cheers,
>Jeff



>Jeff Yoak  jeff@yoak.com  http://yoak.com/


-------  signature  ----------

Check out the Perl site!

http://www.microserve.net/~soccer/

use password perlmisc

Geat tool for Developers>



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

Date: Sun, 11 May 1997 01:15:41 -0700
From: Cimarron Taylor <cimarron@dis.org>
Subject: Re: New draft of scripting white paper
Message-Id: <3375802D.49A3@dis.org>

John Ousterhout wrote:
> If you hated the first version then you aren't likely to be satisfied
> with the new version either, but I've toned down the section on objects
> a bit, mentioned the "L" word, and made various other small changes.

	Well, a quick read of the new paper doesn't entirely
	satisify but I have to say it doesn't infuriate either
	so it is probably better.  My most specific criticism
	is that the entire paper misses the larger picture of
	how computing technology is being assimilated by our
	culture.  In particular, you write:

This paper is an opinion piece that calls attention to the change and 
explains why scripting languages will handle many of the programming tasks 
of the next century better than system programming languages.	

	This statement overlooks a very important class of high-level
	domain-specific	lanugages and interfaces (e.g. SQL, Matlab, 
	SAS, APT, Ladder-Logic, Spreadsheets, Word Macros, ...) which 
	are used to solve more real world problems than systems 
	programming or scripting languages.  

	I would like to claim that the current interest in general-purpose
	scripting and systems programming languages (e.g Tcl / Java) is 
	rapidly approaching a local maximum and in the beginning of the
	next century as more and more of our world's culture learns how 
	to represent business concepts in domain-specific computing languages 
	we will see a decline in the use of scripting and systems 
	programming and an increase in the use of domain-specific languages 
	supported by new generations of more powerful language construction 
	and analysis tools.  



	Cimarron Taylor
	cimarron@dis.org


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

Date: 11 May 1997 10:01:06 GMT
From: "Bill House" <bhouse@dazsi.nospam.com>
Subject: Re: New draft of scripting white paper
Message-Id: <01bc5df0$afb8f680$03d3c9d0@wjh_dell_133.dazsi.com>

It's much better. Now, I can better appreciate the parts I agreed with to begin with,
because I'm not so busy objecting to the earlier errata. <g>

Bill House
-- 
http://www.dazsi.com
Note: my e-mail address has been altered to
confuse the enemy. The views I express are
mine alone (unless you agree with me).




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

Date: 11 May 1997 04:09:14 GMT
From: mitchell@leadbelly.math.ufl.edu (Bill Mitchell)
Subject: persistent regular expressions
Message-Id: <MITCHELL.97May11000914@leadbelly.math.ufl.edu>


An earlier post asked about a way to use regular expressions in cases
where using /$pat/o is not appropriate because $pat may change, but in
which the same pattern is used often enough to make it desirable to
avoid a recompilation.  Someone suggested that

   "std" =~ /$pat/;
   while(...) { ...  if ($whatever =~  //){...}   }

would work if there was a string, "std" above, known to match every
pattern.  The following avoids the need for such a string:

   "" =~ /($pat)|$/;
   while(...) { ...
      $whatever =~ //; 
      if (defined($1)) { ... }
    }

If $1 is not needed, and the matches are long enough that copying
them slows things down, then /$pat|($)/ could be used instead, 
with  the test changed to "if (!defined($1))".
--
    Bill Mitchell
    Dept of Mathematics,        The University of Florida
    PO Box 118105, Gainesville, FL 32611--8105
    mitchell@math.ufl.edu	(352) 392-0281 x284

  


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

Date: 11 May 1997 00:39:36 -0500
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: persistent regular expressions
Message-Id: <5l3m2p$lmt@shoga.wwa.com>

Bill Mitchell <mitchell@leadbelly.math.ufl.edu> wrote:
>pattern.  The following avoids the need for such a string:
>
>   "" =~ /($pat)|$/;
>   while(...) { ...
>      $whatever =~ //; 
>      if (defined($1)) { ... }
>    }
>
>If $1 is not needed, and the matches are long enough that copying
>them slows things down, then /$pat|($)/ could be used instead, 
>with  the test changed to "if (!defined($1))".

Unless $pat contains parentheses.



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

Date: 11 May 1997 09:53:39 GMT
From: pmarquess@bfsec.bt.co.uk (Paul Marquess)
Subject: Re: REQ: Perl obfuscator
Message-Id: <5l44v3$5a7@pheidippides.axion.bt.co.uk>

Magnus Bodin (Magnus.Bodin@tychonides.se) wrote:

: Is there a perl obfuscator around?

: As if lurkers hadn't problems yet reading regexps :-D

: I really need one.

Have a look at the Filters module on CPAN, specifically the template
decrypt filter.

Paul


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

Date: Sun, 11 May 1997 11:20:31 GMT
From: jgd@cix.compulink.co.uk ("John Dallman")
Subject: Re: Searching NT Network For File
Message-Id: <EA0Ku8.BBz@cix.compulink.co.uk>

In article <33738777.15BE@enter.net>, rauenzc@enter.net (Craig R.) wrote:

> I'm new to perl and NT. What I want to do is to create a network
> connection to a specific server but I'm not sure how to do this. I have
> a book on perl but can't seem to find any way of accomplishing this. I
> would appreciate any hints or advice.

The Win32::NetAdmin and Win32::NetResource modules provided with 
ActiveWare's Perl for Win32 are supposed to let you do this, but I must 
say that my success with them has been limited. The scripts I've been 
writing do drive mounts using net.exe, which is supplied with NT.

For example, to mount \\server\a_share on f:, the perl would be

        system( "net use f: \\\\server\\a_share");
        
net.exe is documented in the Windows NT help, under Windows NT Commands.        

--- 
John Dallman, jgd@cix.co.uk. A micro-FAQ on things I keep getting asked: 
#!perl is at ftp://.../CPAN/ports/msdos/tips-tricks/hbp_403.zip, Perl for 
NT/Win 95 can be found at http://www.activeware.com, with an excellent FAQ 
file at http://www.endcontsw.com/people/evangelo/Perl_for_Win32_FAQ.html 
and no, I don't have the slightest idea what's wrong with your CGI script. 
Try http://www.perl.com/perl/faq/idiots-guide.html


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

Date: Sun, 11 May 1997 02:31:51 -0700
From: "Jonathan R. Seagrave" <jrs@abiogenesis.com>
Subject: sockets and port 23
Message-Id: <Pine.NXT.3.95q.970511021530.27566A-100000@gandalf>


Hi.  If anyone has any words of wisdom I'd love to hear them.

The following bit of code is a simple client program (much like that in 
the camel book) that connects and talks to a server.  I've tested it and
it does what I expect it to do for almost all of the ports on my system.
(e.g. echo-7, daytime-13, ftp-21, smtp-25, time-37, finger-79, httpd-80)

However, when I connect to port 23, there is nothing to read on SOCKET

If, when I'm connected (on port 23), I do a netstat -a I see (among 
other things):
  >  Prot RQ SQ Local Address     Foreign Address   (state)
  >  tcp  0  0  localhost.telnet  localhost.2652    ESTABLISHED
  >  tcp  0  0  localhost.2652    localhost.telnet  ESTABLISHED
So I know it's connecting.

If I try connecting to port 23 via telnet I see:
  >  $ telnet localhost 23
  >  Trying 127.0.0.1... Connected to localhost.
  >  Escape character is '^]'.
  >  
  >  
  >  NeXT Mach (gandalf) (ttyp5)
  >  
  >  Password:

Would anyone please tell me why this perl program doesn't send the "NeXT 
Mach $blahblahblah" stuff through SOCKET ?

One final tidbit is that while running perl -d with any of the ports that 
I listed above (that worked as expected) hitting ^C while in the for(;;)
loop sends me back to the debugger.  While running perl -d and port 23,   
hitting ^C while in the for(;;) loop does not send me back into the 
debugger.  I'm at a loss to explain this.  Anyone?

thanks a lot,
Jonathan

########################################################################
#!/usr/bin/perl5 -w

use strict;
use Carp;
use Socket;
use Term::ReadKey;

my ($host, $port) = ("localhost", 23);

my $iaddr = inet_aton ($host) or die "no host: $!";
my $paddr = sockaddr_in ($port, $iaddr);
my $proto = getprotobyname ('tcp');

socket (SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
connect (SOCKET, $paddr) or die "connect: $!";

# if you to see anything that's poorly coded please let me know,
# tips are always welcome  :)

my $in = \*STDIN;
my $sock = \*SOCKET;

select $sock;
$| = 1;

my ($stdin, $stdout, $socketin, $socketout);

for (;;) {                                 # nice infinite loop huh? :)
    $stdin = ReadLine (-1, $in);
    $socketin = ReadLine (-1, $sock);
    print STDOUT $socketin if (defined $socketin);
    print SOCKET $stdin if (defined $stdin);
}
__END__

Jonathan R Seagrave   <jrs@abiogenesis.com>
pgp public key at     http://www.abiogenesis.com/jrs
                           
The other day I saw a bumper sticker that read "Honk if you passed p-chem".
I honked and the driver flipped me off; I guess he didn't pass!



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

Date: Tue, 13 May 1997 13:27:03 GMT
From: kimtan@lucent.com (kim Tan)
Subject: speed up "STDOUT" ?
Message-Id: <5l9pu3$4hs@nntpa.cb.lucent.com>

I have a program written in C and outputing stuff to STDOUT, I use the 
output from the C program for building HTML page. 
This is what I did :

$| = 1;
foreach $line (`cprogram`) {
        do something;
}

However, basically it is slow because it will have to wait for the 
cprogram to finish all the output before executing the foreach...., what I
am trying to do is to process each line of output from the cprogram as it
goes instead of waiting for it to finish outputing all (because the list the 
cprogram output can be long, hence the wait).
the cprogram is being maintained by different group, hence I
am hoping that if there is a workaround to speed it up without me having to
"embed" my stuff into the  cprogram. 


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

Date: 12 May 1997 03:20:07 -0400
From: Owen Taylor <owt1@cornell.edu>
Subject: Re: speeding up a regex
Message-Id: <lzpvuxdumw.fsf@huygens.cit.cornell.edu>


The problem, as I see it is is not your regex, per se, but your
algorithm. It looks like you are checking every name against
every password entry, making the whole thing N^2. If your password
file isn't _too_ big, you should be able to do it in close to linear
time. 

Idea:

Make an initial run over your password file, and create an hash
of arrays, indexed by the uppercased last name, where each subarray
holds the information (user name, name in password file), for all
the people with that last name. Then when you are scanning your
roster, you only have to check those people with the right last
name.

(you could either structure your array as,

{ SMITH => [ 'John A Smith:jasmith', 'Jane B Smith:jbsmith' ] }

or,

{ SMITH => [ [ 'John A Smith','jasmith'], ['Jane B Smith','jbsmith'] ] }

the first one is probably more memory efficient, the second one is
almost certainly faster, since you don't have to do a split each
time.)

(This might take a bit of memory, but you should be able to handle
many thousand names like this on a modest machine.)

If you do it this way, the speed of your regex shouldn't matter much.

Regards,
                                        Owen


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

Date: Wed, 07 May 1997 13:01:50 GMT
From: knetsch@golden.net.no.spam (SJK)
Subject: Re: system () won't execute the called program.
Message-Id: <33707c65.1668310@news.golden.net>

On 06 May 1997 12:24:31 -0400, Ken Anderson <anderson@necsys.gsfc.nasa.gov>
wrote:

>
>Hi again,
>
>I have a perl program which has to execute an external
>c program, so i am using 
>
>
>	system("cprog -p prog.par") && die "cprog failed. $!\n";
>

Ummm.... I'm just a newbie, but I think I see something here.  You're asking the
program to call the system AND die.  Don't you want it to die only if the system
call fails? ie 

system("cprog -p prog.par") || die "cprog failed. $!\n";

Cautiously sticking my head up,

Stuart Knetsch (newbie PERL programmer)
Knetsch@golden.net


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

Date: Sat, 10 May 1997 22:55:49 GMT
From: stephen farrell <stephen+usenet@farrell.org>
To: knetsch@golden.net.no.spam (SJK)
Subject: Re: system () won't execute the called program.
Message-Id: <87yb9nndhm.fsf@phaedrus.uchicago.edu>

knetsch@golden.net.no.spam (SJK) writes:

> On 06 May 1997 12:24:31 -0400, Ken Anderson <anderson@necsys.gsfc.nasa.gov>
> wrote:
> 
> >
> >Hi again,
> >
> >I have a perl program which has to execute an external
> >c program, so i am using 
> >
> >
> >	system("cprog -p prog.par") && die "cprog failed. $!\n";
> >
> 
> Ummm.... I'm just a newbie, but I think I see something here.  You're asking the
> program to call the system AND die.  Don't you want it to die only if the system
> call fails? ie 
> 
> system("cprog -p prog.par") || die "cprog failed. $!\n";
> 
> Cautiously sticking my head up,
> 
> Stuart Knetsch (newbie PERL programmer)
> Knetsch@golden.net

Check back in the previous posts in this thread.  The problem is that
the return type from a shell is supposed to work so that if there is
normal execution, return 0, otherwise return an error code.  By this
notion, his && usage is right.  However, in perl it is a little more
complex.  Again, look back at the earlier posts in the thread.

--sf


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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

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

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


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

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