[17101] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4513 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 4 00:05:28 2000

Date: Tue, 3 Oct 2000 21:05:09 -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: <970632309-v9-i4513@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 3 Oct 2000     Volume: 9 Number: 4513

Today's topics:
        advise on how to set bugging on in perl file <sammy@bigpond.net.au.nospam>
    Re: advise on how to set bugging on in perl file (Clay Irving)
    Re: Blank line appending data to file (Gwyn Judd)
    Re: check double words <jeffp@crusoe.net>
    Re: die() ignores tied STDERR? <anmcguire@ce.mediaone.net>
    Re: error in mapping array slice <r28629@email.sps.mot.com>
        eval(): How do I redirect input? 104073.3433@compuserve.com
    Re: force arithmetic interpretation <anmcguire@ce.mediaone.net>
    Re: how to split text by number of words? <tina@streetmail.com>
    Re: Limiting Form Field Input? <tina@streetmail.com>
        LWP Newbie Question <m00fbe01@mcmail.comNOSPAM>
    Re: MATH problem <jeffp@crusoe.net>
        PERL CD BOOKSHELF from O'Reilly - Anyone post these CD' eatme@myhouse.com
    Re: problems to install perl module (Clay Irving)
    Re: scripts not working <pdmos23@geocities.com>
    Re: scripts not working <jeff@vpservices.com>
    Re: scripts not working <jeff@vpservices.com>
    Re: scripts not working <peter.sundstrom@eds.com>
        Search an array <adalessandro@odione.com>
    Re: Search an array <tony_curtis32@yahoo.com>
    Re: Search an array <wyzelli@yahoo.com>
    Re: Search an array <anmcguire@ce.mediaone.net>
    Re: Search an array (Craig Berry)
    Re: Search an array <godzilla@stomp.stomp.tokyo>
    Re: some questions (Craig Berry)
    Re: Strange behavior with DESTROY and END <bwalton@rochester.rr.com>
    Re: Testing for numeric integer (Keith Calvert Ivey)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 04 Oct 2000 01:25:31 GMT
From: "sammy" <sammy@bigpond.net.au.nospam>
Subject: advise on how to set bugging on in perl file
Message-Id: <fGvC5.16479$Nr3.61901@news-server.bigpond.net.au>

Appreciate some advise on how to set bugging on in perl file.

similar to typing set -x in a unix shell program or sh -x

perl -D4 file.pl

I have used the d option but the man entry of perl advises I need to enter
debug options into the perl script itself for the d option to have any
affect.


Thanks in advance
Sammy





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

Date: 4 Oct 2000 01:58:02 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: advise on how to set bugging on in perl file
Message-Id: <slrn8tl3la.slt.clay@panix3.panix.com>

On Wed, 04 Oct 2000 01:25:31 GMT, sammy <sammy@bigpond.net.au.nospam> wrote:

>Appreciate some advise on how to set bugging on in perl file.
>
>similar to typing set -x in a unix shell program or sh -x
>
>perl -D4 file.pl
>
>I have used the d option but the man entry of perl advises I need to enter
>debug options into the perl script itself for the d option to have any
>affect.

perldoc perldebug

-- 
Clay Irving <clay@panix.com>
PREDILECTION, n. The preparatory stage of disillusion. 
- Ambrose Bierce 


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

Date: Wed, 04 Oct 2000 02:07:39 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Blank line appending data to file
Message-Id: <slrn8tl478.kkt.tjla@thislove.dyndns.org>

I was shocked! How could Nige P <nige@npay.freeserve.co.uk>
say such a terrible thing:
>Thanks Gwyn,
>Apologies for the format - this should be better?

Almost. You got the plain-text bit right but failed on the other usenet
"no-no". It's generally considered a good thing to post replies *below*
the text you are replying to as I am doing. Also you should only quote
text that makes it helpful to anyone reading your answer. ie. you
shouldn't quote everything they said, as well as everything they quoted
as well as...but rather you should delete most of it, only leaving in
the bits that are absolutely necessary. This makes it quicker to
download as well as easier to understand.

>Essentially $login is a variable used to enter the 'type xxxx' command
>on the command line.... does that help?
>Failing that, I can post the script up tomorrow....
>Thanks again.

