[16661] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4073 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 20 21:05:45 2000

Date: Sun, 20 Aug 2000 18:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <966819915-v9-i4073@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 20 Aug 2000     Volume: 9 Number: 4073

Today's topics:
    Re: crypt function (Mark-Jason Dominus)
    Re: crypt function (Mark-Jason Dominus)
    Re: DBI has me stumped... maybe OO problem? <dale@emmons.dontspamme.com>
    Re: Forking sub{}'s and selective SIG{CHLD} responses (Martien Verbruggen)
    Re: Forking sub{}'s and selective SIG{CHLD} responses (Martien Verbruggen)
        Getting rid of extra spaces and returns <bob3434@excite.com>
        Help! Perl wont even run from DOS prompt. xdesmond@hotmail.com
    Re: Help! Perl wont even run from DOS prompt. <xdesmond@hotmail.com>
    Re: HELP: interpolation of patterns and the pos command <drayner@atnf.csiro.au>
    Re: how to generate unreadable from readable perl code (Abigail)
    Re: How to know when the client close the browser (Abigail)
        HOWTO......(without LWP) <mtaylorlrim@my-deja.com>
    Re: HOWTO......(without LWP) <tina@streetmail.com>
    Re: HOWTO......(without LWP) (Martien Verbruggen)
    Re: Localize "require" to subdomain (Clinton A. Pierce)
    Re: My script has some bugs <rtarpine@hotmail.com>
    Re: Need some quick help.. (Abigail)
        Newbie lost and needs direction <steve.beaumont.spamoff@btinternet.com>
    Re: Newbie lost and needs direction <bwalton@rochester.rr.com>
    Re: Newbie Needs Help with string comparison <callgirl@la.znet.com>
    Re: Newbie Needs Help with string comparison <o_dehon@my-deja.com>
    Re: Newbie Needs Help with string comparison <callgirl@la.znet.com>
    Re: Newbie Needs Help with string comparison <mauldin@netstorm.net>
    Re: Newbie Needs Help with string comparison <mauldin@netstorm.net>
    Re: Open Multiple Files (Abigail)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 20 Aug 2000 23:46:14 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: crypt function
Message-Id: <39a06dc6.a17$2c8@news.op.net>

In article <8neaoq$tid$1@nnrp1.deja.com>,  <sankarmukh@my-deja.com> wrote:
>I copied the decrypt subroutine from a FAQ:
> But this is giving me syntax error. What is wrong here?
> Any advice is appreciated.

My apologies.  Here is a corrected version.

        sub decrypt {
          my $c = shift;
          my @c = (0) x 8;
          for (;;) {
            my $i = 0;
            my $s = join '', map chr, @c;
            return $s if crypt($s, $c) eq $c;
            $c[$i]=0, $i++ while $c[$i] == 255;
            return undef if $i > 7;
            $c[$i]++;
          }
        }

To use it:

        $true_password = decrypt($encrypted_password);



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

Date: Sun, 20 Aug 2000 23:47:20 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: crypt function
Message-Id: <39a06e07.a21$3c2@news.op.net>

In article <39add6c5.85079077@news.newsguy.com>,
Keith Calvert Ivey <kcivey@cpcug.org> wrote:
>(assuming it doesn't find another string instead that
>produces the same crypted version).

If it does, that's OK, because such a string will work just as well as
the true password.


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

Date: Sun, 20 Aug 2000 19:59:04 -0500
From: "Dale Emmons" <dale@emmons.dontspamme.com>
Subject: Re: DBI has me stumped... maybe OO problem?
Message-Id: <sq0vd6o387v111@corp.supernews.com>

ok, now I feel a bit dumb. I never ran the program at the command line (I
was tired...). I just did, and found at any date later than the first it
outputs:

DBD::mysql::db selectrow_array failed: MySQL server has gone away at
calendar.cgi line 257.

Which explains the problem that I'm having, but I can't figure out why the
server is going away? It's only miliseconds between queries, so it isn't
timing out.

Any ideas? Anyone?




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

Date: 20 Aug 2000 22:37:00 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Forking sub{}'s and selective SIG{CHLD} responses
Message-Id: <slrn8q0mq9.l5b.mgjv@martien.heliotrope.home>

