[17541] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4961 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 24 14:05:33 2000

Date: Fri, 24 Nov 2000 11:05:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <975092714-v9-i4961@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 24 Nov 2000     Volume: 9 Number: 4961

Today's topics:
    Re: Check for integer (Anno Siegel)
    Re: Check for integer (Garry Williams)
    Re: Check for integer <G.Liakhovetski@sheffield.ac.uk>
    Re: Check for integer (Anno Siegel)
    Re: Check for integer (Garry Williams)
    Re: Check for integer (Tad McClellan)
        Compiling Curses-1.05 Module <rountree@cs.queensu.ca>
    Re: Counting bits. <W.Hielscher@mssys.com>
    Re: Counting bits. <steffen@mayo.imperia.net>
    Re: Counting bits. <jeffp@crusoe.net>
    Re: Counting bits. (Tad McClellan)
        FAST hex string to binary string conversion nigel_elliot@my-deja.com
    Re: FAST hex string to binary string conversion <uri@sysarch.com>
    Re: FAST hex string to binary string conversion (Mark W. Schumann)
    Re: how do I merge blocks of text from different lines? <amzeen@mtu-net.ru>
    Re: How to find what is between n'th and the next tab? (Anno Siegel)
    Re: How to find what is between n'th and the next tab? (Tad McClellan)
    Re: How to find what is between n'th and the next tab? (Tad McClellan)
    Re: How to find what is between n'th and the next tab? nobull@mail.com
    Re: How to Install Crypt::SSLeay on Remote Host? horace700@my-deja.com
    Re: IO::Socket: bind or listen errors <unformat@my-deja.com>
    Re: IO::Socket: bind or listen errors <uri@sysarch.com>
    Re: IO::Socket: bind or listen errors (Garry Williams)
        Need help with LPW (Florian Oefinger)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 24 Nov 2000 14:53:55 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Check for integer
Message-Id: <8vlve3$89k$1@lublin.zrz.tu-berlin.de>

Michael Guenther <MiGuenther@lucent.com> wrote in comp.lang.perl.misc:
>my $str = "3";
>
>
>if ( ($str/2)=~/[\.,]/) {
> print "not Ok\n"
>}
>else{
> print "OK\n";
>}
>print $str."\n";
>
>
>looking for divided by 2
>
>treat the result as an string and look fo "." or "," depending on your local
>settings

You are right in reducing the problem to a question about integers, that
is where it belongs.  That you demonstrate your solution only with a
denominator of 2 is easily fixed; just replace "2" in your code with
"$denominator" to make it more general.

You go wrong in treating the integers as strings, however.  While
Perl allows you to do that, it leads you to a string-oriented solution.
Yes, you can decide about divisibility by inspection of the decimal
representation of a number.  You have yourself noted a big drawback
of this method: It depends on locale settings, while divisibility
of numbers is a mathematical property independent of language.

This unexpected dependency should ring an alarm bell: If the solution
depends on things that have nothing to do with the problem, there
must be something wrong with the solution.  In this case, the way
to determine divisibility is to treat integers as integers and look
at the remainder, which the %-operator gives you.  Observing the
boolean qualities of numbers we get that "not $x % $y" is true
exactly if $y divides $x (for $y != 0).

Anno


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

Date: Fri, 24 Nov 2000 15:33:46 GMT
From: garry@zweb.zvolve.net (Garry Williams)
Subject: Re: Check for integer
Message-Id: <uTvT5.1585$xb1.95602@eagle.america.net>

On Fri, 24 Nov 2000 12:30:03 -0000, Shallowen <shallow@mail.com> wrote:
>If I have a number, say 18.88, stored as an element of an array, what is
>the most elegant way to check that that number is:
>exactly divisible by 0.64 after 0.32 has been subtracted from the original
>number. I tried using a modular divide, but I reached (and went past) the
>limit of my understanding of maths at that point.
>
>So something like this (this is pseudo-code, I know it means not much to
>PERL as it is):
>
>if (((($sample_array[$element])-0.32)/0.64)==an integer) {
>  print "It's divisible!\n";
>} else {
>  print "D'oh! It's not exactly divisible!\n";
>}

I think you want to work with integers: 

    #!/usr/local/bin/perl -w
    use strict;
    sub is_divisible {
      my $i;
      $i  = shift;
      $i -= 0.32;
      $i  = int($i * 100);
      return !($i % 64);
    }
    for ( 5.44, 10.56, 5, 10 ) {
      print "$_ is ", is_divisible($_) ? "" : "not ", "divisible\n";
    }