Not really. I'm afraid you really need to post a complete (but minimal)
script that exhibits the behaviour. Can you take the script you have and
cut it right down to the minimum parts that still exhibits the
misbehaviour (and that will run by itself) and then post that? If not I
fear nobody here will be able to help you.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Next Friday will not be your lucky day. As a matter of fact, you
don'thave a lucky day this year.


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

Date: Tue, 3 Oct 2000 22:59:27 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: check double words
Message-Id: <Pine.GSO.4.21.0010032258140.14163-100000@crusoe.crusoe.net>

On Oct 3, Larry Rosler said:

>perlfaq4: "How can I remove duplicate elements from a list or array?"

I'm highly irked that the pre-5.6 entry in the FAQ contains the keyword
'unique', and the 5.6 entry contains the keyword 'duplicate'.

Rather, I'm irked that the 5.6 docs don't also contain the old question,
with a "see the 'How can I remove duplicate elements...'" forwarding.

But then I'm being stingy.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Tue, 3 Oct 2000 20:55:55 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: die() ignores tied STDERR?
Message-Id: <Pine.LNX.4.21.0010032050430.8030-100000@hawk.ce.mediaone.net>

On Tue, 3 Oct 2000, Martien Verbruggen quoth:

MV> On 3 Oct 2000 21:45:12 GMT,
MV> 	Daniel Chetlin <daniel@chetlin.com> wrote:
MV> > On Tue, 3 Oct 2000 09:21:23 +1100,
MV> >  Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
MV> > >Ok, apart from pointer abuse with unpack and passing bad stuff to
MV> > >syscall, can anyone think of other things one can do from Perl (not XS
MV> > >or using the Inline stuff) that causes perl to segfault?
MV> > 
MV> > Off the top of my head...
MV> > 
MV> >   [~] $ perl -e'use overload q/""/,sub{"$_[0]"};$r=bless{};print$r'
MV> >   Segmentation fault (core dumped)
MV> >   [~] $ perl -e'sub TIEHASH{bless$_[1]}sub FETCH{shift->{$_[0]}}
MV> >                 tie%h,"main",\%h;$h{a}'
MV> >   Segmentation fault (core dumped)
MV> 
MV> Neither of the two segfault for me (perl 5.005_03 and 5.6.0). They do
MV> emit warnings when run with -w though.

They both segfault for me...

[anm@hawk ~] perl -e'use overload q/""/,sub{"$_[0]"}; \         [pts/3]        
~~           $r=bless{};print$r'
Segmentation fault
[anm@hawk ~] perl -e'sub TIEHASH{bless$_[1]}sub \               [pts/3]
~~           FETCH{shift->{$_[0]}}tie%h,"main",\%h;$h{a}'
Segmentation fault
[anm@hawk ~] perl -v                                            [pts/3]

This is perl, v5.6.0 built for i386-linux

[ snip ]

Regards,

anm
-- 
perl -wMstrict -e '
$a=[[qw[J u s t]],[qw[A n o t h e r]],[qw[P e r l]],[qw[H a c k e r]]];$.++
;$@=$#$a;$$=[reverse sort map$#$_=>@$a]->[$|];for$](--$...$$){for$}($|..$@)
{$$[$]][$}]=$a->[$}][$]]}}$,=$";$\=$/;print map defined()?$_:$,,@$_ for @$'



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

Date: Wed, 04 Oct 2000 08:36:54 +0800
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: error in mapping array slice
Message-Id: <39DA7BA6.7FCF5AD9@email.sps.mot.com>

Martien Verbruggen wrote:
> 
> [Please, for future reference, post your reply AFTER the suitably
> TRIMMED text you reply to. It makes the whole thing much easier to
> follow, and it follows the convention used on this group]

Actually I am not new to c.l.p.m, just got a bit disconnected lately
(about a year :-) Appreciate the reminder though.