On Sat, 19 Aug 2000 02:19:52 GMT,
	Mark Neill <unixgod@jacksonville.net> wrote:
> Please respond in Email as well, I don't normally frequent this newsgroup -
> mark@thisismyown.com

Sorry, if you want email responses, you better make sure that your From:
or reply-To headers are correct.

> I'm having a problem with a program I'm writing that inconveniently happens
> to be under a deadline.  It's a Perl/Tk GUI to monitor the status of a
> number of tape drives.  The querying of the drives takes a long time,
> though, so I have written the code to fork a child to do the actual
> monitoring, leaving the GUI to respond to clicks and such.  The pseudocode
> is at http://www.thisismyown.com/files/perl.html
>  if you want to see, but basically, the Tk::MainWindow::repeat() method
> calls a forking wrapper to sub A{} every so often.  On the exit of said
> fork, I want to run sub B{}.  I can't install a blatant SIG{CHLD} handler,
> because the various subs are making system calls and other execs that are
> returning false CHLD's.
> 
> What do I need to do to _selectively_ trap and respond to SIG{CHLD}?

Hmmm... First of all: this problem isn't really Perl specific, and you
might actually have some success by posting this to
comp.unix.programmer.

Are you sure that you need to solve the problem by trapping specific
SIG_CHLD? Do you control the code in the fork, or do you exec in there?
Does the work really need to happen _after_ termination of the fork, or
could it be done in the fork itself, or even by having the child
communicate to the parent? o

AFAIK there is no way to distinguish one SIG_CHLD from another. They're
all the same thing.

Maybe it's an idea to rethink your design. Have more code in the fork,
and let the fork do the work you want to do. Put IPC between the child
and the parent, or use threads.

As said, over in comp.unix.programmer they might ctually have more or
better ideas.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd.   | cynical. It's perfectly easy to be
NSW, Australia                  | cynical.


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

Date: 20 Aug 2000 22:37:19 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Forking sub{}'s and selective SIG{CHLD} responses
Message-Id: <slrn8q0ndf.l5b.mgjv@martien.heliotrope.home>

On Sat, 19 Aug 2000 02:19:52 GMT,
	Mark Neill <unixgod@jacksonville.net> wrote:
> 
> What do I need to do to _selectively_ trap and respond to SIG{CHLD}?

Just had another thought about this, although I don't know whether it
will work:

Have you tried setting $SIG{CHLD} globally to something else than
locally? I am not sure whether that works at all, or whether the signal
handlers in perl are installed per process. You could give that a try at
least.

local $SIG{CHLD} = \&foo;

Martien

PS. I really doubt it will work, but it would be interesting to see.
Would be nice of you to report back to tell us whether or not this
worked.
-- 
Martien Verbruggen              | 
Interactive Media Division      | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd.   | make up 3/4 of the population.
NSW, Australia                  | 


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

Date: Sun, 20 Aug 2000 17:49:35 -0700
From: Unknown <bob3434@excite.com>
Subject: Getting rid of extra spaces and returns
Message-Id: <200820001749353419%bob3434@excite.com>

Hi,

I have created a resume form - and I need to have its output printed to
an external file in comma delimited form. This external file will then
need to be imported into a spreadsheet program.

However I want to eliminate uneeded spaces and returns in the external
file.  For example a user may add one two many spaces between words or
they may paste in some text with lots of additional returns or spaces.

Here is a snapshot of the log file:

http://home.mindspring.com/~lexmesa/stest/logFile.jpg

