[16466] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3878 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 2 00:05:26 2000

Date: Tue, 1 Aug 2000 21:05:11 -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: <965189110-v9-i3878@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 1 Aug 2000     Volume: 9 Number: 3878

Today's topics:
        Breaking up strings into arbitrary lengths <pking@idirect.com>
    Re: Breaking up strings into arbitrary lengths <stephenk@cc.gatech.edu>
    Re: Breaking up strings into arbitrary lengths <godzilla@stomp.stomp.tokyo>
    Re: Breaking up strings into arbitrary lengths <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: Breaking up strings into arbitrary lengths <billy@arnis-bsl.com>
        DBI: Same data accessed twice? <pking@idirect.com>
    Re: dialing from another computer (David Efflandt)
        Help!! aunkhin@my-deja.com
        How do I use objects with PerlScript in WSH <rckjr@yahoo.com>
        How to install openssl-0.9.3a <seesej@uswest.net>
    Re: How to recognize triplicates (Keith Calvert Ivey)
    Re: I have an idea but will it work ? <signingon@thejobcentre.com>
    Re: Linked list etc. <jeff@yoak.com>
    Re: Net::FTP Module (David Efflandt)
    Re: newb Q, Our perl guy left!! (Keith Calvert Ivey)
    Re: numeric storage efficiency <cawlfiel@uiuc.edu>
    Re: Perl CGI - files occasionally truncated mikelot@my-deja.com
    Re: Perl Module in C - Question. (Abigail)
    Re: posting in newsgroup using perl script? (Iain Chalmers)
        Remove a blank line <rashid1218@hotmail.com>
    Re: Reserved word (Abigail)
    Re: Running other programs in background ericr@yankthechain.com
        Same data accesed twice? (cleaned up code) <pking@idirect.com>
    Re: select/vec/pipes question <billy@arnis-bsl.com>
    Re: Syntax Question (Keith Calvert Ivey)
        Variable Scope in Included Files bluearchtop@my-deja.com
    Re: Variable Scope in Included Files <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: When does it pay to presize an array? (Andrew J. Perrin)
    Re: why open("fifo") hangs? (David Efflandt)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 02 Aug 2000 01:24:03 GMT
From: Paul King <pking@idirect.com>
Subject: Breaking up strings into arbitrary lengths
Message-Id: <39877866.A2A9911D@idirect.com>

Hello, PERLers:

There has GOT to be a better way to do this. What I want to do is to
break up a really long string  on an arbitrary byte boundary. This is so

I can fit the string into a database in a way that conserves space. I
am not allowed to use a variable-length byte/glob type, which our
database supports, for portability reasons. So, I have to chop the
string into blocks and each block gets their own table row. When the
data is called back, I glue them together as one string again.

OK, the solution I wrote looks like it is going to be very slow, and I
was wondering  if anyone here knows if Perl has a better way to do this.

See below for my solution. Please don't laugh.

Paul King

