[23684] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5891 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 4 09:05:54 2003

Date: Thu, 4 Dec 2003 06:05:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 4 Dec 2003     Volume: 10 Number: 5891

Today's topics:
        A problem while testing MPEG-LibMPEG3-0.01 (xern)
        Can you tell me how to change from regular Perl to Mod_ <Temp@NoSuchDomain.Info>
    Re: Can you tell me how to change from regular Perl to  <Temp@NoSuchDomain.Info>
    Re: Can you tell me how to change from regular Perl to  <tore@aursand.no>
    Re: Can you tell me how to change from regular Perl to  <tom@nosleep.net>
    Re: Can you tell me how to change from regular Perl to  (Malcolm Dew-Jones)
    Re: Can you tell me how to change from regular Perl to  <tore@aursand.no>
    Re: Can you tell me how to change from regular Perl to  <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: Descending sort <colossus_NOSPAM_@freemail.it>
    Re: Descending sort (Anno Siegel)
    Re: Descending sort <tore@aursand.no>
    Re: Descending sort <colossus_NOSPAM_@freemail.it>
    Re: Descending sort <peter@semantico.com>
    Re: Don't Read - Testing <Paul@Hovnanian.com>
        foreach counter <chatasos@yahoo.com>
    Re: foreach counter <tore@aursand.no>
    Re: foreach counter <carsten@welcomes-you.com>
    Re: Generating Day of Week in Pure Perl <bart.lateur@pandora.be>
    Re: Generating Day of Week in Pure Perl <tore@aursand.no>
    Re: Generating Day of Week in Pure Perl (Tad McClellan)
    Re: In search of elegant code: is variable is within a  (Rafael Garcia-Suarez)
        Is perl 5.8 slower than 5.005_03? (Jon Reed)
        My apologizes (Was: Descending sort) <colossus_NOSPAM_@freemail.it>
    Re: My apologizes (Was: Descending sort) <HelgiBriem_1@hotmail.com>
        newbie creating test help (John)
    Re: newbie creating test help (Anno Siegel)
    Re: return the array index for a given value (Anno Siegel)
    Re: return the array index for a given value (Anno Siegel)
    Re: Starting Perl Script at Bootup <Paul@Hovnanian.com>
    Re: UDP Log & CPU Usage (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 4 Dec 2003 04:47:02 -0800
From: xern@cpan.org (xern)
Subject: A problem while testing MPEG-LibMPEG3-0.01
Message-Id: <297c4cc7.0312040447.1fedac3d@posting.google.com>

The error message is as follows.

Can't load 'blib/arch/auto/MPEG/LibMPEG3/LibMPEG3.so' for module
MPEG::LibMPEG3:
blib/arch/auto/MPEG/LibMPEG3/LibMPEG3.so: undefined symbol:
mpeg3_seek_percentage at
/usr/local/lib/perl5/5.8.1/i686-linux/DynaLoader.pm line 229. at
test.pl line 18

I've got libmpeg3.a successfully installed, and have written a C
program to test libmpeg3, which was good. I'm curious about why this
error would happen. The author's email seems broken, so I cannot reach
him for the answer. Hope someone can give me the solution.

Thanks in advance.


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

Date: Thu, 04 Dec 2003 05:30:47 GMT
From: "Picker Leon" <Temp@NoSuchDomain.Info>
Subject: Can you tell me how to change from regular Perl to Mod_perl
Message-Id: <bEzzb.147687$Ec1.5903163@bgtnsc05-news.ops.worldnet.att.net>

Do I just simple add a
use mod_perl;
then all my old perl program can work with mod_perl?

Any sample code is ok.

I looked at perl.apache.org, but could not find any sample codes.




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

Date: Thu, 04 Dec 2003 05:33:50 GMT
From: "Picker Leon" <Temp@NoSuchDomain.Info>
Subject: Re: Can you tell me how to change from regular Perl to Mod_perl
Message-Id: <2Hzzb.147696$Ec1.5898820@bgtnsc05-news.ops.worldnet.att.net>

My webhost allows mod_perl and there is a perl dir in the html dir and I was
told that is where I put my mod_perl scripts to. I don't understand it. Do I
have to use mod_perl only in certain dir but not in all dir? I can use perl
in all dir now. Not sure if mod_perl is part of perl or part of apache.

> Do I just simple add a
> use mod_perl;
> then all my old perl program can work with mod_perl?
>
> Any sample code is ok.
>
> I looked at perl.apache.org, but could not find any sample codes.
>
>




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

Date: Thu, 04 Dec 2003 07:31:33 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Can you tell me how to change from regular Perl to Mod_perl
Message-Id: <pan.2003.12.04.06.19.34.824198@aursand.no>

On Thu, 04 Dec 2003 05:30:47 +0000, Picker Leon wrote:
> Do I just simple add a
> use mod_perl;
> then all my old perl program can work with mod_perl?

No.  Please read the documentation on http://perl.apache.org/ before you
continue asking.  There's even a document describing how to migrate from
CGI to mod_perl on that site.

> I looked at perl.apache.org, but could not find any sample codes.

That's bullshit, actually.  No more, no less.


-- 
Tore Aursand <tore@aursand.no>
"Fighting terrorism is like being a goalkeeper. You can make a hundred
 brilliant saves but the only shot that people remember is the one that
 gets past you." -- Paul Wilkinson


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

Date: Wed, 3 Dec 2003 23:22:11 -0800
From: "Tom" <tom@nosleep.net>
Subject: Re: Can you tell me how to change from regular Perl to Mod_perl
Message-Id: <3fceed91$1@nntp0.pdx.net>


what the f is mod perl anway?




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

Date: 3 Dec 2003 23:55:32 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Can you tell me how to change from regular Perl to Mod_perl
Message-Id: <3fcee874@news.victoria.tc.ca>

Tom (tom@nosleep.net) wrote:

: what the f is mod perl anway?

That's mod_perl (note _) as in "google mod_perl".



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

Date: Thu, 04 Dec 2003 09:03:26 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Can you tell me how to change from regular Perl to Mod_perl
Message-Id: <pan.2003.12.04.08.02.44.252769@aursand.no>

On Wed, 03 Dec 2003 23:22:11 -0800, Tom wrote:
> what the f is mod perl anway?

Read the documentation next time.  Don't know where to start?  Google
should get you off, and the link to http://perl.apache.org/ in my previous
post should give you a clue.

For now, 'perldoc mod_perl' gives me this (and a lot more):

  The Apache/Perl integration project brings together the full power of
  the Perl programming language and the Apache HTTP server.  This is
  achieved by linking the Perl runtime library into the server and pro-
  viding an object oriented Perl interface to the server's C language
  API.  These pieces are seamlessly glued together by the `mod_perl'
  server plugin, making it is possible to write Apache modules entirely
  in Perl.  In addition, the persistent interpreter embedded in the
  server avoids the overhead of starting an external interpreter and the
  penalty of Perl start-up (compile) time.

In short, there are two major benefits from using mod_perl:

  1. Speed (no need to load the Perl interpreter for each request)
  2. Integration with the Apache web-server


-- 
Tore Aursand <tore@aursand.no>
"I am become Death, shatterer of worlds." -- J. Robert Oppenheimer,
 upon witnessing the explosion of the first atomic bomb.


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

Date: Thu, 4 Dec 2003 00:00:51 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Can you tell me how to change from regular Perl to Mod_perl
Message-Id: <jjpmqb.86a.ln@goaway.wombat.san-francisco.ca.us>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

On 2003-12-04, Picker Leon <Temp@NoSuchDomain.Info> wrote:
> Do I just simple add a
> use mod_perl;
> then all my old perl program can work with mod_perl?

No.  Read (carefully this time) the docs at perl.apache.org.

> I looked at perl.apache.org, but could not find any sample codes.

mod_perl involves more than just code.  Go back and read the docs.

- --keith

- -- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/zumghVcNCxZ5ID8RAnD8AJsEFFK5Nggx8vUaSagVHhxJgLCc4QCeOuPz
BT9vCF7G2FYd4EKvznrkGu0=
=rSyG
-----END PGP SIGNATURE-----


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

Date: Thu, 04 Dec 2003 10:49:44 +0100
From: Colossus <colossus_NOSPAM_@freemail.it>
Subject: Re: Descending sort
Message-Id: <bqmvsq$22kimd$1@ID-154800.news.uni-berlin.de>

Tore Aursand wrote:

> Well.  You don't actually tell us the criteria for your sorting, but it
> seems to me that you'd like to sort the numeric value of column 5, then by
> column 3, in a descending order.
> 
> For that, use Sort::Fields from CPAN.
> 
I think that the obvious things are very difficult to understand. From my
example is very clear that I want to sort from the last field in descending
sort.
-- 
Bye,
Colossus



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

Date: 4 Dec 2003 11:15:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Descending sort
Message-Id: <bqn517$8p7$2@mamenchi.zrz.TU-Berlin.DE>

Colossus  <colossus_NOSPAM_@freemail.it> wrote in comp.lang.perl.misc:
> Tore Aursand wrote:
> 
> > Well.  You don't actually tell us the criteria for your sorting, but it
> > seems to me that you'd like to sort the numeric value of column 5, then by
> > column 3, in a descending order.
> > 
> > For that, use Sort::Fields from CPAN.
> > 
> I think that the obvious things are very difficult to understand. From my
> example is very clear that I want to sort from the last field in descending
> sort.

Talk about proud answers.

Your example makes *nothing* clear.  As has been discussed in this thread,
the result can be derived from the original through sorting by columns 1
and 5, or by columns 3 and 5.  Are you reading the thread at all?

Anno


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

Date: Thu, 04 Dec 2003 12:27:16 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Descending sort
Message-Id: <pan.2003.12.04.11.26.43.757422@aursand.no>

On Thu, 04 Dec 2003 10:49:44 +0100, Colossus wrote:
>> Well.  You don't actually tell us the criteria for your sorting, but it
>> seems to me that you'd like to sort the numeric value of column 5, then by
>> column 3, in a descending order.
>> 
>> For that, use Sort::Fields from CPAN.

> I think that the obvious things are very difficult to understand. From
> my example is very clear that I want to sort from the last field in
> descending sort.

First of all you don't say that in your post.  Secondly, your example of
how you want the sorted data to be doesn't conform to the rule of sorting
the last column in a descending order.

Take a look at what you wrote:

  > I have a flat database file this way:
  > 
  > A00469.PE1      SSGGH.PE1       HBG011318       1.26943 39
  > A00469.PE1      SGGH2.PE1       HBG011318       1.26943 110
  > A14829.PE1      SSAPOLAI.PE1    HBG004257       1.88791 39
  > A14829.PE1      DRAPLIPAI.PE1   HBG004257       1.96625 386
  > A14829.PE1      AF042219.PE1    HBG004257       2.03983 110
  > 
  > The fields are tab separated. I want it this way:
  > A00469.PE1      SGGH2.PE1       HBG011318       1.26943 110
  > A00469.PE1      SSGGH.PE1       HBG011318       1.26943 39
  > A14829.PE1      DRAPLIPAI.PE1   HBG004257       1.96625 386
  > A14829.PE1      AF042219.PE1    HBG004257       2.03983 110
  > A14829.PE1      SSAPOLAI.PE1    HBG004257       1.88791 39

As I hope you can see, the data _IS NOT_ sorted in a descending order.

Desperatly trying to humanly parse your data, I think the latter data is
sorted on column 3 (descending) and then on column 5 (descending).

And - again - you can use Sort::Fields for that.  And - again - please
express yourself _much_ clearer next time you want _us_ to understand what
you _actually_ means.


-- 
Tore Aursand <tore@aursand.no>
"A car is not the only thing that can be recalled by its maker." --
 Unknown


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

Date: Thu, 04 Dec 2003 12:41:41 +0100
From: Colossus <colossus_NOSPAM_@freemail.it>
Subject: Re: Descending sort
Message-Id: <bqn6eo$24kaf3$3@ID-154800.news.uni-berlin.de>

Tore Aursand wrote:

>   > The fields are tab separated. I want it this way:
>   > A00469.PE1      SGGH2.PE1       HBG011318       1.26943 110
>   > A00469.PE1      SSGGH.PE1       HBG011318       1.26943 39
>   > A14829.PE1      DRAPLIPAI.PE1   HBG004257       1.96625 386
>   > A14829.PE1      AF042219.PE1    HBG004257       2.03983 110
>   > A14829.PE1      SSAPOLAI.PE1    HBG004257       1.88791 39
> 
> As I hope you can see, the data _IS NOT_ sorted in a descending order.

You are right.
-- 
Bye,
Colossus



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

Date: Thu, 04 Dec 2003 12:24:20 +0000
From: Peter Hickman <peter@semantico.com>
Subject: Re: Descending sort
Message-Id: <3fcf2774$0$13905$afc38c87@news.easynet.co.uk>

Colossus wrote:
> Tore Aursand wrote:
> 
> 
>>  > The fields are tab separated. I want it this way:
>>  > A00469.PE1      SGGH2.PE1       HBG011318       1.26943 110
>>  > A00469.PE1      SSGGH.PE1       HBG011318       1.26943 39
>>  > A14829.PE1      DRAPLIPAI.PE1   HBG004257       1.96625 386
>>  > A14829.PE1      AF042219.PE1    HBG004257       2.03983 110
>>  > A14829.PE1      SSAPOLAI.PE1    HBG004257       1.88791 39
>>
>>As I hope you can see, the data _IS NOT_ sorted in a descending order.
> 
> 
> You are right.

Now you say. The best I could come up with was that it was sorted on column 1 
(or 3) as text ascending and 5 as numbers descending. Which gives us the 
following beginners code.

#!/usr/bin/perl

use strict;
use warnings;

my @biglist;

while(my $line = <DATA>) {
         push(@biglist, [split('\t', $line)] );
}

my @newlist = sort {
         $a->[0] cmp $b->[0]
         or
         $b->[4] <=> $a->[4]
         } @biglist;

foreach my $line (@newlist) {
         print join("\t", @{$line});
}


__DATA__
A00469.PE1      SSGGH.PE1       HBG011318       1.26943 39
A00469.PE1      SGGH2.PE1       HBG011318       1.26943 110
A14829.PE1      SSAPOLAI.PE1    HBG004257       1.88791 39
A14829.PE1      DRAPLIPAI.PE1   HBG004257       1.96625 386
A14829.PE1      AF042219.PE1    HBG004257       2.03983 110

Which gives:

A00469.PE1      SGGH2.PE1       HBG011318       1.26943 110
A00469.PE1      SSGGH.PE1       HBG011318       1.26943 39
A14829.PE1      DRAPLIPAI.PE1   HBG004257       1.96625 386
A14829.PE1      AF042219.PE1    HBG004257       2.03983 110
A14829.PE1      SSAPOLAI.PE1    HBG004257       1.88791 39



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

Date: Wed, 03 Dec 2003 22:46:43 -0800
From: "Paul Hovnanian P.E." <Paul@Hovnanian.com>
Subject: Re: Don't Read - Testing
Message-Id: <3FCED853.50BD5DB@Hovnanian.com>

Tad McClellan wrote:
> 
> Alquemius <Alquemius@hotmail.com> wrote:

[snip]
 
> > the main
> > subject of every mail i post
> 
> mail does not go to Usenet newsgroups.
> 
> This is not email.

From the OP's headers:
 
X-Newsreader: Microsoft Outlook Express

This may explain the confusion.

-- 
Paul Hovnanian     mailto:Paul@Hovnanian.com
note to spammers:  a Washington State resident
------------------------------------------------------------------
I have a very firm grasp on reality. I can reach out and strangle it any
time!


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

Date: Thu, 04 Dec 2003 15:26:02 +0200
From: Tassos <chatasos@yahoo.com>
Subject: foreach counter
Message-Id: <1070544455.953113@athprx02>

Is there a special var (like $_) which contains the number of the current loop?

so instead of :

foreach $i (1..$#array) {
         $array[$i] = "0";
	print $i;
}


we can do :

foreach (@array) {
	$_ = "0";
	print $x;	# where x should be equal to $i in the above example
}	



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

Date: Thu, 04 Dec 2003 14:33:11 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: foreach counter
Message-Id: <pan.2003.12.04.13.33.11.436295@aursand.no>

On Thu, 04 Dec 2003 15:26:02 +0200, Tassos wrote:
> Is there a special var (like $_) which contains the number of the
> current loop?

Not that I'm aware of (never needed it), but when reading files you can do
something like this;

  while ( <FILE> ) {
      print 'This is line #' . $. . "\n";
  }


-- 
Tore Aursand <tore@aursand.no>
"A car is not the only thing that can be recalled by its maker." --
 Unknown


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

Date: Thu, 04 Dec 2003 14:35:59 +0100
From: Carsten Aulbert <carsten@welcomes-you.com>
Subject: Re: foreach counter
Message-Id: <bqnd8n$22r2rj$1@ID-213226.news.uni-berlin.de>



Tassos wrote:

> we can do :
> 
> foreach (@array) {
>     $_ = "0";
>     print $x;    # where x should be equal to $i in the above example
> }   
> 
I suppose there is a misconception here, since $_ indeed contains the 
current "value" (not index <- what you probably meant by number):

foreach (@array) {
   print $_, "\t";
}

will print all occurences in @array (even though 'join' would probably be 
faster), but I think what you want is changing the values in @array which 
is only possible as you described in your first example or by using a hash 
(AFAIK).

Sorry

Carsten


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

Date: Thu, 04 Dec 2003 08:24:52 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Generating Day of Week in Pure Perl
Message-Id: <9prtsvk8n3s9o0h8dj8vs8gajk119ii1bh@4ax.com>

Iain Truskett wrote:

>* rev <rev@TheWaterCooler.com>:
>
>> I cannot use the POSIX package.
>
>Why?

For the same reason he can't use any other module. The ISP probably
deleted it and isn't willing to install it again.

-- 
	Bart.


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

Date: Thu, 04 Dec 2003 12:27:16 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Generating Day of Week in Pure Perl
Message-Id: <pan.2003.12.04.09.11.31.913321@aursand.no>

On Thu, 04 Dec 2003 08:24:52 +0000, Bart Lateur wrote:
>>> I cannot use the POSIX package.

>> Why?

> For the same reason he can't use any other module. The ISP probably
> deleted it and isn't willing to install it again.

Why would an ISP delete a module that comes with Perl?


-- 
Tore Aursand <tore@aursand.no>
"I know not with what weapons World War 3 will be fought, but World War
 4 will be fought with sticks and stones." -- Albert Einstein


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

Date: Thu, 4 Dec 2003 07:02:32 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Generating Day of Week in Pure Perl
Message-Id: <slrnbsuc38.5rc.tadmc@magna.augustmail.com>

Tore Aursand <tore@aursand.no> wrote:
> On Thu, 04 Dec 2003 08:24:52 +0000, Bart Lateur wrote:
>>>> I cannot use the POSIX package.
> 
>>> Why?
> 
>> For the same reason he can't use any other module. The ISP probably
>> deleted it and isn't willing to install it again.
> 
> Why would an ISP delete a module that comes with Perl?
               ^^^


The "S" often stands for "silly" rather than for "service".  :-(


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 04 Dec 2003 08:33:30 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: In search of elegant code: is variable is within a range???
Message-Id: <slrnbsts4o.pas.rgarciasuarez@rafael.serd.lyon.hexaflux.loc>

Ben Morrow wrote:
>>     if(abs($foo-5.5)<4.5){blah blah...
>
>You clearly have a different idea of 'elegant' from me... :)
>
>I would have said
>  if(grep /$foo/, 1..10) {
>before that...

This doesn't work at all. What if $foo is 2.47 ? What if $foo is ".1" ?
What if $foo is 0 ?

-- 
Unfinished is not *NIX


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

Date: 4 Dec 2003 05:50:10 -0800
From: jreed@ptc.com (Jon Reed)
Subject: Is perl 5.8 slower than 5.005_03?
Message-Id: <21cca72e.0312040550.128bd53d@posting.google.com>

Is perl 5.8 slower than perl 5.005_03 ?


We rebuilt one of three webserver machines with solaris 5.8 and added
perl 5.8 using
	./Configure -des -Dusethreads -Dcc='gcc -B/usr/ccs/bin/'

(The old configuration was Solaris 5.6 with perl 5.005_03)

I noticed that our website seemed slower with this new configuration. 
Using Apache Benchmark confirmed that it was slower.  Next step was to
eliminate the webserver, so executing a simple perl script 1000 times
direct from the command line took about 30 seconds with perl 5.8. 
Then I copied the perl 5.005_03 binary over from a very similar
machine (that has not been rebuilt yet) and it takes 16 seconds for
the same test!!

This is consistent with the behavior I am seeing where anything using
perl on the new machine is slower.

Then I installed perl 5.8 as a package from sunfreeware and the same
test takes about 30 seconds.  Consistent with my other install of 5.8.

Also,
The 5.005_03 is --> version 5.005_03 built for sun4-solaris
The 5.8 package is --> v5.8.0 built for sun4-solaris
The 5.8 that I compiled is --> v5.8.0 built for
sun4-solaris-thread-multi

Given that both 5.8 installs were significantly longer in my tests, I
don't think the multi-thread makes a difference at this point.

Is perl 5.8 slower than 5.005_03?  Does anyone have any tips for
enhancing the performance of perl?  Is there a switch or something in
the config I was supposed to set?

Any other ideas why I am seeing such a degradation in performance of
perl with this new version?

Thanks in advance.

Jon Reed


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

Date: Thu, 04 Dec 2003 12:46:10 +0100
From: Colossus <colossus_NOSPAM_@freemail.it>
Subject: My apologizes (Was: Descending sort)
Message-Id: <bqn6n4$24kaf3$4@ID-154800.news.uni-berlin.de>

Hi,

I realized that my example was not clear.
I apologize toward all who replied me. The problem
was mine. An alphabetical order was needed on first column.
Please accept my deepest apologizes.

I have appreciated the answers given by all of you,
in particular the one of Anno who solved my problem.
-- 
Bye,
Colossus



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

Date: Thu, 04 Dec 2003 13:15:45 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: My apologizes (Was: Descending sort)
Message-Id: <cpcusv4nc0145uftm3tonh91ueakqgjmms@4ax.com>

On Thu, 04 Dec 2003 12:46:10 +0100, Colossus
<colossus_NOSPAM_@freemail.it> wrote:

>I realized that my example was not clear.
>I apologize toward all who replied me. The problem
>was mine. An alphabetical order was needed on first column.
>Please accept my deepest apologizes.
>
>I have appreciated the answers given by all of you,
>in particular the one of Anno who solved my problem.

It's pretty late for that after having insulted almost
everyone who might have a shot at solving your
problem.  Most of them have already killfiled you
and will never see anything you post, ever again.

Such is life.


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

Date: 4 Dec 2003 03:50:50 -0800
From: news2003@wanadoo.es (John)
Subject: newbie creating test help
Message-Id: <3bd6db81.0312040350.3ca0c8ea@posting.google.com>

Hi,


I am trying to create a test for my module and I would like to know
how to test this:


my $input = [ 
     '123',
     '456'];

my $output = [
     ['1', '2', '3'],
     ['4', '5', '6']];

I have a method that returns the reference to the array of array after
splitting it.


but when I try to make the test for that:

ok $obj->splitted eq $output;


I get:

not ok 2
# Failed test 2 in Example.t at line 68

How do I check if the values hold by the reference are the same?


Thanks in advance for your help.
John


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

Date: 4 Dec 2003 12:11:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: newbie creating test help
Message-Id: <bqn88u$aj9$2@mamenchi.zrz.TU-Berlin.DE>

John <news2003@wanadoo.es> wrote in comp.lang.perl.misc:
> Hi,
> 
> 
> I am trying to create a test for my module and I would like to know
> how to test this:
> 
> 
> my $input = [ 
>      '123',
>      '456'];
> 
> my $output = [
>      ['1', '2', '3'],
>      ['4', '5', '6']];
> 
> I have a method that returns the reference to the array of array after
> splitting it.
> 
> 
> but when I try to make the test for that:
> 
> ok $obj->splitted eq $output;
> 
> 
> I get:
> 
> not ok 2
> # Failed test 2 in Example.t at line 68

Sure.  "eq" compares strings.  If you print the two references, they
look different.

> How do I check if the values hold by the reference are the same?

Use "Test::More", it has a utility for that:

    
    ok( eq_array( $obj->splitted, $output));

should do it.

Oh, and the past tense of "split" is "split", not "splitted".  Of
course, you can call your methods anything you like... :)

Anno


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

Date: 4 Dec 2003 08:11:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: return the array index for a given value
Message-Id: <bqmq8f$1gn$1@mamenchi.zrz.TU-Berlin.DE>

Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > Edo  <eddGallary2@hotmail.com> wrote in comp.lang.perl.misc:
> >> Edo wrote:
> 
> >> > is there a ready perl function to return the index of a given value in 
> >> > an array?
> 
> > If you are happy to take the first index, and accept an undef if there
> > isn't one, this would be idiomatic (untested):
>                                       ^^^^^^^^
>                                       ^^^^^^^^ right :-)
> 
> >     my ( $first_index) = grep $_ eq $value, @array;
> 
> 
> I think you meant:
> 
>     my($first_index) = grep $array[$_] eq $value, 0..$#array;

Ack.

Anno


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

Date: 4 Dec 2003 08:12:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: return the array index for a given value
Message-Id: <bqmq9v$1gn$2@mamenchi.zrz.TU-Berlin.DE>

Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
> 
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> >     my %invert;
> >     @invert[ @array] = 0 .. $#array;
> 
> ITYM { } :)

Ack.

Anno


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

Date: Wed, 03 Dec 2003 22:38:03 -0800
From: "Paul Hovnanian P.E." <Paul@Hovnanian.com>
Subject: Re: Starting Perl Script at Bootup
Message-Id: <3FCED64B.4139A297@Hovnanian.com>

Josef Möllers wrote:
> 
> Matt wrote:
> >
> > I have a perl script I would like to have run every time my server boots up.
> > Its running Redhat Linux.  How would I do that?
> 
> It depends on at what stage of the boot process you want to run the
> script and whether or not the directories needed are available (i.e.
> mounted).
> 
> There are several (os-related, as Ted already said) issues regarding
> where to put the call of the script, but in general, there's no reason
> why it should not work.
> You might want to look at the /etc/rc.d directory tree. Just try adding
> your script somewhere in that tree and see what happens. There's little
> chance your machine will blow up if something goes wrong (unless, of
> course, you fiddle around with the connection to the nuclear power plant
> your machine controls).

Whether it works or not (in the /etc/rc.d tree) depends on whether the
resources needed to run your particular perl script (the perl executable
plus libraries) have been mounted yet. If they're where perl and your
script expect them to be, it should work just fine.

Of course, if your script does networking, it will have to run after
networking is started.

-- 
Paul Hovnanian     mailto:Paul@Hovnanian.com
note to spammers:  a Washington State resident
------------------------------------------------------------------
Happily doing the work of 3 Men ... Moe, Larry & Curly


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

Date: 4 Dec 2003 11:52:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: UDP Log & CPU Usage
Message-Id: <bqn76c$aj9$1@mamenchi.zrz.TU-Berlin.DE>

Matt <nospam.hciss@yahoo.com> wrote in comp.lang.perl.misc:
> I wrote the below UDP logger.  The syslog in Linux did not do what I wanted
> so I wrote this.  Its supposed to fork and stay resident.  Seems to work
> fine.  My question is how much CPU will it use?  Is it going to be a real
> hog being it just loops through constantly?

Don't worry.  Most of the time it will hang in $sock->recv(...) and
not consume time.

>                                              Is this a bad way to do it?
> Also, where I use: "gethostbyaddr($ipaddr, AF_INET)" I would rather just use
> the IP source address but could not figure out how to do that.

What is the "IP source address"?

> #!/usr/bin/perl -w
> #udp logging
> use IO::Socket;
> use LWP::Simple;
> use Time::localtime;
> close(STDIN);
> close(STDOU);
> close(STDERR);
> exit if (fork());
> exit if (fork());
> while (1){

This outer loop seems to be useless.  If the inner loop ever ends, you
die anyway.  *If* the loop is there, its block should be indented.

> my($sock, $msg, $PORTNO, $LPATH);

Lexicals, good.  This would run under strict.

> $PORTNO = 5151;

Why isn't this also a lexical?

> $LPATH = "/home/logs/";
> $sock = IO::Socket::INET->new(LocalPort => $PORTNO, Proto => 'udp')
>         or die "socket: $@";

 ...and these?  All variables should be declared with "my", unless there
is a reason.  Switch on "strict" and "warnings", they help you find errors.

> print "awaiting UDP messages on port $PORTNO\n";
> while ($sock->recv($msg, 1024)) {
>         $tm = localtime;

From HERE...

>         ($hour, $minute, $sec, $day, $month, $year) = ($tm->hour, $tm->min,
> $tm->sec, $tm->mday, $tm->mon, $tm->year);
>         $year = ($year+1900);
>         $month = ($month+1);
>         if ($hour < 10){
>                 $hour = '0'.$hour;}
>         if ($minute < 10){
>         $minute = '0'.$minute;}
>         if ($day < 10){
>                 $day = '0'.$day;}
>         if ($month < 10){
>                 $month = '0'.$month;}
>         if ($sec < 10){
>                 $sec = '0'.$sec;}

 ...to HERE you are doing much too much work.  Replace it with

    $time_stamp = sprintf "%04d-%02d-%02d %02d:%02d:%02d",
        $tm->year + 1900, $tm->mon + 1, $tm->mday, 
        $tm->hour, $tm->min, $tm->sec;

and similar for $file_stamp.  Or you could use one of the many
time-formatting modules.

>         $time_stamp = $year.'-'.$month.'-'.$day.'
> '.$hour.':'.$minute.':'.$sec;
>         $file_stamp = $year."-".$month;
>         my($port, $ipaddr) = sockaddr_in($sock->peername);
>         open(LOGFILE, ">>".$LPATH.$file_stamp.'.log') || die "cannot
> open/create file: $!";
>         print LOGFILE $time_stamp." ".gethostbyaddr($ipaddr, AF_INET)."
> ".$msg."\n";
>         close(LOGFILE);
> }
> die "recv: $!";
> }

Apart from the indentation issues, plus warnings and strict, the code looks
fine (I didn't run it).  The other objections are only stylistic.

Anno


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 5891
***************************************


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