[28386] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9750 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 21 18:05:58 2006

Date: Thu, 21 Sep 2006 15:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 21 Sep 2006     Volume: 10 Number: 9750

Today's topics:
    Re: Deleting characters from the end of each line <uri@stemsystems.com>
    Re: Deleting characters from the end of each line <mritty@gmail.com>
    Re: Deleting characters from the end of each line <someone@example.com>
    Re: Deleting characters from the end of each line <uri@stemsystems.com>
    Re: explaining how memory works with tie()ed hashs <botfood@yahoo.com>
    Re: explaining how memory works with tie()ed hashs <glex_no-spam@qwest-spam-no.invalid>
    Re: explaining how memory works with tie()ed hashs xhoster@gmail.com
    Re: explaining how memory works with tie()ed hashs <botfood@yahoo.com>
    Re: explaining how memory works with tie()ed hashs <botfood@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 21 Sep 2006 14:23:11 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Deleting characters from the end of each line
Message-Id: <x78xkdf59s.fsf@mail.sysarch.com>

>>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:

  PL> amrussell wrote:
  >> I am trying to figure out how I can go to the end of each line in a
  >> report and delete an exact number of characters from right to left.  I
  >> have some characters at the end of each line in some reports I am
  >> processing and I want to get rid of them.  I know how to do a search
  >> and replace, but the patterns are never the same.  Can any one help?

  PL> s/// is useful to remove specific patterns.
  PL> substr() is useful to remove specific numbers of characters.

  PL> substr($s, -3) = q{};
  PL> for example, will remove the last three characters of $s.

i like 4 arg substr and it is faster than lvalue substr:

	substr( $s, -3, 3, '' ) ;

the biggest annoyance is there is no way to do a wildcard length to the
end of the string so you have to pass in a proper length value.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 21 Sep 2006 11:30:55 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Deleting characters from the end of each line
Message-Id: <1158863455.605030.113140@m73g2000cwd.googlegroups.com>

Uri Guttman wrote:
> >>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:
>   PL> substr($s, -3) = q{};
>   PL> for example, will remove the last three characters of $s.
>
> i like 4 arg substr and it is faster than lvalue substr:
>
> 	substr( $s, -3, 3, '' ) ;
>
> the biggest annoyance is there is no way to do a wildcard length to the
> end of the string so you have to pass in a proper length value.

I knew *someone* would bring this up. :-)   While I know about the
4-arg substr, I've just never gotten the hang of reading it correctly,
and it always causes me to do a doubletake.  Even though the concept of
a lvalue subroutine is weird, that version of it "reads" correctly to
me.  ("Make this substring of the string into this").

TIMTOWTDI, and all...

Paul Lalli



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

Date: Thu, 21 Sep 2006 19:35:52 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Deleting characters from the end of each line
Message-Id: <sQBQg.19905$KA6.13246@clgrps12>

Tad McClellan wrote:
> amrussell <arussell@leggmason.com> wrote:
> 
>> I am trying to figure out how I can go to the end of each line in a
>>report and delete an exact number of characters from right to left.
> 
> 
>    perldoc -f substr
> 
> 
>>Can any one help?
> 
>    substr($str, -$exact_number_of_characters, length $str, '');

ITYM:

substr($str, -$exact_number_of_characters, $exact_number_of_characters, '');


John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 21 Sep 2006 16:19:11 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Deleting characters from the end of each line
Message-Id: <x7u031dlc0.fsf@mail.sysarch.com>

>>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:

  PL> Uri Guttman wrote:
  >> >>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:
  PL> substr($s, -3) = q{};
  PL> for example, will remove the last three characters of $s.
  >> 
  >> i like 4 arg substr and it is faster than lvalue substr:
  >> 
  >> substr( $s, -3, 3, '' ) ;
  >> 
  >> the biggest annoyance is there is no way to do a wildcard length to the
  >> end of the string so you have to pass in a proper length value.

  PL> I knew *someone* would bring this up. :-)   While I know about the
  PL> 4-arg substr, I've just never gotten the hang of reading it correctly,
  PL> and it always causes me to do a doubletake.  Even though the concept of
  PL> a lvalue subroutine is weird, that version of it "reads" correctly to
  PL> me.  ("Make this substring of the string into this").

i will give you a big help on grokking 4 arg substr. it has the SAME API
as splice but for strings. splice always has had the 4th arg (actually a
list) to replace the list you splice out. the only main diff is that
splice removes elements but substr only copies them. both can be used to
insert stuff (without deleting) in the middle of their targets as well

a very rare but interesting use of substr is that you can take a ref to
it and pass that around to stuff like s///. splice can't do that.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 21 Sep 2006 11:18:34 -0700
From: "botfood" <botfood@yahoo.com>
Subject: Re: explaining how memory works with tie()ed hashs
Message-Id: <1158862714.163580.154320@d34g2000cwd.googlegroups.com>


botfood wrote:
> I would like to know more about how perl uses memory when managing a
> hash that is tie()ed to a file on disk. Using DB_File and variable
> length records....
 ...snip