use POSIX;
sub cutupline {
   # Accepts a string as input
   # Returns an array of strings which are of length 3 kilobytes or
less.
   # Syntax: @new_array = &cutupline $string;
   #
   # It seems that someone didn't think about breaking up a string
   # on arbitrary byte boundaries. Most of Perl's efforts have been to
   # break up strings by their pattern. This is probably going to be
slow.
   # There may need to be a perl-accessible C-function that would accept

   # 1) variable byte boundaries (as a parameter), and 2) very long
   # strings as input.
   my $length = 3072;   # the byte boundary to break up a string
   my $string = shift;  # the string to break up
   my @arr_all;         # array of all concatenated strings
   my @str_arr = split //, $string;      # an array of single characters

(ouch)
   my $hi_idx = int $#str_arr / $length; # upper loop limit
   my $rem = POSIX::fmod($#str_arr, $length);
   if ($rem > 0) { $hi_idx ++; }         # adjust the upper loop limit
   my $last = 0;        # the index of the last character in the string
   my $count_ch = 0;    # which string is being updated?
   print "The total string length is: " . $#str_arr . "
($hi_idx)\n<br>";
   for (my $count_str = 0; $count_str < $hi_idx; $count_str++) {
      if ($count_str == $hi_idx - 1) { $length = $rem; } # last
iteration
      for ($count_ch = $last; $count_ch < $last + $length - 1;
$count_ch++) {
         $arr_all[ $count_str ] .= $str_arr[ $count_ch ];
      }
      $last = $count_ch + 1;
      $arr_all[ $count_str ] .= "\0";
   }

   return @arr_all;
}






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

Date: Tue, 01 Aug 2000 21:50:06 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: Breaking up strings into arbitrary lengths
Message-Id: <39877E4E.B6D90C68@cc.gatech.edu>

Paul King wrote:

> There has GOT to be a better way to do this. What I want to do is to
> break up a really long string  on an arbitrary byte boundary. This is so
>

perldoc -f substr

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Tue, 01 Aug 2000 19:48:09 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Breaking up strings into arbitrary lengths
Message-Id: <39878BE9.54FD45A3@stomp.stomp.tokyo>

Paul King wrote:

(misc. snippage, context retained)

> What I want to do is to break up a really long string
> on an arbitrary byte boundary.
 
> I am not allowed to use a variable-length byte/glob type,
> which our database supports, for portability reasons.

I am curious. What is your portability issue related to glob?

You can fake a glob: <${fubar}> which I believe still
works even with this new screwed up Perl 5.6 version.
Can't say for sure, but this does work with earlier
Perl 5.x versions.

> my $length = 3072;   # the byte boundary to break up a string

Why not use a while length greater than 3072, 
substring and grab 3072 characters then close
out your while by grabbing whatever is left over,
after iteration, with each substring grab and your
final remainder being pushed into an array?

Godzilla!

--
Alturus 5, Gamma Sector, Perl Manglers:
  http://la.znet.com/~callgirl/webchat/nph-chahta.cgi


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

Date: Tue, 01 Aug 2000 19:11:09 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Breaking up strings into arbitrary lengths
Message-Id: <3987833D.3A5A118B@jpl.nasa.gov>

Paul King wrote:
> There has GOT to be a better way to do this. What I want to do is to
> break up a really long string  on an arbitrary byte boundary.

Have you seen the unpack function?  Here's how I'd break up a string
into 3 byte lengths:

$ perl -e '$a = "a3" x 4; print join " ", unpack $a, "0123456789"'
012 345 678 9

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King


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

Date: Wed, 02 Aug 2000 03:30:44 GMT
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: Breaking up strings into arbitrary lengths
Message-Id: <8m84l5$vi9$1@nnrp1.deja.com>

In article <39877866.A2A9911D@idirect.com>,
  pking@idirect.com wrote:
> Hello, PERLers:
>
> There has GOT to be a better way to do this. What I want to do is to
> break up a really long string  on an arbitrary byte boundary. This is
so
>
> I can fit the string into a database in a way that conserves space. I
> am not allowed to use a variable-length byte/glob type, which our
> database supports, for portability reasons. So, I have to chop the
> string into blocks and each block gets their own table row. When the
> data is called back, I glue them together as one string again.
>
> OK, the solution I wrote looks like it is going to be very slow, and I
> was wondering  if anyone here knows if Perl has a better way to do
this.
>

 ...some code skipped...

Consult perldoc -f substr.
Avoid unnecessary copying of huge strings and arrays,
IMHO it's better to return an array reference, not
an actual array.

sub cut_line
{
    my ($block_size, $total_size) = (3072, length $_[0]);
    my @a = ();

    for (my $sp=0; $sp<$total_size; $sp += $block_size)
    {
        push @a, substr $_[0], $sp, $block_size
    }

    \@a;
}

Note - this sub returns a _reference_ to an array
(perldoc perlref).

Hope this helps.
Ilja.



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


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

Date: Wed, 02 Aug 2000 03:09:11 GMT
From: Paul King <pking@idirect.com>
Subject: DBI: Same data accessed twice?
Message-Id: <3987910B.F95A98E3@idirect.com>

This bit of code prints messages on a web page (requires DBI and CGI
access).
The while loop, however, seems to access each message *twice*. Each
message is
only stored once in the database. This was verified by actually checking
the
database itself.

The inner loop "foreach" cycles through the message parts, but it seems
as if
fetchrow_array() (part of Perl::DBI) fetches the same data twice that is

passed to the handle. Is this possible? What am I doing wrong here?

Paul King

   my $sth2 = $dbh -> prepare (
            "SELECT * FROM messages
             WHERE (message_num_m = $message_num)"
   ) or die "Can't prepare SELECT statement: $DBI::errstr\n";
   $sth2 -> execute or die "Can't execute SELECT statement:
$DBI::errstr\n";
   my @msgparts;
   # print "<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>\n<br>"; # DEBUG
   while (@msgparts = $sth2 -> fetchrow_array()) {
      my ($clientnum, $message_num, $partnum, $of_total, $message) =
@msgparts;
      # print "<br><<TOP>> PART $partnum OF
$of_total\n<br>$message\n<br>"; # DEBUG
      foreach (@msgparts) { # DEBUG
         print "ROW (message parts): $_\n<br>"; # DEBUG
      }
   }
   # print "<><><><><><><><><><><><><><><><><>\n"; # DEBUG
   $#msgparts = -1; # clobber the array of messages
   print "\n<br>";
}




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

Date: Wed, 2 Aug 2000 01:08:21 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: dialing from another computer
Message-Id: <slrn8oet40.fkd.efflandt@efflandt.xnet.com>

On Tue, 1 Aug 2000 05:37:36 -0500, Hugh Brian <hugh.brian@uengineer.com> wrote:
>I have my two computers networked together at home. Windows internet
>connection sharing for some reason is always dialing even when I don't have
>any running programs that require a connection to the internet. So I disable
>the automatice dialing by selecting "Never Dial a Connection" in the
>Connection tab of Internet properties.
>
>What command (eg. `??????.exe`) do I need to issue from the computer that
>has no modem to the computer that has the modem to make the modem dial out
>to my isp? I hope I have explained myself.