-- 
Garry Williams


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

Date: Fri, 24 Nov 2000 15:29:11 +0000
From: "Guennadi V. Liakhovetski" <G.Liakhovetski@sheffield.ac.uk>
Subject: Re: Check for integer
Message-Id: <Pine.GSO.4.21.0011241528290.27198-100000@acms23>

Function int gives you the integer part of a number.

On Fri, 24 Nov 2000, Shallowen wrote:

> If I have a number, say 18.88, stored as an element of an array, what is
> the most elegant way to check that that number is:
> exactly divisible by 0.64 after 0.32 has been subtracted from the original
> number. I tried using a modular divide, but I reached (and went past) the
> limit of my understanding of maths at that point.
> 
> So something like this (this is pseudo-code, I know it means not much to
> PERL as it is):
> 
> if (((($sample_array[$element])-0.32)/0.64)==an integer) {
>   print "It's divisible!\n";
> } else {
>   print "D'oh! It's not exactly divisible!\n";
> }
> 
> 
> or something like that.
> 
> Any help much appreciated! If there's a function which tests for this,
> sorry for wasting your time, but I looked, and couldn't find it. (Although
> doubtless that means very little =)
> 
> --
> Posted via CNET Help.com
> http://www.help.com/
> 

___

Dr. Guennadi V. Liakhovetski
Department of Applied Mathematics
University of Sheffield, U.K.
email: G.Liakhovetski@sheffield.ac.uk




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

Date: 24 Nov 2000 16:32:13 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Check for integer
Message-Id: <8vm56d$8kt$1@lublin.zrz.tu-berlin.de>