The diamond symbols represent the extra spaces and the returns are also
documented (I'm using a feature in BBedit)

My Html response page  eliminates all of the spaces and unwanted
returns but for some reason the log does not do this:

http://home.mindspring.com/~lexmesa/stest/htmlResponsePage.jpg


I have been using the translate function to try an remove returns:

$resume =~ tr/\n/ /s;

but I also need a translate function to remove extra spaces between
words?

Basically I want to be able to parse the data so that addional spaces
between words are eliminated and additional returns (more than one) are
eliminated.  Any suggestions would be appreciated.

best,
Mark





My code ----------

#!/usr/local/bin/perl
require "../subr/sub_error.lib";
require "../subr/parseForm.lib";

&parseForm($formdata);
#&ErrorMessage;

print "Content-type: text/html\n\n";

# created scalars  from sub parseForm

$name = $formdata{'name'};
$name =~ tr/\n/ /s;
$saddr = $formdata{'saddr'};
$saddr =~ tr/\n/ /s;
$city = $formdata{'city'};
$resume = $formdata{'resume'};
$resume =~ tr/\n/ /s;
$resume =~ tr/,/ /s;


#####
# leaving these sub routine conversions in just in case I need more
#####


#$tac4 = $formdata{'tac4'};
#$tac5 = $formdata{'tac5'};
#$tac6 = $formdata{'tac6'};
#$dac1 = $formdata{'dac1'};
#$dac2 = $formdata{'dac2'};
#$dac3 = $formdata{'dac3'};
#$dac4 = $formdata{'dac4'};
#$dac5 = $formdata{'dac5'};
#$dac6 = $formdata{'dac6'};
#$h1 = $formdata{'h1'};
#$h2 = $formdata{'h2'};
#$h3 = $formdata{'h3'};
#$h4 = $formdata{'h4'};

####
# sroutine conversion for sendmail
# the subject, from, and to fields need to be setup as hidden fields in
the HTML file
# the cc field can be commented out if not needed
# you could create a hidden field with cc or setup a user inputted field
# $to needed to have any spaces or return lines removed from its input
# so chop and chomp was called to get the job done
####

$to = $formdata{'to'};
while ($to =~ /\s$/) {
   chop($to);
   chomp($to);
}

$subject = $formdata{'subject'};
$from = $formdata{'from'};
#$cc = $formdata{'cc'};

####
# figure out current date
####

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);

@days = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
@months =
qw(January February March April May June July August September October
November December);

####
# check referer link is on mcg server
# open file to prepare for printing to external file
####

$origin = $ENV{'HTTP_REFERER'};

if ($origin =~ m#^http://www.mcreative.com/#) {
open(LOG, ">>/users/www/domains/mcreative.com/logs/mailform/log.txt") 
|| &ErrorMessage("Error occurred attempting to open file test.txt");

flock(LOG, 2);
print LOG "\"$name\",\"$saddr\",\"$city\",\"$resume\"\n\n";
flock(LOG, 8);
close (LOG);

} else {
print "Can not run script from this location";
exit;
}

####
# prints the HTML response page
####

print <<"HTML code";

<html>

   removed code
</html>

HTML code


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

Date: Mon, 21 Aug 2000 00:03:32 GMT
From: xdesmond@hotmail.com
Subject: Help! Perl wont even run from DOS prompt.
Message-Id: <8nprkb$ms4$1@nnrp1.deja.com>

Im a newbie and ive been reading the faq's about installing
active perl on win98 but nothing seems to be working.
when i try perl -v (or any perl <scriptname> for that matter)
from the console i just get a bad command or file name error.
I have tried to reinstall perl but didnt help. i also installed
the DCOM.asp but still nothin. Am i missing something?

also, when i run from within my browser it just shows me the script
but not the output. is there some configuring that i need to do to run
my own perl/cgi or do i need to install a webserver to do that? if so
whats a good solution for windows?

sorry for the rookie questions..
thanks a bunch



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 21 Aug 2000 00:48:30 GMT
From: Mike <xdesmond@hotmail.com>
Subject: Re: Help! Perl wont even run from DOS prompt.
Message-Id: <8npu8p$po6$1@nnrp1.deja.com>

- when i type SET at the dos prompt it says my PATH is
C:\PERL\5.00502\BIN\MSWIN32-x86-OBJECT;
C:\PERL\5.00502\BIN;

this doesnt look right to me considering i installed
active perl release 5.6.0.616. if anyone thinks this
might be the cause of my problem, how can i change the
path?

thanks again


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 20 Aug 2000 22:27:06 GMT
From: Dave Rayner <drayner@atnf.csiro.au>
Subject: Re: HELP: interpolation of patterns and the pos command
Message-Id: <39A05B3A.F539F7EA@atnf.csiro.au>