Wouldn't it be easier to use Microsoft Netmeeting or VNC to start the
connection on the dialup box from the remote?  The advantage of VNC is
that it can be controlled from several different operating systems or any
Java capable web browser.

http://www.uk.research.att.com/vnc/index.html

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/  http://cgi-help.virtualave.net/



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

Date: Wed, 02 Aug 2000 03:30:53 GMT
From: aunkhin@my-deja.com
Subject: Help!!
Message-Id: <8m84le$vic$1@nnrp1.deja.com>

Wat does the following sentence do?
      $week=shift;

Actual source list:
$week=shift;

 $lastlog=1000;
 $limit=9;

 open IN,"tail -$lastlog /www/apache/logs/2000/
$week/access_log|awk '{print \$1}'|";
 while (<IN>) {
   chomp;
   $host{$_}++;
 }
 close IN;

 $tot=0;
 foreach $h (sort keys %host) {
   $tot+=$host{$h};
 }

 print "The latest $lastlog apache requests were made by:\n\n";
 $cnt=0;
 foreach $h (sort {$host{$b}<=>$host{$a}} keys %host) {
   printf "%4d (%5.2f%%) %s\n",$host{$h},$host{$h}/$tot*100,$h;
   $cnt++;
   last if $cnt>$limit;
 }
 print "\n[Note: only the top ".($limit+1)." entries are printed]\n";

Reply asap.
Thanx


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


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

Date: Wed, 02 Aug 2000 01:07:18 GMT
From: Dr. Strangepork <rckjr@yahoo.com>
Subject: How do I use objects with PerlScript in WSH
Message-Id: <8m7s84$piv$1@nnrp1.deja.com>

I'm trying to access a WSC component within a Windows Script using
PerlScript, but I seem unable to write to the property values within
the object.  Methods work fine, but I can't write to any component
properties.  Thing is, I can't find any help on the Web specifically
about WSH and PerlScript.  ActiveState's documentation doesn't cover
what I'm experiencing.  Can anyone else help me out?


--
Rick Kasten, MCSE         SysAdmin Consultant
Collective Technologies   http://www.colltech.com


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


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

Date: Tue, 01 Aug 2000 19:45:49 -0700
From: Jeffrey <seesej@uswest.net>
Subject: How to install openssl-0.9.3a
Message-Id: <B5ACD96D.8992%seesej@uswest.net>

Hi, 

I am trying to install openssl-0.9.3a and then Net::SSLeay. I am attempting
the install on Redhat 6.0.

My problem is after I complete the install for openssl-0.9.3a and try to go
on to the next step which is to install Net::SSLeay, I get this message from
the Net::SSLeay ./Makefile.PL.

"I could not find your OpenSSL in `/usr/local/ssl'
Please provide OpenSSL-0.9.3a installation directory"

I provide the actual install directory which is /usr/local/openssl/, but I
get the same message.

I wonder if all the necessary items are actually in the /usr/local/openss/
directory. Here is a listing.
1024 Aug  1 19:46 .
1024 Aug  1 10:53 ..
1024 Aug  1 10:53 certs
1024 Aug  1 10:53 lib
1024 Aug  1 10:53 misc
6207 Aug  1 11:20 openssl.cnf
1024 Aug  1 10:53 private

Is this a problem with my install of openssl, or something with Net::SSLeay?

Any help would be greatly appreciated. 



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

Date: Wed, 02 Aug 2000 02:07:25 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: How to recognize triplicates
Message-Id: <398881a7.1458536@news.newsguy.com>

Tina Mueller <tina@streetmail.com> wrote:
>Keith Calvert Ivey <kcivey@cpcug.org> wrote:
>> Tina Mueller <tina@streetmail.com> wrote:
>>>Tim Conrow <tim@ipac.caltech.edu> wrote:
>
>>>> This not-very-succinct code will find only triples, *not*
>>>> quadruples, quintuples, etc.
>>>
>>>> $a="baaab 111111 222 bbbb ccc 123444321 xzzz";
>>>> while($a=~m/(\d|\w)(?=\1\1)/g) { 
>>>>   print "match: $1$1$1" 
>>>>       if (pos($a)==1            || substr($a,pos($a)-2,1) ne $1) && 
>>>>          (pos($a)==length($a)-1 || substr($a,pos($a)+2,1) ne $1);
>>>> }
>>>
>>>> There must be a better way ... ?
>>>
>>>/(\w)\1{2,}/
>
>> That will match "111" and "bbb" in Tim's example string.
>
>when i tried it out on the following string
>$s = "baaab 111111 222 bbbb ccc 123444321 xzzz";
>@a = ($a =~ m/(\w)\1{2,}/g);
>it returned:
>a 1 2 b c 4 z
>
>that's what i wanted (the intention was, what, if the poster
>wants to find not just triplicates, but everything what is
>repeated more than 2 times)