> > Jim Mauldin wrote:
> > >
> > > Tk Soh wrote:
> 
> > > > @b = map {$_} @a[-10 .. -1];   # line 2
> 
> [snip]
> 
> > array slicing with non-existing subscripts produces list of undef's. Why
> > puzzles me is why it bombed when this list (of undef's ) was passed to
> > map {$_}, since it simply pass on the value (i.e. undef) as is, with no
> > attempt to modify it. Unless there are undocument feature that I am not
> > aware of, or missed. The fact that $_ is reference to the array elements
> > doesn't justify for that error, IMHO.
> 
> But it does. It means that there have to be values to refer to. That
> means that for $_ to be a reference to $a[-10], there actually has to be
> a $a[-10], so perl will silently DWYM and autovivify it for you. When
> it's trying to do that, it finds out that it can't.
 
[snip]
 
> But don't tell anyone I told you that, and don't actually use it.  Just

I won't tell anyone :-)

> don't use negative subscripts on an array if you don't mean to use them.
> 
> I am almost afraid to ask... Why?

the original intention was to build an array from another with a minimum
number of elements, or "pre-fill" with "" if element value is undefined.
My two-line alternative works, but I thought using map would make the
code more perl'ish:

   @this_array = map {defined? $_ : ''} @that_array[-10, -1];


-TK


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

Date: Tue, 03 Oct 2000 19:57:31 GMT
From: 104073.3433@compuserve.com
Subject: eval(): How do I redirect input?
Message-Id: <8re9tl$bki$1@sshuraab-i-1.production.compuserve.com>
Keywords: eval


If I read in a perl file to an array like this:

@script = <FILE>;

and the script reads from <STDIN>, how do I eval(@script) such that @script's 
input actually comes from some file?

Thanks, Tom


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

Date: Tue, 3 Oct 2000 21:54:18 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: force arithmetic interpretation
Message-Id: <Pine.LNX.4.21.0010032153140.8030-100000@hawk.ce.mediaone.net>

On Tue, 3 Oct 2000, Anders Lund quoth:

AL> ruzbehgonda@my-deja.com wrote:
AL> 
AL> > after dynamically building an arithmetic
AL> > expression
AL> > such as
AL> > $arith = ( (1 * 0) + 1) + 1
AL> > how can i force perl to evaulate the results??
AL> > assigning it to another variable :
AL> > $results = $arith + 1;
AL> > does not work
AL> 
AL> What do you mean??
AL> 
AL> [anders@pluto anders]$ perl -e '$_ = ((1 * 0) + 1) + 1, print, print "\n"'
AL> 2

  When he says "after dynamically building an arithmetic expression", I think
he means something like:

#!/usr/bin/perl -lw
use strict;

my @expr = qw/ ( ( 1 * 0 ) + 1 ) + 1 /;
my $expr = join ' ', @expr;
$expr    = $expr .=  ' + 1';
print eval $expr;

Could be wrong of course.

anm
-- 
perl -wMstrict -e '
$a=[[qw[J u s t]],[qw[A n o t h e r]],[qw[P e r l]],[qw[H a c k e r]]];$.++
;$@=$#$a;$$=[reverse sort map$#$_=>@$a]->[$|];for$](--$...$$){for$}($|..$@)
{$$[$]][$}]=$a->[$}][$]]}}$,=$";$\=$/;print map defined()?$_:$,,@$_ for @$'



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

Date: 4 Oct 2000 03:50:02 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: how to split text by number of words?
Message-Id: <8re9da$hjnma$3@ID-24002.news.cis.dfn.de>

hi,
In comp.lang.perl.misc Firestar <theebh@yahoo.com> wrote:
> Hi, i need to break a long chunk of text into a few paragraphs, each
> paragraph not more than 300 characters, for example. can i use regexp
> for this? TIA.

use Text::Wrap;

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: 4 Oct 2000 03:48:03 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Limiting Form Field Input?
Message-Id: <8re99i$hjnma$2@ID-24002.news.cis.dfn.de>

hi,
In comp.lang.perl.misc Jeff Pinyan <jeffp@crusoe.net> wrote:

> On Oct 3, xlr6drone@my-deja.com said:

>>I have a resume form and I want to prevent the user from inputting more
>>than 250 characters in any of the fields.  For example I need to prevent
>>people from pasting in text that will exceed 250 characters.

> Um, <input type="text" maxlength=250 ...>

hm, i've got a browser that has no input type=text.
it's called libwww-perl.


>>Would it be possible to create a regular expression to handle this?

> This doesn't need to be done on the Perl side of things.  If you wanted
> to, though, why not use the length() function?