> In this particular case, each record is not that big, except for one
> specific type of 'book-keeping' record that is used to keep track of
> what records are considered 'complete' by this particular application.
> With a couple reports, I need to whip thru all complete records
> searching for various things.... And in another spot I know that the
> code looks for matches within this big record that contains around 20k
> 'words' consisting of about 20 digits.
> ------------------------------

thanks for comments so far people.... its sounding like my suspicion
that the memory problems I am having are more likely to be from using a
'record' inside the DB to manage a large list of values, which I need
to sift, sort, and edit... is more likely to be the problem than the
memory allocated to manage the access and paging of the DB itself.

Allow me to clarify in that the nature of the failure SEEMED to be more
like a limit placed by the Apache Web Server running the process,
rather than a hard limit on memory available on the machine.

while I think I am going to try some re-design to extract the hash of
'complete' records to a separate DB, I am trying to get a handle on a
short-term fix by increasing the Apache::SizeLimit parameter to accept
the memory use required for the current design.

so.... the question changes to:

how can I estimate the memory required by perl for a m// or s//
operation on a string that is about 20k 'words' consisting of 20 digits
each separated by a single space.

thanks,
d



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

Date: Thu, 21 Sep 2006 14:26:17 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: explaining how memory works with tie()ed hashs
Message-Id: <4512e69c$0$34082$815e3792@news.qwest.net>

botfood wrote:

> so.... the question changes to:
> 
> how can I estimate the memory required by perl for a m// or s//
> operation on a string that is about 20k 'words' consisting of 20 digits
> each separated by a single space.

Why estimate it? Simply run it from the command line, or some other 
method, maybe adding a fairly long sleep, after the point you want to 
measure, and watch the memory usage using top, ps, etc.


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

Date: 21 Sep 2006 19:41:43 GMT
From: xhoster@gmail.com
Subject: Re: explaining how memory works with tie()ed hashs
Message-Id: <20060921154315.016$3z@newsreader.com>

"botfood" <botfood@yahoo.com> wrote:
>
> so.... the question changes to:
>
> how can I estimate the memory required by perl for a m// or s//
> operation on a string that is about 20k 'words' consisting of 20 digits
> each separated by a single space.

I just system out to "ps" (on linux).

It seems to be trivial, as long the regex doesn't degenerate badly.


$ perl -le 'my $x = join " ", map rand, 1..20_000; \
            $_=~s/1[23]45/foobar/g; system "ps -p $$ -o rss ";'
 RSS  #(this is the size in kilobytes)
4340


$ perl -le 'my $x = join " ", map rand, 1..20_000; \
            $x=~s/1[23]45/foobar/g; system "ps -p $$ -o rss ";'
 RSS
4476

So it takes about 136K more to do the substitution than it does just to
start perl and build the string (plus do a dummy substituion on an empty
varaible)

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 21 Sep 2006 13:15:05 -0700
From: "botfood" <botfood@yahoo.com>
Subject: Re: explaining how memory works with tie()ed hashs
Message-Id: <1158869704.987127.169510@m73g2000cwd.googlegroups.com>


J. Gleixner wrote:
> botfood wrote:
>
> > so.... the question changes to:
> >
> > how can I estimate the memory required by perl for a m// or s//
> > operation on a string that is about 20k 'words' consisting of 20 digits
> > each separated by a single space.
>
> Why estimate it? Simply run it from the command line, or some other
> method, maybe adding a fairly long sleep, after the point you want to
> measure, and watch the memory usage using top, ps, etc.
----------------
the machine running the script is a webserver on a remote host... they
dont give access to any place I can watch memory.



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

Date: 21 Sep 2006 13:23:55 -0700
From: "botfood" <botfood@yahoo.com>
Subject: Re: explaining how memory works with tie()ed hashs
Message-Id: <1158870235.087935.230150@m73g2000cwd.googlegroups.com>


xhoster@gmail.com wrote:

> I just system out to "ps" (on linux).
>
> It seems to be trivial, as long the regex doesn't degenerate badly.
>
>
> $ perl -le 'my $x = join " ", map rand, 1..20_000; \
>             $_=~s/1[23]45/foobar/g; system "ps -p $$ -o rss ";'
>  RSS  #(this is the size in kilobytes)
> 4340
>
>
> $ perl -le 'my $x = join " ", map rand, 1..20_000; \
>             $x=~s/1[23]45/foobar/g; system "ps -p $$ -o rss ";'
>  RSS
> 4476
>
> So it takes about 136K more to do the substitution than it does just to
> start perl and build the string (plus do a dummy substituion on an empty
> varaible)
> -----------------------------------------

not sure exactly what you did with these little tests to build the test
string, but think the estimate is moving in the right direction. The
exact size value I think might be low since each of my 20k 'words' is
20 characters long rather than a random number.

unfortunately I do not have access to the LINUX machine since it is a
remote web server.....

d



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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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