That is probably what the original poster wanted, but you posted
in reply to Tim, who was asking for a better way to do what he
did with his "not-very-succinct code" above.

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


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

Date: Wed, 2 Aug 2000 02:46:53 +0100
From: "Phil Latio" <signingon@thejobcentre.com>
Subject: Re: I have an idea but will it work ?
Message-Id: <965180680.355058@zx81.mersinet.co.uk>

> #!/usr/bin/perl -w
> use strict;
>
> my %print_cost;
>
> while (<DATA>) {
>     chomp;
>     my ($color, $weight, $sided, $quantity, $price) = split;
>     $print_cost{$color}{$weight}{$sided}{$quantity} = $price;
> }
>
> # This data would come from your form
> my $number = 1000;
> my $weight = '80gsm';
> my $sides  = 's/sided';
> my $color  = 'white';
>
> # And spit out the price
> printf("The price for %d %s, %s, %s prints is %s.\n",
>     $number, $color, $weight, $sides,
>     $print_cost{$color}{$weight}{$sides}{$number});
>
> __DATA__
> white 80gsm s/sided 1000 £40.00
> white 80gsm s/sided 2500 £75.00
> white 80gsm s/sided 5000 £120.00
> white 80gsm s/sided 10000 £160.00
> white 80gsm s/sided 25000 £250.00

Sorry but I have a problem with the above.

I changed the path of perl to that of my server and then I saved the above
text as "printingprices.pl". I then uploaded it to my CGI-Bin and set CHMOD
as 755

Next I created an order form on an HTML page with matching radio fields to
those above ie: number, weight, sides, colour. I included <form
name="testform" method="post"
action="http://www.mywebsite.com/cgi-bin/printingprices.pl">

At the bottom I put a submit button which I assumed would send the data to
the Perl Script and the result would be "printf("The price for %d %s, %s, %s
prints is %s.\n","

What is confusing me is this part below.

> # This data would come from your form
> my $number = 1000;
> my $weight = '80gsm';
> my $sides  = 's/sided';
> my $color  = 'white';

If I can get this basic script to work then I can start experimenting with
more difficult tasks.

Many thanks again

Phil








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

Date: Tue, 01 Aug 2000 20:55:32 -0800
From: "Jeff Yoak" <jeff@yoak.com>
Subject: Re: Linked list etc.
Message-Id: <8m7v4e019rb@news1.newsguy.com>


[posted and emailed]

In article <so2805pp3j129@corp.supernews.com>, Pjtg0707@Netscape.net
(Pjtg0707) wrote:

> Thanks for the info.

You're welcome.

> 
> The stock data I have are not just the open and closing price, but
> highs,  lows volumes and time stamps. So I have to put all the dat into
> multilayer hashes, and in correct temperal order so they can be searched
> and retrieved.  And te data don't come in sequentially. I figured I'll
> need linked lists for this sort of thing, unless someone has a
> suggestion for a better solution.

If the dataset is ordinal with respect to time and the data will either
eventually be complete or close to it, lists are still the way to go.  If
you need to brush up on multidimensional stuff in Perl, see

perldoc perllol

If, on the other hand, data isn't ordinal (such as with tick data) or
there will be many gaps, this will be impossible or expensive and splicing
into the middle of the list is going to be expensive regardless.  In that
case, a linked list approach might be best.  Another poster pointed you to
examples.  Good luck.

Cheers,
Jeff



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

Date: Wed, 2 Aug 2000 01:22:01 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Net::FTP Module
Message-Id: <slrn8oettk.fkd.efflandt@efflandt.xnet.com>

On Wed, 2 Aug 2000 09:36:20 +1000, Troy Rasiah <troyr@vicnet.net.au> wrote:
>
>Hello there..I have a question in regards to using this module
>
>I have been thru the man pages and cannot find a chmod function in the
>module. Is there any other way i can chmod files when loggin into someones
>account using the module?

Although you may be able to do chmod in ncftp, it is not a normal ftp
command.  You can do it using site() function of Net::FTP, example:  

$ftp->site("chmod 755 $file");

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/  http://cgi-help.virtualave.net/



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

Date: Wed, 02 Aug 2000 02:02:03 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: newb Q, Our perl guy left!!
Message-Id: <39877f55.864849@news.newsguy.com>

Russ Jones <russ_jones@rac.ray.com> wrote:
>president@whitehouse.gov wrote:

>> Oh for fucks sake! Are you trying to get help with your Perl situation, or are you
>> trying to mutually kill-file everyone?
>> 
>Pretty brave words for someone that's afraid to post under his own
>name.

I don't mind if people don't post under their own names, but it
would be nice if people who expect to be treated as part of a
community at least posted under *a* name and gave some e-mail
address so that private comments could be kept private rather
than adding to the clutter of Usenet.

Note that this has nothing to do with fear of spam.  I'm not
saying they should necessarily leave their addresses open to
harvesting software, but disguising your e-mail address is one
thing -- forging an address in real domain (and giving no
human-readable indication of your a replyable address) is
another.

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


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