i think it *has* to be done (also) on the serverside.
maxlength=250 in the textfield is of course
useful, but doesn't give you a guarantee.

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: Wed, 04 Oct 2000 03:04:43 +0100
From: Steve <m00fbe01@mcmail.comNOSPAM>
Subject: LWP Newbie Question
Message-Id: <39DA903B.40B@mcmail.comNOSPAM>

Hi all,

Can anyone offer any advice/info regarding installing
the LWP module. I'm still a newbie - so pardon me if this
is elementary and not explained well.

I contacted my ISP and asked whether or not the LWP module
for Perl was loaded. They explained that it wasn't but could be
installed locally in a directory in the CGI Bin. 
i.e. in a new directory in my cgi-bin - Firstly is this correct?

Secondly I don't want to mess this up - so do I just download
the module from CPAN then unzip and upload to a directory
in the CGI-Bin. Once this is done direct the script to point
towards the LWP directory?

If the above is not the case and you have to compile this module
in simple terms how do you do this?

BTW I have checked out the readme file at CPAN but could do with
it explained again if possible :)


Many thanks in advance for any assistance given.


Cheers


Steve


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

Date: Tue, 3 Oct 2000 23:05:43 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: MATH problem
Message-Id: <Pine.GSO.4.21.0010032304500.14163-100000@crusoe.crusoe.net>

On Oct 3, F=E9lix Gourdeau said:

>I need a subroutine or a module that accept a long mathematical
>operation like this:
>$input =3D '3+4**5-6*7+(4-5)/4-2';

I'm currently writing a module to parse arbitrary mathematical expressions
(for the purpose of taking their derivatives (!)), but also for simple
parsing and evaluating.

I'll alert the NG when it exists and works.

--=20
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Wed, 04 Oct 2000 03:08:49 GMT
From: eatme@myhouse.com
Subject: PERL CD BOOKSHELF from O'Reilly - Anyone post these CD's Please (In English) Thanks
Message-Id: <39da9efb.277050858@news.igg-tx.net>




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

Date: 4 Oct 2000 02:00:33 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: problems to install perl module
Message-Id: <slrn8tl3q1.slt.clay@panix3.panix.com>

On Tue, 3 Oct 2000 18:02:59 -0500, Bo Pan <bpan99@yahoo.com> wrote:

>I am trying to install XML:Parser on my SGI machine, (IRIX 6.5).  As I
>do not have cc compiler,
>I installed gcc. But when ever I try 'perl Makefile.PL', makefile
>generated still uses cc as
>compiler, and CFlag includes -n32, mip3, etc.
>What should I do to make the Makefile use gcc?

Edit it.

Seriously... Edit the Makefile and change "CC = cc" to "CC = gcc" -- Usually
the Makefile provides comments to make the obvious.

-- 
Clay Irving <clay@panix.com>
Nothing is at last sacred but the integrity of your own mind. 
- Ralph Waldo Emerson 


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

Date: Wed, 04 Oct 2000 01:40:57 GMT
From: Pasquale <pdmos23@geocities.com>
Subject: Re: scripts not working
Message-Id: <39DA8B52.82E2C182@geocities.com>

Jeff Zucker wrote:

> [I have re-arranged this to be in chronological order, in the future,
> please put your responses *after* the message you are responding to,
> thanks]
>
> Pasquale wrote:
> >
> > Jeff Zucker wrote:
> >
> > > Pasquale wrote:
> > > >
> > > > I have some perl scripts I was testing on Hypermart and they were
> > > > working perfectly fine.  I tried them on Freedom 2 Surf  & they are not
> > > > working(Internal Server Error).
> > >
> > > use CGI::Carp qw(fatalsToBrowser);
> >
> > Thanks. I received the following error:
> > Can't locate CGI/Cookie.pm in @INC.....
> > Does this mean they(F2S) do not have or support CGI::Cookie?
>
> It probably means that they are using an ancient version of CGI.pm.
> AFAIK, all recent versions of CGI.pm come with CGI::Cookie as part of
> it.  You could ask them to update their version of CGI.pm (using as an
> inticement the fact that there are known security hazards in older
> versions of the module), or you could install it yourself in your own
> directory.  You could do that with only FTP access since the module does
> not require compilation.   See perlfaq8 "How do I keep my own
> module/library directory" for details.
>
> --
> Jeff

Jeff,
Thanks again. One more question on this and then if it doesn't workout and they
don't update their CGI module, I'll try some other server/site.
<<This the top of my script;
#!/usr/bin/perl