"Dragomir R. Radev" wrote:
> 
> I am trying to see where in $long does a substring $short appear.
> 
> ======================
> #!/bin/perl
> 
> $long = <>;
> chop $long;
> $short = <>;
> chop $short;
> 
> $long =~ m/$short/g;
> $pos = pos $long;
> 
> print "$pos\n";
> ======================
> 

I think the \Q \E sequence will do what you want:

$long =~ m/\Q$short\E/g;

Regards, Dave R.


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

Date: 20 Aug 2000 18:05:16 GMT
From: abigail@foad.org (Abigail)
Subject: Re: how to generate unreadable from readable perl code
Message-Id: <slrn8q07dk.tj3.abigail@alexandra.foad.org>

Horst Wassenberg (horst@swid.de) wrote on MMDXLV September MCMXCIII in
<URL:news:399E3A63.A5D94B79@swid.de>:
,, Hi,
,, 
,, I need to provide perl code to others, but I would like to avoid that
,, - the code can be understood easily
,, - can be extended by others
,, 
,, Hence, I would like to run a program that replaces my "long name var
,, names" with something like "$V00001" to "$V99999" or similar, that
,, replaces sub-names in a similar mannor, that deletes all comments,
,, removes all indenting white space etc.
,, 
,, => where can I find such a program?


Well, I have such a program, but to avoid it from being understood or
extended by others, you can't have it.



Abigail
-- 
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()


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

Date: 20 Aug 2000 18:07:55 GMT
From: abigail@foad.org (Abigail)
Subject: Re: How to know when the client close the browser
Message-Id: <slrn8q07ik.tj3.abigail@alexandra.foad.org>

Yeung Kin (kyeung@acae.cuhk.edu.hk) wrote on MMDXLVI September MCMXCIII
in <URL:news:399F8836.B9FF49E5@acae.cuhk.edu.hk>:
** Hello! Could anyone share the idea with me that I have a page can only
** access by one client once time. So after one client logon, others are
** forbiddened. My server can be known that the user has been logout when
** he/she click on the logout button. But how can I know if the user just
** close the browser suddenly?

Very short answer: you don't. Your idea of how HTTP works is completely
and utterly wrong. Give up now - it's easier to make water flow upwards.

However, this has nothing to do with Perl. You might want to ask in a
group dealing with HTTP, or perhaps CGI.

** I mainly handle them in Perl language.

Irrelevant.


Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


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

Date: Sun, 20 Aug 2000 23:40:02 GMT
From: Mark <mtaylorlrim@my-deja.com>
Subject: HOWTO......(without LWP)
Message-Id: <8npq8g$l9l$1@nnrp1.deja.com>

I have searched and cannot find that oft asked question....

Can I capture the source of a web page into an array?

I know it can be done with the LWP module, but I want to do it without.
Perhaps even put the output into a file. Sort of like this...

open FILE;
print FILE "Location:http://domain.com/page.html";
close FILE;

I only wish it was that simple.... Can someone please pass me enough
code snippets to get it please?

Thanks
Mark


--
Please reply to this newsgroup as my Deja mail
is used as a spam catcher only!


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 21 Aug 2000 00:07:40 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: HOWTO......(without LWP)
Message-Id: <8nprsc$95jp3$11@ID-24002.news.cis.dfn.de>

hi,
Mark <mtaylorlrim@my-deja.com> wrote:

> Can I capture the source of a web page into an array?
> I know it can be done with the LWP module, but I want to do it without.

sure. look at the source code of LWP::Simple and do
it the same way...
seriously, that's the only way i can think of.
maybe i would use wget or webget for UNIX, if i was sure the
script would only run under UNIX

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: 21 Aug 2000 01:01:22 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: HOWTO......(without LWP)
Message-Id: <slrn8q0u39.l5b.mgjv@martien.heliotrope.home>

On Sun, 20 Aug 2000 23:40:02 GMT,
	Mark <mtaylorlrim@my-deja.com> wrote:
> I have searched and cannot find that oft asked question....
> 
> Can I capture the source of a web page into an array?
> 
> I know it can be done with the LWP module, but I want to do it without.