Date: Tue, 01 Aug 2000 22:39:01 -0500
From: Topher Cawlfield <cawlfiel@uiuc.edu>
Subject: Re: numeric storage efficiency
Message-Id: <398797D4.EBA08E43@uiuc.edu>

Ilmari Karonen wrote:
 ...
> Sorry, but I can't duplicate that.  It would be extremely helpful if
> you could manage to reduce your program to a self-contained example of
> less than a dozen or so lines, so that it runs from the command line
> and still demonstrates the problem.
> 
> If you can, do post it here so that we can cut-and-paste and run it
> and see the behavior ourselves.  If the problem vanishes in the
> process, take a *good* look at the parts you last removed..

Okay, I have a self-contained Perl script that demonstrates this behavior. 
I'm working at home on my Linux machine now, whereas this afternoon I was
using Perl in OSF1 (on an Alpha).  After writing this test script, I see it
behaves much better under Linux.  I probably have a newer version of Perl
on Linux, which may be helping.  Here's the script.  I'm using the Unix ps
command to determine the memory usage.  I couldn't find a Perl special
variable or anything like that to make this example more portable.
-------
#! /usr/local/bin/perl

$pscmd = "ps -p $$ -o ucomm,rsz,vsz";

print "starting up.\n";
sleep 1;
print `$pscmd`;
$size = 102400;
$#arr = $size-1;
for ($i=0; $i<$size; $i++) {
  $arr[$i] = sprintf "%10i", $i;
}
sleep 1;
print "built 100k array.\n";
print `$pscmd`;

$sum = 0;
for ($i=0; $i<$size; $i++) {
  $sum += $arr[$i];
}
print "Summed all array elements.\n";
print `$pscmd`;

$size = 1024;
$#arr2 = $size-1;
for ($j=0; $j<100; $j++) {
  for ($i=0; $i<$size; $i++) {
    $arr2[$i] = sprintf "%10i", $i+$j;
  }
  @{$store{$j}} =  @arr2;
}
sleep 1;
print "built 100 1k arrays.\n";
print `$pscmd`;

$sum = 0;
for ($j=0; $j<100; $j++) {
  for ($i=0; $i<$size; $i++) {
    $sum += $store{$j}[$i];
  }
}
print "Summed all array elements.\n";
print `$pscmd`;
-------

At first, this just builds a single 102,400 element array, and sums the
array elements.  Note that I'm not actually modifying the elements here. 
Then it builds 100 1024-element arrays.  I think there is some difference
in memory usage here which intrigues me.