Garry Williams <garry@zvolve.com> wrote in comp.lang.perl.misc:
>On Fri, 24 Nov 2000 12:30:03 -0000, Shallowen <shallow@mail.com> wrote:
>>If I have a number, say 18.88, stored as an element of an array, what is
>>the most elegant way to check that that number is:
>>exactly divisible by 0.64 after 0.32 has been subtracted from the original
>>number. I tried using a modular divide, but I reached (and went past) the
>>limit of my understanding of maths at that point.
>>
>>So something like this (this is pseudo-code, I know it means not much to
>>PERL as it is):
>>
>>if (((($sample_array[$element])-0.32)/0.64)==an integer) {
>>  print "It's divisible!\n";
>>} else {
>>  print "D'oh! It's not exactly divisible!\n";
>>}
>
>I think you want to work with integers: 
>
>    #!/usr/local/bin/perl -w
>    use strict;
>    sub is_divisible {
>      my $i;
>      $i  = shift;
>      $i -= 0.32;
>      $i  = int($i * 100);

Use of int() here is risky.  It always is, when the expected result
of a float operation is an integer.  You never know if you will
actually get an integer result or whether it will be approximated
by a floating point number.  In the latter case, int() will come
up one too small if the approximation is from below.  You will
have to round $i * 100 to reliably arrive at the intended integer.

Anno


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

Date: Fri, 24 Nov 2000 18:00:59 GMT
From: garry@zweb.zvolve.net (Garry Williams)
Subject: Re: Check for integer
Message-Id: <v1yT5.1595$xb1.96665@eagle.america.net>

On 24 Nov 2000 16:32:13 -0000, Anno Siegel
<anno4000@lublin.zrz.tu-berlin.de> wrote:
>Garry Williams <garry@zvolve.com> wrote in comp.lang.perl.misc:
>>On Fri, 24 Nov 2000 12:30:03 -0000, Shallowen <shallow@mail.com>
>>wrote:
>>>If I have a number, say 18.88, stored as an element of an array, what is
>>>the most elegant way to check that that number is:
>>>exactly divisible by 0.64 after 0.32 has been subtracted from the original
>>>number. 
>>
>>I think you want to work with integers: 
>>
>>    #!/usr/local/bin/perl -w
>>    use strict;
>>    sub is_divisible {
>>      my $i;
>>      $i  = shift;
>>      $i -= 0.32;
>>      $i  = int($i * 100);
>
>Use of int() here is risky.  It always is, when the expected result
>of a float operation is an integer.  You never know if you will
>actually get an integer result or whether it will be approximated
>by a floating point number.  In the latter case, int() will come
>up one too small if the approximation is from below.  You will
>have to round $i * 100 to reliably arrive at the intended integer.

You are right, here's the corrected version: 

    sub is_divisible {
      ! (sprintf("%.2f", shift() - 0.32) * 100 % 64);
    }

-- 
Garry Williams


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

Date: Fri, 24 Nov 2000 09:15:03 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Check for integer
Message-Id: <slrn91stv7.uth.tadmc@magna.metronet.com>

Michael Guenther <MiGuenther@lucent.com> wrote:
>my $str = "3";
>
>
>if ( ($str/2)=~/[\.,]/) {
                  ^
                  ^

Useless use of backslash character.


>treat the result as an string and look fo "." or "," depending on your local
>settings


Hmmm. I wonder what the question was that this is supposed to
be answering?

You did not quote any context.

Whatever the question was, I'm quite sure the "answer" provided
is nonsense. 


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


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

Date: 24 Nov 2000 09:37:31 -0500
From: Eric Rountree <rountree@cs.queensu.ca>
Subject: Compiling Curses-1.05 Module
Message-Id: <vzt3dghtp04.fsf@cs.queensu.ca>

Hello to all.

I'm trying to set up the Curses-1.05 module so that I can use the
perlmenu.v4.0 module. My curses library was really old, so I
downloaded ncurses-5.2 from one of the GNU mirrors. Perlmenu seems to
need the getcap function, so I configured ncurses with the
--enable-termcap and --enable-getcap options (as well as
--disable-overwrite, --without-ada, and --without--cxx-binding)

The ncurses test programs work fine. They do color and everything. :-)
But, when I do the make for the Curses Perl module, the following
missing functions are reported:

function 'getsyx' NOT found
function 'getsyx' returns void
function 'setsyx' NOT found
function 'setsyx' returns void
 ...
function 'flusok' NOT found
function 'getcap' NOT found
function 'touchoverlap' NOT found
function 'new_panel' NOT found
function 'bottom_panel' NOT found
function 'top_panel' NOT found
function 'show_panel' NOT found
function 'update_panels' NOT found
function 'hide_panel' NOT found
function 'panel_window' NOT found
function 'replace_panel' NOT found
function 'move_panel' NOT found
function 'panel_hidden' NOT found
function 'panel_above' NOT found
function 'panel_below' NOT found
function 'set_panel_userptr' NOT found
function 'panel_userptr' NOT found
function 'del_panel' NOT found

I'm not sure where to go from here. I don't have a lot of experience
with includes and libraries. I'm running Solaris 2.6, gcc version
2.8.1, and Perl, v5.6.0.

Thanks in advance for any suggestions.

Eric

-- 
---------------------------------------------
Eric Rountree, Systems Specialist
Department of Computing & Information Science
Goodwin Hall, Room 551
Queen's University
Kingston, Ontario
Canada  K7L 3N6

(613)533-6784
rountree@cs.queensu.ca


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

Date: Fri, 24 Nov 2000 15:16:35 +0100
From: Wolfgang Hielscher <W.Hielscher@mssys.com>
Subject: Re: Counting bits.
Message-Id: <3A1E7843.EB8548AB@mssys.com>

Michael Guenther wrote:
> my $count = 0;
> while ($str=~/1/g){
>    $count ++;
> }

Or simply use m//g in a list context:
   my $count = @{[$str =~ m/1/g]};


Cheers
	Wolfgang


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

Date: 24 Nov 2000 14:38:44 GMT
From: Steffen Beyer <steffen@mayo.imperia.net>
Subject: Re: Counting bits.
Message-Id: <8vluhk$kpn$1@swifty.westend.com>

In article <8vlodd$g15$1@pheidippides.axion.bt.co.uk>, Michael Cousins <mcousins@bfsec.bt.co.uk> wrote:

> Is there an easy way in Perl to count the number of bits set in an integer?
> eg;
> 4     = 00000100 has 1 bit set
> 132 = 10000100 has 2 bits set
> etc..

The following is an efficient way (I don't know if you consider it easy :-) ):

$i = 0x84; # has 2 bits set

$bits = 0;
while ($i)
{
    $i &= $i - 1;
    $bits++;
}

It is efficient because it only needs as many loops as there are set bits.

Regards,
-- 
    Steffen Beyer <sb@engelschall.com>
    http://www.engelschall.com/u/sb/whoami/ (Who am I)
    http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
    http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)


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

Date: Fri, 24 Nov 2000 11:47:28 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Counting bits.
Message-Id: <Pine.GSO.4.21.0011241133400.714-100000@crusoe.crusoe.net>

[posted & mailed]

On Nov 24, Michael Cousins said:

>Is there an easy way in Perl to count the number of bits set in an integer?
>
>4     = 00000100 has 1 bit set
>132 = 10000100 has 2 bits set

This is potentially slow (for a number represented by '100....00'):

  my $bits;
  for (; $x; $x >>= 1) { $bits++ if $x & 1 }

There is a pattern to the number of bits set.  Now, if I can figure it out
in constant time.

For 1 through 63:

  1
  1 2
  1 2 2 3
  1 2 2 3 2 3 3 4
  1 2 2 3 2 3 3 4 2 3 3 4 3 4 4 5
  1 2 2 3 2 3 3 4 2 3 3 4 3 4 4 5 2 3 3 4 3 4 4 5 3 4 4 5 4 5 5 6

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






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

Date: Fri, 24 Nov 2000 09:32:34 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Counting bits.
Message-Id: <slrn91sv02.uth.tadmc@magna.metronet.com>

Wolfgang Hielscher <W.Hielscher@mssys.com> wrote:
>Michael Guenther wrote:
>> my $count = 0;
>> while ($str=~/1/g){
>>    $count ++;
>> }
>
>Or simply use m//g in a list context:
>   my $count = @{[$str =~ m/1/g]};


That is a profoundly horrid solution!

Even s///g would be better than that silliness (though still not "best"):

      my $count = $str =~ s/1/1/g;


m//g is the Wrong Tool for the "counting characters" job.

   my $count = $str =~ tr/1//;


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


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

Date: Fri, 24 Nov 2000 15:45:19 GMT
From: nigel_elliot@my-deja.com
Subject: FAST hex string to binary string conversion
Message-Id: <8vm2ee$4k4$1@nnrp1.deja.com>

I'm looking for some FAST routines to convert between hex and binary
string representations of a number

eg   "123abc" <=> "000100100011101010111100"

My hex strings are long (100's of chars) and doing global substitutions
on a line takes a great deal of time when you need to process millions
of lines (which I do!)

Any advice welcome

Thanks

- Nigel


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


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

Date: Fri, 24 Nov 2000 16:25:05 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: FAST hex string to binary string conversion
Message-Id: <x73dghcp7h.fsf@home.sysarch.com>

>>>>> "ne" == nigel elliot <nigel_elliot@my-deja.com> writes:

  ne> I'm looking for some FAST routines to convert between hex and binary
  ne> string representations of a number

  ne> eg   "123abc" <=> "000100100011101010111100"

perldoc -f pack

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 24 Nov 2000 11:49:24 -0500
From: catfood@apk.net (Mark W. Schumann)
Subject: Re: FAST hex string to binary string conversion
Message-Id: <8vm66k$8j0@junior.apk.net>

In article <8vm2ee$4k4$1@nnrp1.deja.com>,  <nigel_elliot@my-deja.com> wrote:
>I'm looking for some FAST routines to convert between hex and binary
>string representations of a number
>
>eg   "123abc" <=> "000100100011101010111100"
>
>My hex strings are long (100's of chars) and doing global substitutions
>on a line takes a great deal of time when you need to process millions
>of lines (which I do!)
>
>Any advice welcome

$ perldoc -f pack
$ perldoc -f unpack



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

Date: Fri, 24 Nov 2000 17:35:40 +0300
From: "Amzin" <amzeen@mtu-net.ru>
Subject: Re: how do I merge blocks of text from different lines?
Message-Id: <8vlulu$1pfl$1@gavrilo.mtu.ru>

Greetings, Mauro <-@-.com>! You wrote:
> ________input is____
> [1]|some text
> [2]|I've an apple
> [3]|I eat the apple
> 
> separatortag
> 
> 1. HALLO
> 2. HI
> 3. FOOBAR
> 
> _______output must be_____
> HALLO|some text
> HI|I've an apple
> FOOBAR|I eat the apple
> 
> do you know the way to do that?
Yes. There is a quick'n'dirty version.

BEGIN {separator="separatortag";
       separated="fir";
       str_count=0;
output_file="myfile";
}

{
#Just modify it for numbers in first fields -- I got no time to.
if (($0!=separator) && ($0!="")) {f[str_count,separated]=$0;
    str_count++;   }

    if ($0==separator) {minus=str_count; separated="gur";}
}

END {
for (i=0; i<minus; i++) {
printf "%s|%s\n", f[i,"fir"], f[i+minus,"gur"];


 }

}





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

Date: 24 Nov 2000 16:22:30 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to find what is between n'th and the next tab?
Message-Id: <8vm4k6$8jl$1@lublin.zrz.tu-berlin.de>

Pekka Kumpulainen  <kumpu@mit.tut.fi> wrote in comp.lang.perl.misc:
>Hi,
>I am a newbie with perl but I have read the faq, searched from books and
>web tutorials.
>I want to get a column from tab-separated ascii-file.
>Is it possible to find where in my line is the n'th tab and then get the
>characters from that to next tab?
>
>Now I do it with split:
>        (@stuff) = split /\s/, $_;
>        print OUT "$stuff[$colnum-1]\n";
>
>It works but this it takes ages to run. If I get the first one or second
>limiting the split:
>      (@stuff[0..1],$rest) = split /\s/, $_, 3;
>       print OUT "$stuff[1]\n";
>
>This runs fast. So splitting entire string seems to be inefficient when
>I only want one value.
>
>Can I find positions of tabs n and n+1? Then I could use substr.
>Or is there a feature in split (which I could not find yet) that allows
>to pick n:th value directly, something like: ($crap,$mystuff,$morecrap)
>= split /\s/, $_, n;

Let me number the columns from zero.

It is certainly possible to determine the position of two consecutive
tabs in a string.  You could walk from tab to tab using index() (the
tree-argument form), but that would require a loop on perl level,
something like $pos = index( $str, "\t", $pos + 1) while $col--;
This also needs special treatment for the 0th and the last column.
Most likely, split is faster than this.

Another approach uses a regex: qr/(?:[^\t]*\t){$col}([^\t]*)(?:\t|$)/;
deposits the $col'th column in $1.  This requires compilation of a
regex for each column.  If you do that for every access, I doubt that
it can beat split.  You might try and pre-compile a regex for every
column.  Only a benchmark can tell if that is actually faster on your
machine.

Anno


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

Date: Fri, 24 Nov 2000 10:21:11 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How to find what is between n'th and the next tab?
Message-Id: <slrn91t1r7.uth.tadmc@magna.metronet.com>

Michael Guenther <MiGuenther@lucent.com> wrote:

>Try


Can't. It won't compile.


>print $result."


Can't find string terminator '"' anywhere before EOF at ./temp line 17.


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


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

Date: Fri, 24 Nov 2000 11:35:10 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How to find what is between n'th and the next tab?
Message-Id: <slrn91t65u.uth.tadmc@magna.metronet.com>

Pekka Kumpulainen <kumpu@mit.tut.fi> wrote:

>I am a newbie with perl 


Welcome!


>but I have read the faq, searched from books and
>web tutorials.


Thanks. We all appreciate that.

Just in case you don't know, I wouldn't want you to miss a
large and authoritative resource:

   The FAQs are only 10 of the 50-80 files worth of standard
   docs that come with the perl distribution.

So don't forget to check the non-FAQ docs too.


>I want to get a column from tab-separated ascii-file.


use split().


>Is it possible to find where in my line is the n'th tab and then get the
>characters from that to next tab?


Yes. You could call index() a bunch of times, updating the value
of the 3rd argument each time.

But that seems like an awful lot of bother...


>Now I do it with split:
>        (@stuff) = split /\s/, $_;
                            ^
>        print OUT "$stuff[$colnum-1]\n";


Note that that does not do what you said you wanted to do.

It splits on any of 5 characters, but you said you wanted to
split only on 1 particular character (a tab).

You want \t there, not \s


>Or is there a feature in split (which I could not find yet) that allows
>to pick n:th value directly, something like: ($crap,$mystuff,$morecrap)
>= split /\s/, $_, n;


It is not a feature of split(), but there is a feature of Perl
that will help you do that.

It is called a "list slice".

See the "Slices" section in perldata.pod.


>Thanks in advance


You're welcome in arrears.


>Meanwhile I 'll try running index n times increasing startpoint etc. to
>see how it performes.


You should use the Benchmark module for benchmarking  :-)


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

$str = "1001\t101\t010001\t00000\tFR0ED\trolf";
$colnum = 5;

timethese 1_000_000, { 
   split_s   => q( @vals = split(/\s/, $str); $val = $vals[$colnum-1];
                 ),
   split_t   => q( @vals = split(/\t/, $str); $val = $vals[$colnum-1];
                 ),
   slice     => q( $val = (split /\t/, $str)[$colnum-1];
                 ),
   match     => q( $val = $1 if $str =~ /([^\t]*(\t|$)){$colnum}/;
                 ),
};
------------------------

(partial) output:

     match: 19 wallclock secs (18.50 usr +  0.01 sys = 18.51 CPU)
     slice: 13 wallclock secs (11.56 usr +  0.02 sys = 11.58 CPU)
   split_s: 19 wallclock secs (19.01 usr +  0.04 sys = 19.05 CPU)
   split_t: 11 wallclock secs (12.26 usr +  0.02 sys = 12.28 CPU)


Change $colnum to 1 and we get:

     match: 19 wallclock secs (18.65 usr +  0.01 sys = 18.66 CPU)
     slice: 10 wallclock secs (11.51 usr +  0.02 sys = 11.53 CPU)
   split_s: 20 wallclock secs (18.92 usr +  0.05 sys = 18.97 CPU)
   split_t: 13 wallclock secs (12.39 usr +  0.03 sys = 12.42 CPU)


Modify it to run with your real data, and see what it says.


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


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

Date: 24 Nov 2000 18:12:54 +0000
From: nobull@mail.com
Subject: Re: How to find what is between n'th and the next tab?
Message-Id: <u966lddys9.fsf@wcl-l.bham.ac.uk>

Pekka Kumpulainen <kumpu@mit.tut.fi> writes:

> This runs fast. So splitting entire string seems to be inefficient when
> I only want one value.

Using a simple match is about twice as fast as split even though it
involves re-compiling a regex.  Interestingly, if you avoid the
recompilation it saves very little.

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

my $n = 50;
my $data = join "\t" => map "foo$_" => 0 .. 100;
my $piece;
my %regex_cache;

timethese 10000 => {
    split => sub {
	$piece = (split /\s/, $data, $n+2)[$n];
    },
    
    match => sub {
	($piece) = $data =~ /(?:\S*\s){$n}(\S+)/;
    },

    match_o => sub {
	($piece) = $data =~ /(?:\S*\s){$n}(\S+)/o;
    },

    match_cache => sub {
	($piece) = $data =~ ( $regex_cache{$n} ||= qr/(?:\S*\s){$n}(\S+)/ );
    },
}

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 24 Nov 2000 14:32:30 GMT
From: horace700@my-deja.com
Subject: Re: How to Install Crypt::SSLeay on Remote Host?
Message-Id: <8vlu5u$1s5$1@nnrp1.deja.com>

Hello-Thanks for responding

I added the following to my script:

use lib '/data1/hypermart.net/user';
use Crypt::SSLeay;

I then manually ftp'ed (Hypermart does not offer telnet) the contents of
Crypt-SSLeay-0_17_tar.gz to my Hypermart remote user directory. I
realize I'm SOL if module requires compilation but I did not see any .h
 .c, etc files in the pkg so hopefully I'm okay.  All directory
structures were copied verbatim and all permissions were chmod to 777
just to be sure.

Now I'm getting a dynaloader error:

[Fri Nov 24 06:10:15 2000] SSLeay.pm: [Fri Nov 24 06:10:15 2000]
DynaLoader.pm: Can't locate
loadable object for module Crypt::SSLeay in @INC (@INC contains:
/data1/hypermart.net/user /usr/local/lib/perl5/i386-bsdos/5.00404
/usr/local/lib/perl5
/usr/local/lib/perl5/site_perl/i386-bsdos /usr/local/lib/perl5/site_perl
 .) at test5.pl line 11
BEGIN failed--compilation aborted at test5.pl line 11.

Is this just more path errors or something greater?

Thanks Again-agi


In article <G4FtMp.16q@news.muni.cz>,
  adelton@informatics.muni.cz wrote:
> On Wed, 22 Nov 2000 17:28:43 GMT, horace700@my-deja.com
<horace700@my-deja.com> wrote:
> > I'd like to use LWP to retrieve a secure page from my Hypermart
> > account. Presently I get a 501 error & modlist.pl says crypt::ssleay
is
> > not installed. I understand that so long as module does not require
> > compilation, one can upload module in user directory. The only
changes
>
> I bet Crypt::SSLeay needs compiling.
>
> > I'm told would be to create appropriate use's & require's to the
> > script. Basically I've got 3 questions?
> > 1. Can Crypt::SSLeay be successfully installed in a remote user
> > directory?
>
> What's remote directory? Your user (non system) directory? Yes.
>
> > 2. Would I just add "use /path/to/Crypt::SSLeay" to script?
>
> The syntax is
>
> 	use lib '/path/to';
> 	use Crypt::SSLeay;
>
> > 3. Exactly what "require" (or do I even need a require call?) call
do I
> > need.
>
> To do what, HTTPS request? Just issue the request with correct URL.
>
> Yours,
>
> --
>
------------------------------------------------------------------------
>  Honza Pazdziora | adelton@fi.muni.cz |
http://www.fi.muni.cz/~adelton/
>    .project: Perl, DBI, Oracle, MySQL, auth. WWW servers, MTB, Spain.
> Petition for a Software Patent Free Europe
http://petition.eurolinux.org
>
------------------------------------------------------------------------
>


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


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

Date: Fri, 24 Nov 2000 13:59:17 GMT
From: unformat <unformat@my-deja.com>
Subject: Re: IO::Socket: bind or listen errors
Message-Id: <8vls7k$ng$1@nnrp1.deja.com>

I believe this to be a Win32 issue in IO::Socket only since the bare
sockets equivalent acts as expected...

#!perl -w
# blockedport2.pl

use strict;
use Socket;

select((select(STDOUT),$|=1)[0]); #<-- make STDOUT a hot handle.

sub listener
{
   my $port;
   $port = shift or $port = 2070;
   print STDOUT "listener on port $port.\n";
   my $paddr = sockaddr_in($port, INADDR_ANY);
   my $proto = getprotobyname('tcp');
   my $fh = do{ local *DATA };
   socket($fh, PF_INET, SOCK_STREAM, getprotobyname('tcp') ) or
die "socket: $!";
   bind($fh, $paddr) or die "bind: $!";
   listen($fh, SOMAXCONN)  or die "listen: $!";
   sleep 1;
   return $fh;
}

my $l1 = &listener();
my $l2 = &listener();

__END__

 ...and dies upon bind().

--
unformat@my-deja.com
http://www.bmeworld.com/unformat/  -- tattooed all over!
"Enough love to knock a rhino sideways" - SNUFF


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


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

Date: Fri, 24 Nov 2000 15:58:23 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: IO::Socket: bind or listen errors
Message-Id: <x77l5tcqg0.fsf@home.sysarch.com>

>>>>> "u" == unformat  <unformat@my-deja.com> writes:

  u> I believe this to be a Win32 issue in IO::Socket only since the bare
  u> sockets equivalent acts as expected...

i don't do windows. if you really think this is a bug in IO::Socket and
you can reliably show manual coding works and module fails, report it to
the module author.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Fri, 24 Nov 2000 18:59:46 GMT
From: garry@zweb.zvolve.net (Garry Williams)
Subject: Re: IO::Socket: bind or listen errors
Message-Id: <CUyT5.1602$xb1.96922@eagle.america.net>

On Fri, 24 Nov 2000 08:11:42 GMT, unformat <unformat@my-deja.com> wrote:
>In article <nSdT5.1431$xb1.91724@eagle.america.net>,
>  garry@zvolve.com wrote:
>> On Thu, 23 Nov 2000 17:42:01 GMT, unformat <unformat@my-deja.com> wrote:
>> >When using IO::Socket and creating a socket object with ->new, I can
>> >give args to make it listen on a port. I cannot, however, establish an
>> >error condition following failure to bind to port using the ->error
>> >method. How can I find out if the bind or listen failed within ->new() ?
>
>> Why not check $!?
>
>I did and it doesn't get set (or it gets set and gets clobbered)...
>
>#! perl -w
>use strict; use IO::Socket; use IO::Select;
>select((select(STDOUT),$|=1)[0]); #<-- make STDOUT a hot handle.
>
>my $l1 = IO::Socket::INET->new(
>   Proto     => 'tcp',
>   LocalPort => 2070,
>   Listen    => SOMAXCONN,
>   Reuse     => 1);
>
>print STDOUT "After \$l1, \$l1->error() = ", $l1->error(), " and \$! =
>$!.\n";
>
># attempt to listen on same port...
>
>my $l2 = IO::Socket::INET->new(
>   Proto     => 'tcp',
>   LocalPort => 2070,
>   Listen    => SOMAXCONN,
>   Reuse     => 1);
>
>print STDOUT "After \$l2, \$l2->error() = ", $l2->error(), " and \$! =
>$!.\n";
>
>__END__
>
>...which gives...
>
>After $l1, $l1->error() = '0' and $! = ''.
>After $l2, $l2->error() = '0' and $! = ''.

(It looks like there's some cut/paste magic going on with what you
posted.)  

I cannot reproduce this with: 

    $ perl -v

    This is perl, v5.6.0 built for sun4-solaris
    ...
    $ perl -MSocket -wle 'print $Socket::VERSION'
    1.72
    $ perl -MIO::Socket -wle 'print $IO::Socket::VERSION'
    1.26
    $ perl -MIO::Socket -wle 'print $IO::Socket::INET::VERSION'
    1.25
    $ 

I get the expected 'Address already in use'.  I tried doing this in
separate processes and in the same process, but either way, the
expected failure occurred.  

I *can* reproduce it with (Windows 98): 

    d:/garry $ perl -v

    This is perl, v5.6.0 built for MSWin32-x86-multi-thread
    (with 1 registered patch, see perl -V for more detail)

    Copyright 1987-2000, Larry Wall

    Binary build 615 provided by ActiveState Tool Corp.
    http://www.ActiveState.com
    Built 12:54:35 Jul  4 2000
    ...
    d:/garry $ perl -MSocket -wle 'print $Socket::VERSION'
    1.72
    d:/garry $ perl -MIO::Socket -wle 'print $IO::Socket::VERSION'
    1.26
    d:/garry $ perl -MIO::Socket -wle 'print $IO::Socket::INET::VERSION'
    1.25
    d:/garry $

>...Now, $l1 and $l2 cannot be undef here or there would be a runtime
>error. 

Which I *did* get under Solaris but not under Windows.  

>I tried to split up the new and bind and listen separately but
>had trouble with the syntax - but if that is what's necessary then I'll
>persevere. 

I tried doing everything myself instead of relying on IO::Socket::INET
with: 

    #!/usr/local/bin/perl -Tw
    use strict;
    use Socket;

    my $port = 12070;
    socket(SERVER1, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
    setsockopt(SERVER1, SOL_SOCKET, SO_REUSEADDR, 1);
    my $in_addr = sockaddr_in($port, INADDR_ANY);
    bind(SERVER1, $in_addr)
	or die "can't bind to port $port: $!\n";
    listen(SERVER1, SOMAXCONN)
	or die "can't set listen queue ($port): $!\n";

    socket(SERVER2, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
    setsockopt(SERVER2, SOL_SOCKET, SO_REUSEADDR, 1);
    $in_addr = sockaddr_in($port, INADDR_ANY);
    bind(SERVER2, $in_addr)
	or die "can't bind to port $port: $!\n";
    listen(SERVER2, SOMAXCONN)
	or die "can't set listen queue ($port): $!\n";
    exit;

But this fails as expected under Solaris and does *not* fail under
Windows.  

I doubt that my Windows version of perl is up to date, but it seems to
be using the same version of IO::Socket and IO::Socket::INET.  Looks
like a bug with the Windows version of IO::Socket or IO::Socket::INET.
Or maybe it's a bug in the Windows TCP stack.  (Is that even
conceivable?)  Maybe you should contact the module author.  

>Perhaps there is an other way of checking whether the
>IO::Socket object is actually listening on the port - erm ->localport???
>
>(surely this isn't something to do with the Reuse param reusing the
>port because perl sees that I do nothing with the first filehandle -
>nah!)

Nah.  

-- 
Garry Williams


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

Date: Fri, 24 Nov 2000 19:58:56 +0100
From: FlorianOefinger@web.de (Florian Oefinger)
Subject: Need help with LPW
Message-Id: <1ekm9vu.1cfhp0ci7fv70N@p3e9ed366.dip.t-dialin.net>

require LWP::UserAgent;

$ua = new LWP::UserAgent;

$request = new HTTP::Request('POST', 'http://www.etc.com/login.cgi',
[username =>'Name',password =>'Pass',]);
$response = $ua->request($request);

If i try to run this script reports:
Can't call method "clone" on unblessed reference.
File 'lib:HTTP:Message.pm'; Line 47

What's wrong in my code? Is it the way i pass the POST values?

Thanks in advance
Florian Oefinger


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

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


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