Without LWP your life becomes hard. You will have to parse the URL, and
break it up in its constituent parts, open a soclet to
the remote machine, speak the correct HTTP, and send it the request for
the document. Then you have to read the response, parse it, and make
sure no errors occured, and split the headers from the body. Then you
close the socket.

Why don't you want to use LWP? It does a lot of work. reproducing it is
just opening you up to bugs and errors, especially if you don't
understand the issues involved.

Some documentation:

# perldoc Socket

For the rest, I refer you to the source code of LWP, and to an archive
of this newsgroup. Sometimes people do post little snippets of code that
does more or less what you want. You should be able to find some on
www.deja.com, caveat emptor.

Oh, Perl FAQ part 5 has, coincidentally, a small example that might be
useful, under the question 'How do I flush/unbuffer an output
filehandle?  Why must I do this?' (the last example).

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: Sun, 20 Aug 2000 21:01:19 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Localize "require" to subdomain
Message-Id: <zGXn5.5642$QW4.86908@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <8nobfq$l2t$1@solti3.sdm.de>,
	Steffen Beyer <sb@muccpu1.muc.sdm.de> writes:
> In article <dzNn5.3572$Nz4.162641@newsread1.prod.itd.earthlink.net>, Jacob Morrrison <zikeweb@earthlink.net> wrote:
> 
>> Is there a way you can make the variables retrieved with a required file to
>> only be avalible in the subroutine it was required in? thanks,
>> Jacob Morrison
> 
> Trivial: the "require"d code must have a "package" declaration.

No, they're still available outside of the subroutine if you know the 
package name.  This doesn't make them inaccessable outside of the 
subroutine, it just puts them in a corner out of the way.

-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours! 
  clintp@geeksalad.org         for details see http://www.geeksalad.org
"If you rush a Miracle Man, 
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: 20 Aug 2000 15:25:49 -0400
From: Ryan Tarpine <rtarpine@hotmail.com>
Subject: Re: My script has some bugs
Message-Id: <8npbd6$2qp4$1@newssvr05-en0.news.prodigy.com>


Make sure you have the correct path for the shebang line.  e.g., #!/usr/local/bin/perl
Try changing all the CR/LF's in the file into plain linefeeds.  On the unix server, type
tr -d '\r' < yourscript > newscriptname
then try executing the new script

Ryan

>My script is basically finished!  It has some bugs in it.  When I do the
>check in windows/dos it goes just fine, but when I upload it to my server it
>blows up with a 500 error and I can't figure it out.  I have no way of
>tracking what is happening or where it is at when it stops.  If someone
>could tell me how to do that, or do it for me if they have a UNIX machine
>that would be great!  Maybe someone might even want to take a look at the
>script fix it leaving commments where they changed it.  Thanks alot for
>anybody's help!



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

Date: 20 Aug 2000 18:27:08 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Need some quick help..
Message-Id: <slrn8q08ml.tj3.abigail@alexandra.foad.org>

DS (snakeman@kc.rr.com) wrote on MMDXLIV September MCMXCIII in
<URL:news:6ijn5.2564$H5.32745@typhoon.kc.rr.com>:
^^ Hello-
^^    I am wanting to print the last modified date to the html page. For
^^ example using
^^     <!--#flastmod file="default.html" -->
^^ 
^^ but I don't want to edit it everytime I add it to a page. I know that
^^ DOCUMENT_NAME will return the current filename but it wont work like this :
^^ 
^^ <!--#flastmod file="DOCUMENT_NAME" -->
^^ 
^^ due to the fact it is looking for an actual document called "DOCUMENT_NAME".


And your Perl issue is..... ?



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Mon, 21 Aug 2000 00:13:55 +0100
From: "Steve Beaumont" <steve.beaumont.spamoff@btinternet.com>
Subject: Newbie lost and needs direction
Message-Id: <8npojq$n4e$1@plutonium.btinternet.com>

I have freshly installed Perl 5.00503-10 and Libnet 1.0606-2.
I am trying to make use of NNTP.
When I compile I ger the error message saying Globa symbol "%Config"
requires explicit package name.  This is comming from Socket.pm line 211
which reads:
use    Config;.........
if ....... defined $Config{d_alarm} && defined alarm($timeout) or