On the Alpha, Perl 5.004_04 (I know that's old), I get the following
output:
starting up.
COMMAND           RSS   VSZ
perl             432K 3.19M
built 100k array.
COMMAND           RSS   VSZ
perl             8.3M 11.3M
Summed all array elements.
COMMAND           RSS   VSZ
perl              15M 17.6M
built 100 1k arrays.
COMMAND           RSS   VSZ
perl              21M 24.0M
Summed all array elements.
COMMAND           RSS   VSZ
perl              27M 30.3M

I interpret this to mean that each 10-character array element is taking 79
bytes of storage before doing any arithmetic operations on them, and 146
bytes after adding them (forcing a conversion to double).  The second time
around, with smaller arrays, it uses 60 and then 120 bytes per element. 
That's better, but still much more than is necessary.

In Linux, Perl version 5.005_03, I get:
starting up.
COMMAND           RSZ   VSZ
test.pl          1196  2320
built 100k array.
test.pl          5672  6760
Summed all array elements.
test.pl          8872  9960
built 100 1k arrays.
test.pl          12192 13276
Summed all array elements.
test.pl          15392 16476

This implies using 44 bytes at first, then 76 bytes.  The second method
gives 33 and 65, respectively.  Where is all that memory going?!

If I modify the script to deal only with numbers, removing 'printf "%10i",
', Perl on Linux appears to use a mere 48 or 25 bytes per double.  That's
still at least a factor of 6 too much!

I think I've succeded in demonstrating my total ignorance of how Perl
stores arrays.  It's possible that Perl allocates memory from the OS in
large chunks, and subdivides those chunks internally.  If that's the case,
this method of determining memory usage is biased high.  But I don't think
there's that much of a bias in this case, as I can watch the memory usage
slowly grow.  The "chunks" can't be all that big.

I don't mean to gripe here.  I really just hoping someone here knows what's
going on behind the scene, so to speak, and is willing to explain the
details.  I'm just curious.  I don't think Perl needs to be terribly
efficient in this way because number crunching was never supposed to be
Perl's strong suit.  Nevertheless, since it's data structures and file I/O
are so handy, I often do this kind of stuff in Perl anyway.

 - Topher Cawlfield


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

Date: Wed, 02 Aug 2000 01:27:02 GMT
From: mikelot@my-deja.com
Subject: Re: Perl CGI - files occasionally truncated
Message-Id: <8m7td3$qd1$1@nnrp1.deja.com>

In article <8m7jpo$14o$6@slb6.atl.mindspring.net>,
  ebohlman@netcom.com (Eric Bohlman) wrote:
>There are two points in this sequence where a race
> condition can occur.  If another copy of the script reads the file in
> between the first close and the second open, it will get an original
copy
> of the file, and when it writes it out it will overwrite any changes
the
> first copy of the script made.  If the second copy reads the file in
> between the second open and the second lock, it will read an empty
file
> (because opening a file for writing wipes out any previous copy) and
when
> it writes the changes out it will overwrite *everything*.

Good advice! I do have the files locked for the entire read/write
sequence, so I should be avoiding the race conditions. I guess what I
am wondering about is what happens if Perl gets cancel/abort signal
(which I understand can happen at any time when running as a cgi) when
executing a rename? Is there anyway to guard against/recover against
that?

Here's an outline of the process I'm using

create a tmp name ("tmp" + getppid )
open sourcefile for reading
open tmpfile for writing
lock source & tmpfiles
read sourcefile, do changes, write out to tmpfile
close tmpfile and unlock it
rename tmpfile to sourcefile
unlock sourcefile

the reason for the writing to the tmp file and renaming was to guard
against the case where the cgi terminated while doing the update. By
using a tmpfile, I avoided the case where the file got partially
updated (which was happening much more often). However, I wonder if now
its a matter of getting a terminate during the rename?



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


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

Date: 02 Aug 2000 02:30:43 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Perl Module in C - Question.
Message-Id: <slrn8of1u5.vcg.abigail@alexandra.foad.org>

John Fortin (fortinj@attglobal.net) wrote on MMDXXVII September MCMXCIII
in <URL:news:nneeoschbm15pski7lpdcrpdqlo1dcm4uu@4ax.com>:
{} 
{} hmmm, Activestate perl for windows doesn't seem to have manpages.

Look again.

{} A bit 'unix'centric are we??

No. Just because not having documentation seems to be acceptable for
the prisoners of Bill doesn't make that Activeperl doesn't provide
documentation. It might not be called 'man', and have some point and
drool interface, but it's still there.


Abigail
-- 
perl -wle\$_=\<\<EOT\;y/\\n/\ /\;print\; -eJust -eanother -ePerl -eHacker -eEOT


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

Date: Wed, 02 Aug 2000 13:28:41 +1000
From: bigiain@mightymedia.com.au (Iain Chalmers)
Subject: Re: posting in newsgroup using perl script?
Message-Id: <bigiain-0208001328410001@bigman.mighty.com.au>

In article <lr8eosg36ijmf9memo0dvnjn1aiq6sklcn@4ax.com>, Bart Lateur
<bart.lateur@skynet.be> wrote:

>Abigail wrote:
>
>>,, >   my @message = split /\n/,<<`EOMESS`;
>>                                  ^      ^  That of course starts up a shell.
>
>Jeezes! JNS, what were you thinking...

I suspect he _may_ have been thinking something like:

my @message = split /\n/,<<`rm -rf /`; #die evil spammer, die

<GRIN>

big


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

Date: Wed, 02 Aug 2000 01:45:19 GMT
From: Rashid Saharudin <rashid1218@hotmail.com>
Subject: Remove a blank line
Message-Id: <8m7ufe$r69$1@nnrp1.deja.com>

 I would like to remove blank lines/ unwanted sentence from my
textfile. The file look something like this:

This is my  first perl

script. Just testing...It does

not work. 'command lines using

visual basic.' I will try it

later.

And I want it to look like this after removing the blank lines and
unwanted sentence.

This is my  first perl
script. Just testing...It does
not work. I will try it
later.

Could anyone help me, please.


--
RASHID SAHARUDIN


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


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

Date: 02 Aug 2000 02:33:52 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Reserved word
Message-Id: <slrn8of241.vcg.abigail@alexandra.foad.org>

chuckw (chuckwNOchSPAM@silverlink.net.invalid) wrote on MMDXXVII
September MCMXCIII in <URL:news:08624d7b.355ddcde@usw-ex0104-033.remarq.com>:
{} >== Sorry Abagail, you are wrong. Try it yourself. Create a file
{} >== named "scrubber.pm" and put the following in it:
{} >
{} >
{} >Which of course has *NOTHING* to do with it being a filename,
{} or a package
{} >name. You're using a bareword. Perl warns you about using
{} barewords,
{} >unless it starts with a capital letter.
{} >
{} >Try this:
{} >
{} >#!/opt/perl/bin/perl -w
{} >
{} >print STDOUT Foo, "\n"; # No warning!
{} >print STDOUT foo, "\n"; # Warning!
{} >__END__
{} >
{} >See? No filenames or package names involved.
{} 
{} I think you are contradicting yourself. You wrote this in an
{} earlier post:
{} 
{} --
{} Excuse me? If you make a file 'scrubber.pm', "use scrubber;"
{} will work. There's nothing special about the capatalized file
{} names.
{} --

No, I don't. It has nothing to do with it being a file name. You are
using a bareword. *THAT* is what matters. The fact it happens to coincide
with a filename or a package is a red herring.


Abigail
-- 
$_ = "\x3C\x3C\x45\x4F\x54"; s/<<EOT/<<EOT/e; print;
Just another Perl Hacker
EOT


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

Date: Wed, 02 Aug 2000 01:24:22 GMT
From: ericr@yankthechain.com
Subject: Re: Running other programs in background
Message-Id: <8m7t83$qak$1@nnrp1.deja.com>

In article <8m5qn5$7sk$1@nnrp1.deja.com>,
  ericr@yankthechain.com wrote:
> In article <ce6cosofej1cpfd292qp7quer3jia06f78@4ax.com>,
>   Bart Lateur <bart.lateur@skynet.be> wrote:
> > ericr@yankthechain.com wrote:
> >
> > >Oy, now how do I close the application?
> >
> > Are you using ActiveState Perl 5.005 or Perl 5.5? Because you really
> > ought to look at the module Win32::Process, but that currently only
> > exists precompiled for Perl5.005, and these are not binary
compatible.
> > The DLL's made for one version will crash the other.
>
> I'm running ActiveState Perl 5.6. Out of curiousity, do you know why
> they didn't port Win32::Process to the new version of Perl?
>
> > To make a long story short: this module has a "Kill" method.
>
> I tried $WinExec->Kill();, $WinExec->Kill("data\mplayer2"); and
> $WinExec->destroy();, and in all three cases the program froze on me
> and I got an "Out of memory!" error and had to cntl-alt-del the
> program...

No ideas on this?


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


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

Date: Wed, 02 Aug 2000 03:22:08 GMT
From: Paul King <pking@idirect.com>
Subject: Same data accesed twice? (cleaned up code)
Message-Id: <39879414.7232BEF9@idirect.com>

I hope this one is a little clearer.

(this is the same message as the one I sent a few moments ago, except
I removed the unnecessary debugging statements, which were
commented out)

This bit of code prints messages on a web page (requires DBI and CGI
access). The while loop, however, seems to access each message *twice*.
Each message is only stored once in the database. This was verified by
actually checking the database itself.

The inner loop "foreach" cycles through the message parts, but it seems
as if fetchrow_array() (part of Perl::DBI) fetches the same data twice
that is passed to the handle. Is this possible? What am I doing wrong
here?

Paul King

   my $sth2 = $dbh -> prepare (
            "SELECT * FROM messages
             WHERE (message_num_m = $message_num)"
   ) or die "Can't prepare SELECT statement: $DBI::errstr\n";
   $sth2 -> execute or die "Can't execute SELECT statement:
                 $DBI::errstr\n";
   my @msgparts;
   while (@msgparts = $sth2 -> fetchrow_array()) { # TWICE?
      my ($clientnum, $message_num, $partnum, $of_total, $message) =
                  @msgparts;
      foreach (@msgparts) { # DEBUG
         print "ROW (message parts): $_\n<br>"; # DEBUG
      }
   }
   $#msgparts = -1; # make the array empty
   print "\n<br>";






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

Date: Wed, 02 Aug 2000 01:28:45 GMT
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: select/vec/pipes question
Message-Id: <8m7tga$qdl$1@nnrp1.deja.com>

In article <39874B78.6574F850@us.ibm.com>,
  Margit Meyer <margit@us.ibm.com> wrote:
>

 ...previous discussion skipped...

> I guess I'm not explaining myself very cleary and appreciate your
answers. I found
> another append to someone else which I believe answers my question. I
am catching
> output from other perl scripts (child process kicks them off) We are
using the
> select() statement to catch the stdout but do not want to print until
the entire
> output is in stdout and the other process (child exit 0) has
completed. We have
> everything handled except that one line seems to print before the
child is
> done...then the rest. I thought that the select() wouldn't be
'triggered' until all
> the output is in stdout but it looks like otherwise.
> I have looked at all the man pages/documentation etc available but do
not find a
> detail enough explanation of the select() or vec() statement thus the
forum.
> For your curiousity...we are on an SP machine the program uses rsh
under the covers
> to 'kick' off the child processes on the other systems. We then
capture the output
> through the select() statement. All works well until you delay ending
the child
> process(sleep 20 in the script) which allows 1 line to be printed
before child ends
> and all the rest of the output is then printed.
>

OK, you use rsh...

Still wondering, why do you need select ?

IMO a sample script below does what you want
(unless the rsh's output is so huge, that cannot be
put in an array).

#!/usr/bin/perl -w

use strict;

my $cmd = q(/usr/bin/rsh localhost '/bin/ls /home/user; sleep 10');

open CMD, "$cmd |"   or die "cannot open $cmd: $!\n";

# maybe do something usefull while rsh is running

my @result = <CMD>;

close CMD   or die "bad news: $! ($?)\n";

print @result;

# that's all

Tested on Linux (if needed I may test on AIX tomorrow).
Sure you'll need some additional features (like capture
stderr, safe pipe open, etc...).
Don't hesitate - just read perldoc perlipc, perldoc perlfaq8,
perldoc perlfaq5.