use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use lib "/web/sites/125/username/www.username.f2s.com/cgi-bin";
use CGI::Cookie;
End top of script

After putting in my directory path with the "use lib", the message I am getting
now is:
"Maybe you didn't strip carriage returns after a network transfer".  Does this
mean anything to you?  If I move the "use lib" above "use CGI qw...", I get
internal server error.
Thanks
Pasquale






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

Date: Tue, 03 Oct 2000 18:51:52 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: scripts not working
Message-Id: <39DA8D38.C07B4595@vpservices.com>

Pasquale wrote:
> 
> <<This the top of my script;
> #!/usr/bin/perl
> 
> use strict;
> use CGI qw(:standard);
> use CGI::Carp qw(fatalsToBrowser);
> use lib "/web/sites/125/username/www.username.f2s.com/cgi-bin";
> use CGI::Cookie;
> End top of script
> 
> After putting in my directory path with the "use lib", the message I am getting
> now is:
> "Maybe you didn't strip carriage returns after a network transfer".  Does this
> mean anything to you?  If I move the "use lib" above "use CGI qw...", I get
> internal server error.

Nope, your script looks fine.  (Only thing I'd recommend is a -w on the
top line to help debug).

Here's your problem: carriage returns (the things at the end of lines)
are different on different computers and when you transfer files from
one computer to another, the carriage returns can turn into extra
characters.  Most FTP programs will automatically "do the right thing"
with carriage returns as long as they know that the file that is being
transferred is a text file.  So try FTPing the script and the module you
copied again and making sure that the FTP program knows that they are
text files by specifying "text" or "ascii" transfer.

Keep at it, you're almost there :-).

-- 
Jeff


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

Date: Tue, 03 Oct 2000 18:56:33 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: scripts not working
Message-Id: <39DA8E51.EAFFAE39@vpservices.com>

Jeff Zucker wrote:
> 
> Pasquale wrote:
> >
> > <<This the top of my script;
> > #!/usr/bin/perl
> >
> > use strict;
> > use CGI qw(:standard);
> > use CGI::Carp qw(fatalsToBrowser);
> > use lib "/web/sites/125/username/www.username.f2s.com/cgi-bin";
> > use CGI::Cookie;
> > End top of script
> >
> > After putting in my directory path with the "use lib", the message I am getting
> > now is:
> > "Maybe you didn't strip carriage returns after a network transfer".  Does this
> > mean anything to you?  If I move the "use lib" above "use CGI qw...", I get
> > internal server error.
> 
> Nope, your script looks fine.  (Only thing I'd recommend is a -w on the
> top line to help debug).

On second thought, if you leave "use lib" where it is, you will end up
with two different versions of CGI.pm -- the main module loaded from the
older version on your ISP and the cookie part you loaded yourself.  I am
assuming you loaded all of CGI.pm rather than just the cookie part.  If
so and if you do the stuff with text-mode FTP I recommended in the last
message and you get another error, try moving the "use lib" line up
above "use CGI".

-- 
Jeff


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

Date: Wed, 4 Oct 2000 15:37:35 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: scripts not working
Message-Id: <8re5d1$37t$1@hermes.nz.eds.com>


Pasquale wrote in message <39DA8B52.82E2C182@geocities.com>...

>Jeff,
>Thanks again. One more question on this and then if it doesn't workout and
they
>don't update their CGI module, I'll try some other server/site.
><<This the top of my script;
>#!/usr/bin/perl
>
>use strict;
>use CGI qw(:standard);
>use CGI::Carp qw(fatalsToBrowser);
>use lib "/web/sites/125/username/www.username.f2s.com/cgi-bin";
>use CGI::Cookie;
>End top of script
>
>After putting in my directory path with the "use lib", the message I am
getting
>now is:
>"Maybe you didn't strip carriage returns after a network transfer".  Does
this
>mean anything to you?  If I move the "use lib" above "use CGI qw...", I get
>internal server error.


The message indicates that you didn't FTP the files in ASCII mode.




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

Date: Tue, 3 Oct 2000 22:48:08 -0400
From: "Arthur Dalessandro" <adalessandro@odione.com>
Subject: Search an array
Message-Id: <stl6jdpccmri19@corp.supernews.com>

