[19314] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1509 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 13 14:05:48 2001

Date: Mon, 13 Aug 2001 11:05:15 -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: <997725915-v10-i1509@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 13 Aug 2001     Volume: 10 Number: 1509

Today's topics:
    Re: $string = s/\|//g; error - why? <mjcarman@home.com>
    Re: Accessing a widget when defined local to a sub <Pcmann1@btinternet.com>
    Re: Accessing a widget when defined local to a sub <joe+usenet@sunstarsys.com>
        Anyone know a mailist list opt-in script that can autom (Jerry)
        array question... sort of <leary@foad.NOSPAM.org>
    Re: array question... sort of (Tad McClellan)
    Re: array question... sort of <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Coercing list context onto pair of regexps in a com <ren@tivoli.com>
        Expiration dates for cookies <mieskolaNOSPAM@hfl.tc.faa.gov>
    Re: FTP commands <jeroen.erkens@ing-barings.com>
    Re: help with a global variable in CGI nobull@mail.com
        installing xml-sablotron... ? <kmojar@bmjgroup.com>
    Re: Line counting in a file <iltzu@sci.invalid>
        NTTP > HTTP Gateway? <webmaster@1360squadron.co.uk>
    Re: Perl5 memory leak or garbage collection problems? <iltzu@sci.invalid>
        Read numbers <nll@nospam.com>
    Re: Read numbers <cberry@cinenet.net>
    Re: Read numbers (Malcolm Dew-Jones)
    Re: regex question... <strawSPAM_BEGONEman@plexi.com>
    Re: regex question... <ren@tivoli.com>
    Re: repeating substituation <richard@sunsetandlabrea.com>
    Re: Rounding a number (Tad McClellan)
    Re: Saving Parse::RecDescent Errors for Later Processin (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 13 Aug 2001 11:01:25 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: $string = s/\|//g; error - why?
Message-Id: <3B77F9D5.40AD0307@home.com>

Richard Lawrence wrote:
> 
> I'm a little lost. Can someone please explain to me why:
> 
>   $string = s/\|//g;
> 
> causes the error:
> 
>   Use of uninitialized value in substitution (s///)

Hint: What does $string contain?

-mjc


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

Date: Mon, 13 Aug 2001 17:03:35 +0100
From: "Peter Mann" <Pcmann1@btinternet.com>
Subject: Re: Accessing a widget when defined local to a sub
Message-Id: <9l8tmv$ckh$1@uranium.btinternet.com>


Dear all,
Thanks for the advice, but the code you suggested still doesn't allow me to
access the combo1 from outside the 'donotebook' subroutine. For instance,
upon pressing the button which calls 'comboInsert', the element still isnt
inserted into the combo box!
The code you provided only works within donotebook!
Or im I missing some obvious point?

Thanks in advance
  - Pete


use Tk;
use Tk::DialogBox;
use DBI;
use Tk::NoteBook;
use Tk::LabEntry;
use TK::BrowseEntry;
use strict;

use vars qw($top);

$top = MainWindow->new;
my $pb = $top->Button(-text => "Notebook", -command => \&donotebook);
$pb->pack;
MainLoop;

my $f;

sub donotebook {
    if (not defined $f) {

 $f = $top->DialogBox(-title => "Example",
        -buttons => ["OK", "Cancel"]);
 my $n = $f->add('NoteBook', -ipadx => 6, -ipady => 6);

 my $page1_p = $n->add("page1", -label => "Page 1");
 my $page2_p = $n->add("page2", -label => "Page 2");

 my $combo1=$page1_p->BrowseEntry(-label=>"combo box : ");
 $combo1->pack(-side=>'top', -anchor=>'nw');
 $n->pageconfigure("page1", -createcmd=>sub{fillCombo($combo1)});

 my $insert_combo = sub {
   my($text) = @_;
   $combo1->insert('end', $text);
 };

 $insert_combo->('five');

 $page1_p->Button(-text=>"Go", -command=>\&comboInsert)
                               ->pack(-side   => 'top', -anchor => 'e');

 $n->pack(-expand => "yes",
   -fill => "both",
   -padx => 5, -pady => 5,
   -side => "top");
  }
  my $result = $f->Show;
}


sub fillCombo
{
  my $combo1=shift;
  $combo1->insert('end', "one", "two", "three");
}



############# This still DOESNT work ###########
sub comboInsert
{
  $insert_combo->('five');
}




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

Date: 13 Aug 2001 12:36:38 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Accessing a widget when defined local to a sub
Message-Id: <m3snevapd5.fsf@mumonkan.sunstarsys.com>

"Peter Mann" <Pcmann1@btinternet.com> writes:

> Dear all,
> Thanks for the advice, but the code you suggested still doesn't allow me to
> access the combo1 from outside the 'donotebook' subroutine. For instance,
> upon pressing the button which calls 'comboInsert', the element still isnt
> inserted into the combo box!
> The code you provided only works within donotebook!
> Or im I missing some obvious point?

I recommend you stick to anonymous subs in donotebook()
instead of directly referencing named subs in your handlers.

[...]

>  my $combo1=$page1_p->BrowseEntry(-label=>"combo box : ");
>  $combo1->pack(-side=>'top', -anchor=>'nw');
>  $n->pageconfigure("page1", -createcmd=>sub{fillCombo($combo1)});
                                          ^^^^^^^^^^^^^^^^^^^^^^^
That's just fine as it is.

> 
>  my $insert_combo = sub {
>    my($text) = @_;
>    $combo1->insert('end', $text);
>  };

So is this.

> 
>  $insert_combo->('five');
> 
>  $page1_p->Button(-text=>"Go", -command=>\&comboInsert)
                                            ^^^^^^^^^^^^

No good- you need to pass the value of $combo1 (or $insert_combo) to 
comboInsert at runtime (when donotebook is actually executed).  

The simplest change to fix this is to rewrite this line similar to 
your earlier ones:

  ...(-text=>"Go", -command=> sub { comboInsert($insert_combo) } )


[...]

> sub fillCombo
> {
>   my $combo1=shift;
>   $combo1->insert('end', "one", "two", "three");
> }

That's fine,

> 
> ############# This still DOESNT work ###########
> sub comboInsert
> {
>   $insert_combo->('five');
> }
> 

but change this to repeat the same pattern as fillCombo:

  sub comboInsert {
    my $insert_combo = shift;
    $insert_combo->('five');
  }


Some OO-type tricks (like using a package with some inheritance) 
might clean up your code a bit, but the pattern should be clear
to you now.  See perlmod, perltoot and perlobj for some additional 
ideas.

HTH

-- 
Joe Schaefer       "Technological progress is like an axe in the hands of a
                                   pathological criminal."
                                               --Albert Einstein



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

Date: 13 Aug 2001 10:57:46 -0700
From: jnance@earthlink.net (Jerry)
Subject: Anyone know a mailist list opt-in script that can automatically send daily messages?
Message-Id: <18f2db06.0108130957.21a3c285@posting.google.com>

Hello,

Does anyone know a mailist list opt-in script that can automatically
send daily messages?

I need a script where I can add 7 days of meditations and have the
script send out each daily meditation automatically for the week.

I have seen lots of mailing list scripts, but I haven't found one that
will send out automatic messages for the days of the week.

Thanks for any suggestions.
Jerry


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

Date: Mon, 13 Aug 2001 10:28:45 -0500
From: "Leary" <leary@foad.NOSPAM.org>
Subject: array question... sort of
Message-Id: <3ASd7.20400$V43.1211884@e3500-atl1.usenetserver.com>

I'm using the below script to create an array of arrays that is the output
of a dos command. What I need to do next is create an array for each $acct
so I can seperate all the transactions by account in order to generate
totals. My question then is this; how can I use an element of one array as
the name of another array?
(I'm thinking a seperate array for each account.)
Am I on the wrong track entirely? Is there another method that seems better
suited to this task?

I would appreciate being pointed in the write direction.

TIA

<<begin script>>
#!perl
#8/12/2001 11:22PM
open (TESTDATA, 'VHOUSE3 %IBERDIR%\\DATA\\HOUSE50|') or die "Can't run
vhouse3.exe";
while (<TESTDATA>) {
#This line is only for the purpose of rejecting the header info from the
output of the dos command.
#Valid data has a time field as the first field. (Gotta be a better way to
reject the header lines)
my ($ttime, $AmPm, $tday, $tmonth, $tdate, $tyear, $acct, $type, $amt, $tip,
$prt, $purge) = split;
push @array, [ split ] if "$ttime" =~ /\d\d:\d\d:\d\d/;
}
$tot = 0;
for $i ( 0 .. $#array ) { # $#array is the total number of rows in the array
 $tot += "$array[$i][8]";
}
printf "%10d %68.2f\n", $#array, $tot;
>>end script<<

<<begin sample data>>

VHOUSE2 v5.011 Copyright (C) 1994 by Yoho, Inc.
Time                           ACCT    TYPE      AMT     TIP  PRINT PURGE
----------------------------  -----  --------  ------  ------ ----- -----
02:00:00 PM Thu Apr 12, 2001  03422    CHARGE    6.25    0.00 FALSE FALSE
02:00:00 PM Thu Apr 12, 2001  09562    CHARGE    8.50    0.00 FALSE FALSE
02:00:00 PM Thu Apr 12, 2001  02129    CHARGE   30.68    0.00 FALSE FALSE






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

Date: Mon, 13 Aug 2001 11:58:58 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: array question... sort of
Message-Id: <slrn9nfua1.57t.tadmc@tadmc26.august.net>

Leary <leary@foad.NOSPAM.org> wrote:

>I'm using the below script to create an array of arrays that is the output
>of a dos command. What I need to do next is create an array for each $acct
>so I can seperate all the transactions by account in order to generate
>totals. My question then is this; how can I use an element of one array as
>the name of another array?


Warning Will Robinson!

Quickly approaching Symbolic references. Advise changing course...


>(I'm thinking a seperate array for each account.)


Stop thinking that  :-)


>Am I on the wrong track entirely? 


Yes, most probably.


>Is there another method that seems better
>suited to this task?


Yes, a hash of arrays (HoL) instead of a bunch of individually 
named arrays.


>I would appreciate being pointed in the write direction.

   http://www.plover.com/~mjd/perl/varvarname.html
   http://www.plover.com/~mjd/perl/varvarname2.html
   http://www.plover.com/~mjd/perl/varvarname3.html

along with the Perl FAQ, part 7:

   "How can I use a variable as a variable name?"


><<begin script>>
>#!perl


   #!perl -w
   use strict;


You should enable warnings and strictures. Take all the help you can get!


>#8/12/2001 11:22PM
>open (TESTDATA, 'VHOUSE3 %IBERDIR%\\DATA\\HOUSE50|') or die "Can't run
>vhouse3.exe";


That is a pretty misleading diagnostic message, as the failure of
the open() does NOT indicate a problem with vhouse3.exe. It indicates
a problem with being able to fork, so as to _then_ be able to try
executing it. Perl FAQ, part 8:

   "Why doesn't open() return an error when a pipe open fails?"


>while (<TESTDATA>) {
>#This line is only for the purpose of rejecting the header info from the
>output of the dos command.
>#Valid data has a time field as the first field. (Gotta be a better way to
>reject the header lines)
>my ($ttime, $AmPm, $tday, $tmonth, $tdate, $tyear, $acct, $type, $amt, $tip,
>$prt, $purge) = split;


If you only want the first list element, then a "list slice":

   my($ttime) = (split)[0];

will get what you want without the need for a bunch of dummy variables.


>push @array, [ split ] if "$ttime" =~ /\d\d:\d\d:\d\d/;
                           ^      ^
                           ^      ^
Those double quotes serve no purpose, so they should not be there:

   push @array, [ split ] if $ttime =~ /\d\d:\d\d:\d\d/;


>$tot = 0;
>for $i ( 0 .. $#array ) { # $#array is the total number of rows in the array
> $tot += "$array[$i][8]";
>}


When you find yourself explicitly indexing into an array, you
should pause and consider if you doing it the "non-Perl way". 
You seldom need to index arrays yourself in Perl:

   foreach my $aref ( @array ) {
      $tot += $aref->[8];
   }

Let perl manage the indexing for you. Machines make mistakes far
less often than people do  :-)


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


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

Date: Mon, 13 Aug 2001 18:49:50 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: array question... sort of
Message-Id: <3B78052E.2080909@post.rwth-aachen.de>

Leary wrote:
> I'm using the below script to create an array of arrays that is the output
> of a dos command. What I need to do next is create an array for each $acct
> so I can seperate all the transactions by account in order to generate
> totals. My question then is this; how can I use an element of one array as
> the name of another array?

Don't do it. It is possible since in Perl one can manipulate the 
package's symbol-hash. But creating variables with dynamic names is only 
working if you turn off strict 'refs'. By the way, you do not use the 
strict-pragma at all which is a bad idea [1].

Anyway: For your task, the best thing would be a hash whose keys can 
certainly be the value of an array-element. Thus:

my @array = qw(a b c);
my %hash;
$hash{$_} = 1 for @array;

This will create this structure:
%hash = (
		'a' => 1,
		'b' => 1,
		'c' => 1,
	);

As for hashes of arrays, the same applies as when creating arrays of 
arrays. That is: You add an array by reference:

$hash{key} = [ ('a', 'b', 'c') ];

which is equiv to

$hash{key} = \@array;

Tassilo

[1]: Along with the fact that you didn't indent your code which makes it 
hard to read.

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: 13 Aug 2001 11:07:14 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Coercing list context onto pair of regexps in a comparison
Message-Id: <m3wv487xl9.fsf@dhcp9-161.support.tivoli.com>

On Fri, 10 Aug 2001, brentdax1@earthlink.net wrote:

> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:9l0v35$ql$2@mamenchi.zrz.TU-Berlin.DE...
>> According to Brent Dax <brentdax1@earthlink.net>:
>> > "pt" <mnemotronic@yahoo.com> wrote in message
>> > news:da662010.0108091512.75f7c4d3@posting.google.com...
>> > > I would like to force a pair of regular expressions to be
>> > > evaluted in list context, so that they return $1.
>> > >
>> > > next unless ("\L$A" =~ /.*\.(.+)$/) eq ("\L$B" =~ m#.*/(.*)$#)
>> > > ; ----------------------- -----------------------
>> > >
>> > >   The goal is to compare the file extension portion of $A
>> > >   (after the '.') with the filename portion of $B (after the
>> > >   last '/' delimiter), and do something if equal/not equal.
>> > >   List context for each regexp portion (underlined) will force
>> > >   each to return the grouped expression ($1) for the string
>> > >   comparison.
>> >
>> > What's wrong with just using m{(?<=\.).*$} and m{(?<=/).*$} ?
>>
>> Nothing is wrong, but unless I'm dense I don't see how it solves
>> the problem.  We want to know if what the first .* matches is the
>> same thing (modulo upper/lower case) the second .* matches.
> 
>     next unless m{(?<=\.).*$} eq m{(?<=/).*$};
> 
> Since the lookbehinds are used, the dot or slash isn't part of the
> RE--thus, we don't need to force list context, we can just compare
> the return values in scalar context directly.

There are several problems there.  Matching against $_ is one, though
easily addressed.  The more serious is that the scalar value of a
match is simply a Boolean value indicating whether or not the match
was successful.  This isn't going to compare the matched strings in
any way.

Here is a slightly different solution:

  next unless $A =~ /\.(.+)$/ and $B =~ m{/$1$}i;

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 13 Aug 2001 11:47:13 -0500
From: "A.J. Mieskolainen Titan/SRC x4946" <mieskolaNOSPAM@hfl.tc.faa.gov>
Subject: Expiration dates for cookies
Message-Id: <3B780491.48C6DA74@hfl.tc.faa.gov>

OK,  I have successfully figured out how to set and retrieve cookies, is
there anyway I can set a cookie to die when the browser it was set on
dies?  Thanks.

AJ

--
2nd place is 1st loser





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

Date: Mon, 13 Aug 2001 16:23:46 +0100
From: Jeroen <jeroen.erkens@ing-barings.com>
Subject: Re: FTP commands
Message-Id: <3B77F102.CAADDF03@ing-barings.com>

Gerard,

Thanks for the URL to the RFC - it guided me to what the responses were from
the server. After a bit of trial and error, it appears that the first format
($ftp->quot( "authenticate", "blargh")) is the way to go.

Cheers again,
Jeroen


Gerard Lanois wrote:

> Jeroen <jeroen.erkens@ing-barings.com> writes:
>
> > I have read the documentation. I've also asked colleagues and searched
> > the web. No luck. The documentation says stuff all:
> >
> > $ftp->quot(cmd[,arg])
> > Sends s literal FTP protocol command to the server and waits for a
> > response. Returns the most significant digit of the response code.
> >
> >
> > What is the response code and what does each value indicate?
>
> http://www.faqs.org/rfcs/rfc959.html
>
> Scroll way down to section 4.2.
>
> > Do I use
> > $ftp->quot( "authenticate", "blargh"),
>
> From looking at the source code (Cmd::command), I think this is
> probably the form you want.
>
> Be warned that the word "authenticate" does not appear
> in the RFC, so I assume this is some kind of extension
> command your particular flavor of FTP server supports?
>
> Or maybe you need to submit this via the SITE command, so
> maybe you need to do this:
>
>   $ftp->quot( "SITE", "authenticate", "blargh");
>
> Maybe your FTP server's documentation has some information
> on how to execute extension commands?
>
> In any case, see the documentation for "SITE" in section
> 4.1.3 of the above referenced RFC.
>
> > or $ftp->quot( "quote authenticate", "blargh")
>
> Nope.
>
> > or $ftp->quot( "authenticate blargh") or ...
>
> Nope.
>
> >
> > I use the newsgroup as a last resort for help, not as a first
> > step in getting an answer.
>
> Admittedly, the documentation for the libnet family is
> a little thin, but the RFCs are there, and there is
> always the source code (FTP.pm and Cmd.pm, its base class).
>
> Good luck, and please followup when you figure it out.
>
> -Gerard
> http://www.geocities.com/gerardlanois/perl/



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

Date: 13 Aug 2001 17:41:04 +0100
From: nobull@mail.com
Subject: Re: help with a global variable in CGI
Message-Id: <u9g0av3obj.fsf@wcl-l.bham.ac.uk>

"Ryan Gralinski" <no-reply@bong.net> writes in jeopardy style:

> I am not using the CGI module

Jeopardist and masochist?

> do you know the format of what i need to insert into the header to assign a
> cookie

Exactly the same as you would need if you wrote the CGI script in any
other language.

This is comp.lang.perl* - please ask only questions that in some way
relate to Perl.  The fact that you happened to be programming in Perl
at the time you encountered a CGI question does not make the question
on-topic here any more than the fact that you were drinking coffee at
the time would make it on-topic in rec.food.drink.coffee.

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


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

Date: Mon, 13 Aug 2001 16:52:20 +0100
From: Kourosh A Mojar <kmojar@bmjgroup.com>
Subject: installing xml-sablotron... ?
Message-Id: <3B77F7B4.734E3151@bmjgroup.com>

Hi,

im a novice perl user and am having trouble installing a module i
require (details below). 

ive used ppm before but not for manual installations. xml-sablotorn the
module im trying to install is not available on activestate server and i
"set repository" to point to server that does have it
"http://theoryx5.uwinnipeg.ca/ppmpackages/". i now have access to it via
ppm. although im still not able to get successful install. below is
snippet of what im doing. you can see ive managed a successful search
but get error when installing/reading it. uurrrgghhh! 

"
PPM> search XML-Sablotron
Packages available from http://theoryx5.uwinnipeg.ca/ppmpackages/:
XML-Sablotron [0.43] a Perl interface to the Sablotron XSLT processor
PPM> install XML-Sablotron
Install package 'XML-Sablotron?' (y/N): y
Retrieving package 'XML-Sablotron'...
Error installing package 'XML-Sablotron': Read of
http://theoryx5.uwinnipeg.ca/p
pmpackages/ failed
"

one thing might be the build version im using. activeperl (on win95) 6xx
as some repositories don't only work with 5xx if this can be confirmed.

thanking you in advance and for your kind attention,

kourosh


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

Date: 13 Aug 2001 17:17:54 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Line counting in a file
Message-Id: <997721177.17628@itz.pp.sci.fi>

In article <m3r8umcpo5.fsf@mumonkan.sunstarsys.com>, Joe Schaefer wrote:
>WARNING: Usage of \$. should be avoided whenever possible.
>Of the $. lines it appears in my perl5 tree, most of them are completely
>inane:

I would disagree with the opinion express on the first line above, and
claim that the statistics produced by your (admittedly clever) program
are irrelevant in determining this, for a very simple reason: The main
utility of $. is generally in shell one-liners, not in the modules and
full-blown scripts you are counting. 

After all, I would not expect to find a single script with -p or -i on
its #! line under /usr/lib/perl5, yet those options are far from inane
or useless.  They're just mostly used in other places.


>    %2d of them are for pod or man documentation (in poor condition),

You wouldn't want $. to be documented?

>    %2d are for polite localization (typically the file's sole usage of \$.),

Note that doing this has additional effects beyond just localizing the
current line number.

>    %2d are for reassigning \$. to a less obscure variable name.

I'd say that the last one isn't really "inane" at all -- you would not
make that claim about $1 etc., would you?  $. is a moderately volatile
variable, and saving its value for later use is perfectly sensible.


Now, if you had instead stated that using $. outside one-liners should
be avoided, I *might* agree.  Even there, it's still true that using a
builtin line counter is more efficient than rolling your own.

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: Mon, 13 Aug 2001 17:28:28 +0100
From: "Terence Cooling" <webmaster@1360squadron.co.uk>
Subject: NTTP > HTTP Gateway?
Message-Id: <b6Td7.44735$e%3.6379320@news2-win.server.ntlworld.com>

I've been looking for an example of a perl NTTP > HTTP gateway for quite
some time and have yet to turn one up. My old system used a PHP version, but
since my change in servers I can only use ASP or perl - any ideas?

thanks

Tez





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

Date: 13 Aug 2001 16:14:13 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Perl5 memory leak or garbage collection problems?
Message-Id: <997712413.10103@itz.pp.sci.fi>

In article <JXHb7.115528$Cu6.8899914@bin3.nnrp.aus1.giganews.com>, weigand@DONTMESSWITHtexas.net wrote:
>
>   #!/usr/local/bin/perl5
>
>   %T = ();
>   system("vmstat 1 2");
>   $T{"one"}{"two"} = "1" x 200000000;
>   system("vmstat 1 2");
>   %T = ();
>   system("vmstat 1 2");
>   $T{"one"}{"two"} = "1" x 200000000;
>   system("vmstat 1 2");
>   %T = ();
>   system("vmstat 1 2");
>   $T{"one"}{"two"} = "1" x 200000000;
>   system("vmstat 1 2");
>   %T = ();
>   system("vmstat 1 2");
>   $T{"one"}{"two"} = "1" x 200000000;
>   system("vmstat 1 2");
>   %T = ();
>   system("vmstat 1 2");
>   $T{"one"}{"two"} = "1" x 200000000;
>   system("vmstat 1 2");
>
>It's as if the garbage collection algorithm is not being run.

What I'm seeing is that the process size (I'm using "ps -lyp $$" instead
of vmstat) varies roughly like this:

  1 ##
  2 ############
  3 #######
  4 #################
  5 ############
  6 ######################
  7 #################
  8 ###########################
  9 ######################
 10 ################################

This is on an Linux system, but on closer examination your results seem
to fit the pattern as well.  Another observation is that if, instead of
repeating the same code 5 times, I run it in a for(1..5) loop, there is
no "leak" and the graph looks like this:

  1 ##
  2 ############
  3 #######
  4 ############
  5 #######
  6 ############
  7 #######
  8 ############
  9 #######
 10 ############

Now, based on this, and a bit of knowledge about perl internals, I think
I understand what's happening here.  When the string ("1" x 200000000)
is computed, it gets stored in a temporary pad variable.  This variable
is part of the precompiled expression, and won't get freed until the
program (or module, or string eval) exits.  It will, however, be reused
if the expression is evaluated several times in a loop.

This is still arguably a perl bug, but it's a known side-effect of the
current implementation.  One way to work around it is to wrap any code
that needs to initialize huge variables inside a string eval.

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: Mon, 13 Aug 2001 18:17:55 +0100
From: "Nuno" <nll@nospam.com>
Subject: Read numbers
Message-Id: <9l92h7$v73$1@venus.telepac.pt>

Hello, i'm trying to figure out how to read some numbers like for ex:

803001 and 1412322

these are numbers based on point (001 or 322), room (03 or 12) number and
floor (8 or 14).

Is it possible to read for left to right if you know what i mean?

Tanks in advance.

Nuno




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

Date: Mon, 13 Aug 2001 17:40:57 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: Read numbers
Message-Id: <Xns90FC6CA914C06cberrycinenetnet1@207.126.101.92>

"Nuno" <nll@nospam.com> wrote in news:9l92h7$v73$1@venus.telepac.pt:

> Hello, i'm trying to figure out how to read some numbers like
> for ex:
> 
> 803001 and 1412322
> 
> these are numbers based on point (001 or 322), room (03 or 12)
> number and floor (8 or 14).

If you have any control over the numbering format, zero- or space-
padding the floor number would make this trivially easy to do using 
unpack.  If you don't, then a regex is pretty straightforward:

  my ($floor, $room, $point) = $str =~ /^(\d{1,2})(\d{2})(\d{3})$/;

-- 
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake



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

Date: 13 Aug 2001 10:48:13 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Read numbers
Message-Id: <3b7812dd@news.victoria.tc.ca>

Nuno (nll@nospam.com) wrote:
: Hello, i'm trying to figure out how to read some numbers like for ex:

: 803001 and 1412322

: these are numbers based on point (001 or 322), room (03 or 12) number and
: floor (8 or 14).

: Is it possible to read for left to right if you know what i mean?

: Tanks in advance.

: Nuno


Possibly you want to access the parts of the numbers?

(untested)

my ($floor,$room,$point) = $your_number =~ m/(.*)(..)(...)$/;


e.g.
	my ($floor1,$room1,$point1) = $your_number1 =~ m/(.*)(..)(...)$/;
	my ($floor2,$room2,$point2) = $your_number2 =~ m/(.*)(..)(...)$/;

	if ($floor1.$room1 eq $floor2.$room2)
	{ print "two locations in the same room";
	}
	elsif ($floor1 eq $floor2)
	{ print "same floor, but different rooms"
	}
	else
	{ print "not even on the same floor"
	}


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

Date: Mon, 13 Aug 2001 11:18:49 -0400
From: A person <strawSPAM_BEGONEman@plexi.com>
Subject: Re: regex question...
Message-Id: <3B77EFD9.C7BDF25B@plexi.com>

What is the < in:
s#(?<=\[)(\d*)(?=\])#$1-1#ge
for?

Would you recommend the Friedl book from O'Rielly?




Ren Maddox wrote:

> On Fri, 10 Aug 2001, strawSPAM_BEGONEman@plexi.com wrote:
>
> > I'm trying to replace all instances on a line of [number] with
> > [number-1].
>
> [snip]
>
> > My question is, Can I do this in the regex itself without writing
> > the function decr?
>
> Certainly:
>
>   s#\[(\d*)\]#"[".($1-1)."]"#ge
>
> Or, if you're willing to use more advanced regex features, I prefer:
>
>   s#(?<=\[)(\d*)(?=\])#$1-1#ge
>
> (I just like the concept of only replacing the part that changes.)
>
> Another way to get clever is:
>
>   s#\[(\d*)\]#[@{[$1-1]}]#g
>
> --
> Ren Maddox
> ren@tivoli.com



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

Date: 13 Aug 2001 10:43:26 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: regex question...
Message-Id: <m31ymg9d9d.fsf@dhcp9-161.support.tivoli.com>

On Mon, 13 Aug 2001, strawSPAM_BEGONEman@plexi.com wrote:

> What is the < in:
> s#(?<=\[)(\d*)(?=\])#$1-1#ge
> for?

It is part of (?<=...), which is an advanced regex feature documented
in perlre(1).  It is a zero-width look-behind assertion, which means
that it looks backwards in the string and matches the contained
pattern.  This sub-match is not considered a part of the overall
match, which allows the substitution to ignore it.

That pattern, "(<=\[)(\d*)(?=\])", matches zero or more digits, but
only if the character immediately preceding the digits is "]" and the
character immediately succeeding the digits is "]".  But the match is
just the digits.  With the original pattern, "\[(\d*)\]", the same
strings will match, but the match itself will include the brackets.

> Would you recommend the Friedl book from O'Rielly?

I would, though I don't recall if it documents these particular
advanced regex features.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 13 Aug 2001 18:32:24 +0000
From: Richard Chamberlain <richard@sunsetandlabrea.com>
Subject: Re: repeating substituation
Message-Id: <uaUd7.7348$v86.1053156@news6-win.server.ntlworld.com>

Thanks!

Richard


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

Date: Mon, 13 Aug 2001 10:29:26 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Rounding a number
Message-Id: <slrn9nfp26.4t5.tadmc@tadmc26.august.net>

NOSPAM@mail.ru <NOSPAM@mail.ru> wrote:
>On Mon, 13 Aug 2001 08:46:47 -0400, tadmc@augustmail.com (Tad
>McClellan) wrote:
>
>>plop740@mail.ru <plop740@mail.ru> wrote:
>>>
>>>For a financial application, we need to round numbers after 4, 5, 6
>>>etc, decimals.
>>
>>
>>>Any suggestion ?
>>
>>
>>Yes. I suggest checking the Perl FAQs *before* posting to the
>>Perl newsgroup:
>
>Thanks for your GREAT help, indeed !


It appears that this is the 3rd time that I have helped you.

It won't be happening again.


*plonk*


>If anybody looks in Google, after 2 or 3 days, he will find ALL what
>he wants !


Google is irrelevant.

The docs that ship with Perl are relevant.

It is standard netiquette to check the FAQs before posting in
nearly all Usenet newsgroups.

Is your time more valuable than everyone else's, so you are exempt?


>So what's the use of this NG ? 


To answer questions that are not already answered in the standard 
Perl docs.

Or even to discuss how a FAQ answer could be improved.


>I asked another question  <pj56ntgu7kn27gvorbgudpuk6u8l31m8vq@4ax.com>
>Of course I could find the reply myself, BUT posting it here brought
>really a lot of interesting solutions, that will probably be usefull
>to somebody else !


That was not a Frequently Asked Question.

There is a FAQ for finding the intersection, but you didn't really
need that much, you just wanted to know the size of the intersection,
which allows for an answer different than in the FAQ.

The question of _this_ thread however, is exactly the same problem
as answered in the FAQ.


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


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

Date: Mon, 13 Aug 2001 10:36:36 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Saving Parse::RecDescent Errors for Later Processing
Message-Id: <slrn9nfpfk.4t5.tadmc@tadmc26.august.net>

Bob Dilworth <bdilworth@mco.edu> wrote:

>Having recently discovered Parse::RecDescent and its high coolness
>quotient I'm quickly finding uses for it in my Perl scripts.  One
>thing I've discovered, however, is that there doesn't seem to be any
>way to collect the parser-generated errors and use them later on in my
>script (i.e., no PRD $error variable or the like).
>
>I looked thorugh past clpm threads for possible solutions and found
>one suggestion by Abigail, to wit:
>
>>I don't think Parse::RecDescent has a hook for that (Damian, something
>>for the todo list?), but you can always install a $SIG {__WARN__}
>>handler and process the generated warnings.
>
>Unfortunately there just isn't enough info in the above suggestion to
>get me started.  


See the entry for %SIG in perlvar.pod, along with the "Signals"
section in perlipc.pod.


>I looked up SIGs in the Camel book (3rd edition) but
>haven't been able to find anything that stands out in term of exactly
>HOW to set up such a signal handler 


Bottom half of page 673 basically repeats what perlvar says.


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


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 1509
***************************************


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