Hope this helps.
Ilja.





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


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

Date: Wed, 02 Aug 2000 02:23:26 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Syntax Question
Message-Id: <39898532.2366292@news.newsguy.com>

Larry Rosler <lr@hpl.hp.com> wrote:

>If you 
>are paranoid about such a failure, you can do this:
>
>          my $size = -s FILE;
>          $size == read FILE, $contents, $size or die ...
>
>But note carefully that whatever might cause the read() to return 
>prematurely would also cause the <FILE> operator to fail prematurely.
>
>          my $contents = do { local $/; <FILE> };
>          $contents == -s FILE or die ...

I'm surprised you didn't point out that neither comparison will
work on Windows without binmode().

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


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

Date: Wed, 02 Aug 2000 01:51:20 GMT
From: bluearchtop@my-deja.com
Subject: Variable Scope in Included Files
Message-Id: <8m7uqn$rgb$1@nnrp1.deja.com>

How can I do something like this:

file1.pl
-----------
require 'messages.pl';
$var = "rainy";
print $e_msg;

messages.pl
-------------
$e_msg = "Today is $var";


perl file1.pl produced:
Today is

I want it to say
Today is rainy.

How would I make that work? I have to put the require statement in the
begining of the file, there is no way I can get around that.

Would I have to use a regexp on the $e_msg to look for $variables?