I am making a script to search through FTP log files, pull the IP address
from each line, then add that IP address to an array if it isn't already
there.  Then write the output to another log file.  Problem is how to search
the entire array for a string, to see if it exists, without going through
all the
for i -> x
    @test[i];
etc..

-art




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

Date: 03 Oct 2000 21:51:18 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Search an array
Message-Id: <87zoklnwt5.fsf@limey.hpcc.uh.edu>

>> On Tue, 3 Oct 2000 22:48:08 -0400,
>> "Arthur Dalessandro" <adalessandro@odione.com> said:

> I am making a script to search through FTP log files,
> pull the IP address from each line, then add that IP
> address to an array if it isn't already there.  Then
> write the output to another log file.  Problem is how to
> search the entire array for a string, to see if it
> exists, without going through all the for i -> x
> @test[i]; etc..

You're making a "hash" of this :-)

Try "perldoc -q array"

    How can I tell whether a list or array contains a
    certain element?

hth
t
-- 
Namaste!
And an "oogabooga" to you too!
                                         -- Homer Simpson


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

Date: Wed, 4 Oct 2000 12:24:25 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Search an array
Message-Id: <uXwC5.14$mI3.2609@vic.nntp.telstra.net>

"Arthur Dalessandro" <adalessandro@odione.com> wrote in message
news:stl6jdpccmri19@corp.supernews.com...
> I am making a script to search through FTP log files, pull the IP
address
> from each line, then add that IP address to an array if it isn't
already
> there.  Then write the output to another log file.  Problem is how to
search
> the entire array for a string, to see if it exists, without going
through
> all the
> for i -> x
>     @test[i];
> etc..
>

How about adding them as the keys to a hash, which ensures that they
will always be unique?

--
Wyzelli
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: Tue, 3 Oct 2000 22:33:02 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: Search an array
Message-Id: <Pine.LNX.4.21.0010032226110.8151-100000@hawk.ce.mediaone.net>

On Tue, 3 Oct 2000, Arthur Dalessandro quoth:

AD> I am making a script to search through FTP log files, pull the IP address
AD> from each line, then add that IP address to an array if it isn't already
AD> there.  Then write the output to another log file.  Problem is how to search
AD> the entire array for a string, to see if it exists, without going through
AD> all the
AD> for i -> x
AD>     @test[i];
AD> etc..

Use grep.

#!/usr/bin/perl -w
use strict;

my @array = qw/ foo bar baz /;

if (grep /^foo$/ => @array) {
    print "we have foo!\n";
}
else {
    print "no foo here!\n";
}

anm
-- 
perl -wMstrict -e '
$a=[[qw[J u s t]],[qw[A n o t h e r]],[qw[P e r l]],[qw[H a c k e r]]];$.++
;$@=$#$a;$$=[reverse sort map$#$_=>@$a]->[$|];for$](--$...$$){for$}($|..$@)
{$$[$]][$}]=$a->[$}][$]]}}$,=$";$\=$/;print map defined()?$_:$,,@$_ for @$'



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

Date: Wed, 04 Oct 2000 03:40:54 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Search an array
Message-Id: <stl9m61l76lafa@corp.supernews.com>

Arthur Dalessandro (adalessandro@odione.com) wrote:
: I am making a script to search through FTP log files, pull the IP address
: from each line, then add that IP address to an array if it isn't already
: there.  Then write the output to another log file.

Use a hash instead.  Pseudocode:

  while (<LOG>) {
    $ip = getTheIPSomehow($_);
    $ips{$ip}++;
  }

That results in the hash %ips having as keys all the unique IP addresses
encountered, and as a side bonus the value for each key is the number of
times it appeared.  You can then sort the keys as desired and print them
out.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


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

Date: Tue, 03 Oct 2000 20:53:08 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Search an array
Message-Id: <39DAA9A4.DDBA13A8@stomp.stomp.tokyo>

Arthur Dalessandro wrote:
 
> I am making a script to search through FTP log files, pull the IP address
> from each line, then add that IP address to an array if it isn't already
> there.  Then write the output to another log file.  Problem is how to search
> the entire array for a string, to see if it exists, without going through
> all the
> for i -> x
>     @test[i];