Config.pm reads:  d_alarm='define'

So why am I getting this error?  I don't really know what I am doing wrong
or how to fix it.  As I am so new to this I doubt if it is a bug in the code
especially as I have searched hi and low in the news groups for this speific
problem to no eval.

I would really appreciate some help!




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

Date: Mon, 21 Aug 2000 00:45:25 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Newbie lost and needs direction
Message-Id: <39A07BD3.3251CBD7@rochester.rr.com>

Steve Beaumont wrote:
> 
> I have freshly installed Perl 5.00503-10 and Libnet 1.0606-2.
> I am trying to make use of NNTP.
> When I compile I ger the error message saying Globa symbol "%Config"
> requires explicit package name.  This is comming from Socket.pm line 211
> which reads:
> use    Config;.........
> if ....... defined $Config{d_alarm} && defined alarm($timeout) or
> 
> Config.pm reads:  d_alarm='define'
> 
> So why am I getting this error?  I don't really know what I am doing wrong
> or how to fix it.  As I am so new to this I doubt if it is a bug in the code
> especially as I have searched hi and low in the news groups for this speific
> problem to no eval.
 ...
Steve, could you boil your code down to a very short simple but complete
example that still generates your problem and that anyone could easily
run, and post that?  Then perhaps someone could help.  I note that the
following seems to work fine on ActiveState Perl 5.6 build 616 on
Windoze 98 SE:

#!/usr/local/bin/perl -w
use Net::NNTP;
$c = new Net::NNTP('news-server.rochester.rr.com');
($n,$first, $last) = ($c->group("comp.lang.perl.misc"));
for (; $first <= $last; $first++) {
    print @{$c->article($first)};
}

-- 
Bob Walton


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

Date: Sun, 20 Aug 2000 11:09:41 -0700
From: "Godzilla!" <callgirl@la.znet.com>
Subject: Re: Newbie Needs Help with string comparison
Message-Id: <39A01EE5.2FC26917@la.znet.com>

Warren wrote:

(snippage)
 
> I am trying to compare the IP address for a user using a script,

> because it indicates that none in the file match the one in the
> variable $IP and the value for $n is 0 because it says it found no
> matches. 


> open(FILE, "vote_test.dat");
 
> @UserList = <FILE>;
 
Haven't tested your code. First glance indicates
you need to chomp your array to remove \n from
each element. With this \n at the end, you will
never attain an IP numerical match using an 'eq'
type operation. Use of 'index' would attain a
match if you don't want to chomp those \n.

chomp (@UserList);

or

if (${\index ($data_ip, $input_ip)} gt -1)
 { do something here... }


Easier method for this..

open your file
create an array
chomp your array...

foreach $element (@Array)
 {
  if ($input_ip eq $data_ip)
   { do whatever here...}
 }

 ...and exit your loop by method of your choice.
No counter is required, no "until" is required
if you bail from your loop upon a match.


Keep in mind many IP addresses will change
for the same person. Dynamic IP addresses
are very common. You will successfully
hit more matches by using only the first
six to eight numbers of IP addresses for
comparison. However, you will never have
a one-hundred percent success rate. Still,
as your data base grows, you will enjoy
greater success in matching.

Try chomping your array, remove those \n
characters and discover if you don't
have better luck.

Godzilla!


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

Date: Sun, 20 Aug 2000 18:09:37 GMT
From: Olivier Dehon <o_dehon@my-deja.com>
Subject: Re: Newbie Needs Help with string comparison
Message-Id: <8np6sn$bg$1@nnrp1.deja.com>

In article <39a00c6c.594712837@news.gte.net>,
  warren@desertwolf.com (Warren) wrote:
> I am trying to compare the IP address for a user using a script, to a
> separate txt file of IP addresses. The script below is what I am
> using. The result is a print-out of the IP addresses in the file
> because it indicates that none in the file match the one in the
> variable $IP and the value for $n is 0 because it says it found no
> matches.  However, one of them in the file is my static IP address.
> Any ideas on what I'm doing wrong?
>
> #!/usr/local/bin/perl
>