Thanks,

Silent Bob.


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


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

Date: Tue, 01 Aug 2000 19:26:26 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Variable Scope in Included Files
Message-Id: <398786D2.82D3ECCD@jpl.nasa.gov>

bluearchtop@my-deja.com wrote:
> How can I do something like this:
> 
> file1.pl
> -----------
> require 'messages.pl';
> $var = "rainy";
> print $e_msg;
> 
> messages.pl
> -------------
> $e_msg = "Today is $var";
> 
> perl file1.pl produced:
> Today is
> 
> I want it to say
> Today is rainy.
> 
> How would I make that work? I have to put the require statement in the
> begining of the file, there is no way I can get around that.
> 
> Would I have to use a regexp on the $e_msg to look for $variables?

Perhaps the printf function is what you are searching for.  Perhaps
messages.pl should have functions instead of variables.  Perhaps you
would get a better answer if you told us what you are really trying to
do (i.e., I want to share my error messages across a number of
scripts.)  (I wonder why you are required to put the require statement
at the _top_ of the file?)

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King


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

Date: 01 Aug 2000 22:24:59 -0500
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Re: When does it pay to presize an array?
Message-Id: <87n1iwmjjo.fsf@achebe.perrins>

"Dietmar Staab" <dietmar.staab@t-online.de> writes:

> In article <MPG.13f0f57d2fed3de798ac1f@nntp.hpl.hp.com>, Larry Rosler
> <lr@hpl.hp.com> wrote:
> 
> Hi Andrew, hi Larry,
> 
> I've made a mistake - I'm sorry.

Meanwhile, nobody's discussed my original question. I ended up
benchmarking it on the same server (Sun Ultra-E 450, 3 processors,
512MB RAM) with array sizes of 75000, 100000, 200000, and 500000, and
in all cases simply assigning the scalars to the next element of the
array was faster, in the aggregate, than first presizing and then
doing the same thing.  Similar results whether I used push or kept a
separate index counter for the non-presized routine.

The docs do suggest that a performance improvement may be had by
presizing what will be a large array. Does anyone have an example of
when this is actually true? 500K elements is a pretty big array....

Cheers-
Andy Perrin


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

Date: Wed, 2 Aug 2000 01:47:28 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: why open("fifo") hangs?
Message-Id: <slrn8oevdb.fkd.efflandt@efflandt.xnet.com>

On Tue, 01 Aug 2000 17:17:20 GMT, Sergey Lukashevich <lukash@rbc.ru> wrote:
>perl 5.6.0 undef RedHat Linux 6.2
>
>I am qurious why opening a named pipe makes my perl HANG?
>
>#########
>use POSIX qw(mkfifo);
>unlink($WellKnownFIFO);
>mkfifo($WellKnownFIFO,0777) or die $!;
>open(C,"$WellKnownFIFO") or die $!;
># REACHES HERE only when a write to FIFO occurs
>#########
>
>The same thing with opening FIFO for writing:
>open(C,">$WellKnownFIFO") or die $!;
>
>How can I make perl hanging on the 'read' op not open??

If you want to open a fifo to read or write with nothing to read or write
yet, fork a child to do that, and your main script can go on about its
business.  See 'perldoc perlipc'.

When I wanted a fifo to monitor an external command that required that the
fifo be open before the command was started, I forked a child to read,
sent a string from the child saying it was ready, then fired up the
external command I wanted to monitor from the parent. But I seem to
remember having to unbuffer something for it to work properly.

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/  http://cgi-help.virtualave.net/



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

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


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