Slurp your data base as a single line string and index.
A data base of pure numbers and delimiters can't be all
this big. Quarter of meg, less, string it and index. Add
IP addresses as needed then write a new file. Really no
need for an array.

Which is faster, iterating an array or indexing a string?
From a human perspective, from a realistic perspective,
neither. How much actual time will you save? Enough to
go have lunch? Highly unlikely. Are you sure you even
want to bother with making a decision on this? Might
be easier to flip a coin and write your script. During
this time you wait for responses on this, you could
write your script and be done.


Godzilla!


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

Date: Wed, 04 Oct 2000 02:59:21 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: some questions
Message-Id: <stl789i0ogoq8c@corp.supernews.com>

zoo.tv@btinternet.com wrote:
: Use s/// for this.
: 
: foreach (@line) {
:   s/\"//g;
: }

Spurious \, less efficient than tr.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


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

Date: Wed, 04 Oct 2000 01:27:36 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Strange behavior with DESTROY and END
Message-Id: <39DA878E.F1A34EBA@rochester.rr.com>

sh_kell@my-deja.com wrote:
> 
> Ok, I have run into an interesting situation within a simple Test.pm
> using a test.pl to run it (Perl 5.005_03; Redhat Linux 6.0). It seems
> that depending on how I instantiate the object it affects the order of
> execution of the DESTROY and END blocks. It was my understanding that
> END{ } was ALWAYS executed right before program exit.
> 
> Now what I am seeing is that if I do:
> 
> $obj = new Test;
> 
> Then END is called before DESTROY
> 
> If I do:
> 
> my $obj = new Test;
> 
> then it executes in what is suppose to be the proper order... DESTROY
> then END
> 
> I am just wondering if this is suppose to occur as such, is a bug in
> Perl itself, is a bug in OS/Perl combo, or I messed something up?
> 
> ----------------------------------------------------------------------
> Test.pm
> ----------------------------------------------------------------------
> 
> package Test;
> 
> BEGIN{
>     print __PACKAGE_, " BEGIN\n";
> }
> 
> sub new(){
>     my $class = shift;
>     my $self = bless {}, ref($class) || $class;
>     print __PACKAGE__, " NEW\n";
>     return $self;
> }
> 
> DESTROY{
>     print __PACKAGE__, " DESTROY\n";
> }
> 
> END{
>     print __PACKAGE__, " END\n";
> }
> 
> 1;
> ----------------------------------------------------------------
> test.pl
> ---------------------------------------------------------------
> 
> use Test;
> 
> $test = new Test;
> 
> -----------------------------------------------------------------
> 
> THis gives output of:
> 
> Test BEGIN
> Test NEW
> Test END
> Test DESTROY

Really???  It won't even compile.  When adding the second _ after
PACKAGE in the BEGIN block, it then replicates your results.

> 
> ----------------------------------------------------------------
> 
> Change to:
> 
> my $test = new Test;
> 
> and output is:
> 
> ------------------------------------------------------------------
> 
> Test BEGIN
> Test NEW
> Test DESTROY
> Test END
> 
> Any insight into this would be greatly appreciated. Thank you.

Well, the DESTROY method gets called when an object gets destroyed. 
Destruction of the lexical variable my $test occurs when $test goes out
of scope.  That is right after it is created, and before the program
ends.  The global variable $test, on the other hand, persists until it
is destroyed in the END processing.  To see this even more clearly, add
a block around the my $test=... and a print statement afterwards, like
so:

   use Test;
   {
      my $testlexical=new Test;
      $testglobal=new Test;
   }
   print "Hi from after the block\n";

-- 
Bob Walton


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

Date: Wed, 04 Oct 2000 02:51:31 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Testing for numeric integer
Message-Id: <39da994c.464956@news.newsguy.com>

Ren Maddox <ren.maddox@tivoli.com> wrote:

>Which leads to the way I usually handle this, which is to have an
>allowed range and check for that.  Then the need to check for a valid
>number is completely removed, as the numeric comparison will take care
>of that for you (assuming you are excluding 0).
>
>if($number < 1 or $number > 99) {
>  # out of range
>}

But you'll need to do something before it like

    $number =~ tr/0-9//cd;

or

    $number =~ s/.*?(\d*).*/$1/s;

and then

    $number ||= 0;

if you want to avoid warnings and deal with things like 1.5.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

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


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