Don't forget to use the -w switch, and 'use strict;'

> print "Content-type: text/html", "\n\n";
>
> $IP = $ENV{'REMOTE_ADDR'};
>
> open(FILE, "vote_test.dat");
>
> @UserList = <FILE>;
>

The strings in @UserList contain an ending "newline".
So unless $IP ends in a newline as well, none of the string comparisons
below can be true !

See:
perldoc -f chomp

> $n = 0;
> $ListPos = 0;
>
> until($ListPos > $#UserList){
>   if ($IP eq $UserList[$ListPos]) {
> 	$n +=1;
>       $ListPos +=1;
>    }
>   else {
>   print "$UserList[$ListPos]\n";
>   $ListPos +=1;
>   }
> }
> close(FILE);
>
> print $n;
>

HTH, -Olivier


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 20 Aug 2000 11:20:05 -0700
From: "Godzilla!" <callgirl@la.znet.com>
Subject: Re: Newbie Needs Help with string comparison
Message-Id: <39A02155.5F5CA4EA@la.znet.com>

"Godzilla!" wrote:
 
> Warren wrote:


Minor correction in my syntax here.


> foreach $element (@Array)
>  {
>   if ($input_ip eq $element)
>    { do whatever here...}
>  }


Notice I changed $data_ip to $element
in my 'if' conditional. Sorry, suffered
an obvious brain fart.

Godzilla!


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

Date: Sun, 20 Aug 2000 18:33:39 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: Newbie Needs Help with string comparison
Message-Id: <39A023D2.2448F0AD@netstorm.net>

Warren wrote:
> 
> The result is a print-out of the IP addresses in the file
> because it indicates that none in the file match the one in the
> variable $IP

> until($ListPos > $#UserList){
>   if ($IP eq $UserList[$ListPos]) {
>         $n +=1;
>       $ListPos +=1;
>    }
>   else {
>   print "$UserList[$ListPos]\n";
>   $ListPos +=1;
>   }

No offence meant, but I laughed when I saw this because it's doing
exactly what you told it to!!!  Ask yourself this:  under what
conditions will this *not* print out an element in @UserList?

There are a number of things you should do to sharpen up this code, but
here's another way to accomplish what you are trying to do:

for (@UserList) {
	print if $IP eq $_;
}

I was just in the bookstore wondering whether I should buy the latest
edition of "Progamming Perl" (I already have the 2nd edition), but this
would certainly be a worthwhile investment for you if you don't have
it.  It's fun!

-- Jim


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

Date: Sun, 20 Aug 2000 18:42:13 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: Newbie Needs Help with string comparison
Message-Id: <39A025D8.5EE78474@netstorm.net>

I Mauldin wrote:
> 
> for (@UserList) {
>         print if $IP eq $_;
> }
> 

And Warren and Godzilla are correct - you must chomp the elements in
@UserList first.

-- Jim


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

Date: 20 Aug 2000 18:30:28 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Open Multiple Files
Message-Id: <slrn8q08st.tj3.abigail@alexandra.foad.org>

Jonathan Stowe (gellyfish@gellyfish.com) wrote on MMDXLVI September
MCMXCIII in <URL:news:8no636$iq7$1@orpheus.gellyfish.com>:
'' On Fri, 18 Aug 2000 13:27:26 GMT Micheal wrote:
'' > Hi there,
'' > 
'' > 
'' > How would I open two (or more) documents at the same time to save output to
'' > them?
'' > 
'' > I have
'' > 
'' > open(OUTPUT, ">$dir/$filename");
'' > ...
'' > close OUTPUT;
'' > 
'' > 
'' > 
'' > which works for one file, but I have tried multiple combinations of this to
'' > open to files at once...  never works.  Any suggestions appreciated
'' > 
'' 
'' If you need to write to two files with one print then you might perhaps
'' want to consider a tied filehandle - look at the perltie and Tie::Handle
'' manpages for an idea of where to start.


Or fork [*], have the child read the parents STDOUT and let the child do
the multiplexing.

[*] Without using fork(), just use a special form of open. See perlopentut.


Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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.

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 V9 Issue 4073
**************************************


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