[18893] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1061 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 5 11:05:31 2001

Date: Tue, 5 Jun 2001 08:05:08 -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: <991753508-v10-i1061@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 5 Jun 2001     Volume: 10 Number: 1061

Today's topics:
    Re: Bug in assignment operator <andras@mortgagestats.com>
    Re: Bug in assignment operator (Bernard El-Hagin)
    Re: Bug in assignment operator (Anno Siegel)
    Re: Bug in assignment operator <godzilla@stomp.stomp.tokyo>
    Re: Bug in assignment operator <godzilla@stomp.stomp.tokyo>
    Re: Compile Perl to Exe Prog <newspost@coppit.org>
    Re: Creating a file based on a template with scalar val <gnarinn@hotmail.com>
    Re: date calc modules <sb@engelschall.com>
        DBD::ODBC and recursive functions... <phil@zeddcomm.com>
        Dereferencing undefined value (Garry Williams)
    Re: Dereferencing undefined value (Randal L. Schwartz)
    Re: Dereferencing undefined value (Tad McClellan)
        How can I generate unique number combinations? (Chris Spurgeon)
    Re: How can I generate unique number combinations? (John Joseph Trammell)
        Matching expresions problem <hluan@americasm01.nt.com>
    Re: Newbie guide (Helgi Briem)
        Perl on AS/400 (Patrick Hooper)
        Problem with STAT function <chquek@yahoo.com>
    Re: releasing array memory <mjcarman@home.com>
    Re: todo console script (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 05 Jun 2001 09:17:41 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: Bug in assignment operator
Message-Id: <3B1CDBF5.2798A870@mortgagestats.com>



Anno Siegel wrote:

> "...a list assignment is scalar context returns the number of elements
> produced by the expression on the right hand side of the assignment"
> (perlop).
>
> This leads to the idiomatic
>
>     my $num_elements = () = <something to be evaluated in list context>
>
> to find how many elements the right hand side produces without keeping
> them.
>
> It doesn't work this way when the expression on the right hand side
> is a split operation.  Specifically,
>
> my $num_parts = () = split /,/, 'a,b,c';
>
> sets $num_parts to 1, not 3.  I observed this with v5.6.0 and v5.6.1.
>
> Any comments before I send a bug report?
>
> Anno

v5.00503 produces the same output, in case you care.

By the way, to me

my $num_parts = scalar( split /,/, 'a,b,c');

is a lot more intuitive and it has the advantage of returning the correct
value of 3.




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

Date: Tue, 5 Jun 2001 13:29:00 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Bug in assignment operator
Message-Id: <slrn9hpmv5.com.bernard.el-hagin@gdndev25.lido-tech>

On 5 Jun 2001 11:10:53 GMT, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
wrote:
>"...a list assignment is scalar context returns the number of elements
>produced by the expression on the right hand side of the assignment"
>(perlop).
>
>This leads to the idiomatic
>
>    my $num_elements = () = <something to be evaluated in list context>
>
>to find how many elements the right hand side produces without keeping
>them.
>
>It doesn't work this way when the expression on the right hand side
>is a split operation.  Specifically,
>
>    my $num_parts = () = split /,/, 'a,b,c';
>
>sets $num_parts to 1, not 3.  I observed this with v5.6.0 and v5.6.1.
>
>Any comments before I send a bug report?

Here's something funky:

my $num_parts = () = split /,/, 'a,b,c', 3;

That prints the proper results (you can, in fact, change
the 3 to any number greater than the number of elements in the list).
Definitely looks like a bug.

Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'


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

Date: 5 Jun 2001 14:11:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Bug in assignment operator
Message-Id: <9fipaa$iva$1@mamenchi.zrz.TU-Berlin.DE>

According to Andras Malatinszky  <andras@mortgagestats.com>:
> 
> 
> Anno Siegel wrote:
> 
> > "...a list assignment is scalar context returns the number of elements
> > produced by the expression on the right hand side of the assignment"
> > (perlop).
> >
> > This leads to the idiomatic
> >
> >     my $num_elements = () = <something to be evaluated in list context>
> >
> > to find how many elements the right hand side produces without keeping
> > them.
> >
> > It doesn't work this way when the expression on the right hand side
> > is a split operation.  Specifically,
> >
> > my $num_parts = () = split /,/, 'a,b,c';
> >
> > sets $num_parts to 1, not 3.  I observed this with v5.6.0 and v5.6.1.
> >
> > Any comments before I send a bug report?
> >
> > Anno
> 
> v5.00503 produces the same output, in case you care.

Thanks.

> By the way, to me
> 
> my $num_parts = scalar( split /,/, 'a,b,c');
> 
> is a lot more intuitive and it has the advantage of returning the correct
> value of 3.

Yes, but under warnings it will tell you that "Use of implicit split
to @_ is deprecated".  That is exactly how this came up:  Someone asked
(on IRC) how to avoid the warning, and I suggested using "= () =".  He
said "tnx" and left.  Later I tested...

If you want to avoid an auxiliary array variable

    $num_parts = @{ [split /,/, 'a,b,c']};

works silently, at the cost of some abuse of technology.

Anno


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

Date: Tue, 05 Jun 2001 07:24:47 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Bug in assignment operator
Message-Id: <3B1CEBAF.72728107@stomp.stomp.tokyo>

Anno Siegel wrote:
 
> "...a list assignment is scalar context returns the number of elements
> produced by the expression on the right hand side of the assignment"
> (perlop).

Your quote is incorrect.

 
> This leads to the idiomatic
 
> my $num_elements = () = <something to be evaluated in list context>
 
> to find how many elements the right hand side produces without keeping
> them.

No, it does not. You are using two assignments, not one as indicated
by perlop list assignment definition. Your logic is unacceptable.

 
> It doesn't work this way when the expression on the right hand side
> is a split operation.  Specifically,
 
>     my $num_parts = () = split /,/, 'a,b,c';
 
> sets $num_parts to 1, not 3.  I observed this with v5.6.0 and v5.6.1.
 
> Any comments before I send a bug report?
 

This is not a bug. It is your misunderstanding of the definition
of list assignment and, your bad syntax.


Godzilla!
--

#!perl

$scalar = split /,/, 'a,b,c';

print "Return: $scalar";

exit;

PRINTED RESULTS:
________________

Return: 3


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

Date: Tue, 05 Jun 2001 07:29:16 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Bug in assignment operator
Message-Id: <3B1CECBC.DD158EDD@stomp.stomp.tokyo>

Bernard El-Hagin wrote:
 
>  Anno Siegel  wrote:

(snipped incorrect perlop quote and incorrect logic)

> > my $num_parts = () = split /,/, 'a,b,c';

> > sets $num_parts to 1, not 3.  I observed this with v5.6.0 and v5.6.1.

> > Any comments before I send a bug report?
 
> Here's something funky:
 
> my $num_parts = () = split /,/, 'a,b,c', 3;
 
> That prints the proper results (you can, in fact, change
> the 3 to any number greater than the number of elements in the list).
> Definitely looks like a bug.


This is expected behavior using the limit argument for split.


Godzilla!
--

#!perl

$scalar = () = split /,/, 'a,b,c', 1;

print "Return: $scalar\n\n";

$scalar = () = split /,/, 'a,b,c', 2;

print "Return: $scalar\n\n";

$scalar = () = split /,/, 'a,b,c', 3;

print "Return: $scalar\n\n";

$scalar = () = split /,/, 'a,b,c', 4;

print "Return: $scalar\n\n";

$scalar = () = split /,/, 'a,b,c', 5;

print "Return: $scalar";

exit;


PRINTED RESULTS:
________________

Return: 1

Return: 2

Return: 3

Return: 3

Return: 3


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

Date: Tue, 5 Jun 2001 10:20:37 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Compile Perl to Exe Prog
Message-Id: <Pine.SUN.4.33.0106051019510.26320-100000@mamba.cs.Virginia.EDU>

On Tue, 5 Jun 2001, keng wrote:

> anyone knows where i can get a FREE compiler that compiles *.pl to *.exe.

perlcc comes with Perl. However, you may run into some problems using
it. (At least I did about a year ago. I understand there's been a lot
of hard work on it since then.)

David



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

Date: Tue, 5 Jun 2001 12:38:26 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Creating a file based on a template with scalar value
Message-Id: <991744706.223756265360862.gnarinn@hotmail.com>

In article <90B0AAEB3gunzelT333@203.50.2.80>,
Michael <usenet.spam@gunzel.net> wrote:
>Hi all,
>
>Hope this isn't covered in the FAQ, since I was unable to find it.. But I 
>am having a problem where my script needs to send an email with a username 
>in it, based on a text file, i.e. when creating a new user.
>

another good resource is previous postings on this newsgroups.
try:
http://groups.google.com/groups?q=template&group=comp.lang.perl.misc

gnari







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

Date: Tue, 5 Jun 2001 15:28:10 +0200
From: Steffen Beyer <sb@engelschall.com>
Subject: Re: date calc modules
Message-Id: <apmif9.u77.ln@imperia.net>

Rob Parker <chickenmilkbomb@hotmail.com> wrote:

> I am looking for a module that will allow me to calulate dates in the
> future. I need to take the current date (or any arbitrary date) and
> calculate the settlement date for a trade 3 *business* days in the
> future. 
> 
> For example a trade placed on 5/31/2001 will settle after  3 business
> days -  6/4/2001 (skipping the weekend). I have a list of holidays, so
> that is not a problem.

In Date::Calc version 5.0, this is very easy:

#!perl -w
use strict;
no strict "vars";
use Date::Calendar;
use Date::Calc::Object qw(:all);
use Date::Calendar::Profiles qw($Profiles);
Date::Calc->date_format(3);
$cal = Date::Calendar->new( $Profiles->{'US-MI'} ); # or wherever you're located
$trade = Date::Calc->new(2001,5,31);
$days = 3;
($date) = $cal->add_delta_workdays($trade,$days);
print "$trade plus $days business days gives $date.\n";

This prints:

Thursday, May 31st 2001 plus 3 business days gives Tuesday, June 5th 2001.

Instead of a predefined profile, you can use your own profile of holidays
of course!

The module also supports several languages.

You can download it all from the URL
    http://www.engelschall.com/u/sb/download/pkg/Date-Calc-5.0.tar.gz

Good luck!
-- 
    Steffen Beyer <sb@engelschall.com>
    (This message may not be replyable. Use address on line above instead!)
    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: Tue, 5 Jun 2001 11:54:51 -0230
From: "Phil Glanville" <phil@zeddcomm.com>
Subject: DBD::ODBC and recursive functions...
Message-Id: <9fiq0r$3om$1@horsefly.nf.net>

I'm developing a hierarchical navigation for a web page that has to pull
data out of a MS SQL Server 7.0 database over ODBC 3.7.

On my Win2K box I'm running
ActivePerl 5.6.1
DBI 1.14
DBD::ODBC 1.12

I'm using a recursive function to pull out sections and subsections from the
database, the guts of which look basically like this:

sub getSection
{
 # get the parent to use
 my $parentID= shift;

 my ($db_ID, $db_Title, $sth);

 # loop through the database getting child sections of this parent
 $sth= $dbh->prepare($dbms{getSection_sectionID});
 $sth->execute($parentID);
 while(($db_ID, $db_Title)= $sth->fetchrow)
 {
  # print this section title
  print qq{<p>$db_Title</p>};

  # get children of this section
  &getSection($db_ID);
 }
 $sth->finish;
}

&getSection(0);

(The %dbms hash lives in a separate module and defines dbms-specific SQL
depending on whether the script's running under MySQL or SQL Server.  But
that's another story!)

When I run this on my W2K / SQL Server machine, I get the error

DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver]Connection
is busy with results for another hstmt (SQL-S1000)

Well of *course* the connection is still busy with results - that's because
it's a recursive function!

I've trawled deja for solutions but most people who've had this problem
before have a finite number of connections, so they can add in as many
"dbh"s as they need before they use them.  Because I don't know how many
levels of hierarchy the website navigation will have, I can't do that.

Does anyone have any solutions?

The Linux / MySQL version of this works perfectly (mais oui).

Thanks in advance

Phil





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

Date: Tue, 05 Jun 2001 13:05:48 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Dereferencing undefined value
Message-Id: <slrn9hpm9c.3fl.garry@zfw.zvolve.net>

I ran across some behavior that puzzled me.  

Consider:

  $ perl -Mstrict -wle 'my $x; for (@$x) { print 1 }'
  $

There's no complaint.  In other words, dereferencing an undefined
value as an array reference (apparently) yields an empty list.

But wait.  Look at this:

  $ perl -Mstrict -wle 'my $x; if (@$x) { print 1 }'
  Can't use an undefined value as an ARRAY reference at -e line 1.
  $

There seems to be a special case for an undefined reference appearing
in a for loop.  

I couldn't find this documented.  

-- 
Garry Williams


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

Date: 05 Jun 2001 07:29:55 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Dereferencing undefined value
Message-Id: <m1y9r7gfto.fsf@halfdome.holdit.com>

>>>>> "Garry" == Garry Williams <garry@ifr.zvolve.net> writes:

Garry>   $ perl -Mstrict -wle 'my $x; for (@$x) { print 1 }'
Garry>   $

Garry> There's no complaint.  In other words, dereferencing an undefined
Garry> value as an array reference (apparently) yields an empty list.

foreach provides an lvalue context, so $x gets autovivified.

Garry> But wait.  Look at this:

Garry>   $ perl -Mstrict -wle 'my $x; if (@$x) { print 1 }'
Garry>   Can't use an undefined value as an ARRAY reference at -e line 1.
Garry>   $

if provides an rvalue context, so $x must already be good.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Tue, 5 Jun 2001 10:02:45 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Dereferencing undefined value
Message-Id: <slrn9hppk5.2jh.tadmc@tadmc26.august.net>

Garry Williams <garry@ifr.zvolve.net> wrote:

>Subject: Dereferencing undefined value


At this point, Perlified brains are thinking "autovivification".


>I ran across some behavior that puzzled me.  
>
>Consider:
>
>  $ perl -Mstrict -wle 'my $x; for (@$x) { print 1 }'
>  $
>
>There's no complaint.  In other words, dereferencing an undefined
>value as an array reference (apparently) yields an empty list.


foreach provides an "lvalue context" (due to its aliasing, I suppose),
so autoviv occurs.

perl _creates_ (autovivifies) an (empty) anonymous array (not a list)
and makes $x a reference to it.


>But wait.  Look at this:
>
>  $ perl -Mstrict -wle 'my $x; if (@$x) { print 1 }'
>  Can't use an undefined value as an ARRAY reference at -e line 1.
>  $
>
>There seems to be a special case for an undefined reference appearing
>in a for loop.  


No, the special case is: dereferencing undef in a lvalue context.

foreach loops appear to be one way to get an lvalue context.

Looks like if() does not provide lvalue context?


>I couldn't find this documented.  


autoviv gets not enough coverage in the docs, but at least you
know the search term to use now.


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


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

Date: 5 Jun 2001 07:40:29 -0700
From: cspurgeon@electronicink.com (Chris Spurgeon)
Subject: How can I generate unique number combinations?
Message-Id: <5643c417.0106050640.604f34ce@posting.google.com>

Given a series of digits, I want to generate all of the different ways
they can be arranged.  So, for example, for the numbers 1, 2, 3, 4 and
5 I would generate output like this...

   12345
   12354
   12435
   
   ...snip...

   54231
   54312
   54321

I wrote the following script, which uses nested for loops and then a
big ugly if statement in the inner loop to allow only combinations
where no numbers repeat.  While it works, it just strikes me as very
inelegant and inefficient.  And it will only get worse as the number
of digits increases.  My question is, is there a prettier way to do
this?  Here's the code....

#!/usr/bin/perl

for ($a = 1; $a <= 5; $a++) {
    for ($b = 1; $b <= 5; $b++) {
	for ($c = 1; $c <= 5; $c++) {
	    for ($d = 1; $d <= 5; $d++) {
		for ($e = 1; $e <= 5; $e++) {
		    if (($a == $b) || ($a == $c) || ($a == $d) 
                     || ($a == $e) || ($b == $c) || ($b == $d)
                     || ($b == $e) || ($c == $d) || ($c == $e)
                     || ($d == $e)) {
			next;
		    }
		    print $a, $b, $c, $d, $e, "\n";
		}
	    }
	}
    }
}



Thanks in advance...

Chris Spurgeon
cspurgeon@electronicink.com


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

Date: Tue, 05 Jun 2001 15:01:55 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: How can I generate unique number combinations?
Message-Id: <slrn9hpqia.pcu.trammell@bayazid.hypersloth.net>

On 5 Jun 2001 07:40:29 -0700, Chris Spurgeon wrote:
> Given a series of digits, I want to generate all of the different ways
> they can be arranged.
[snip]
Book of Armaments, chapter 4, verse nineteen:

  http://safari1.oreilly.com/table.asp?bookname=cookbook&snode=87

-- 
To think intelligently about copyrights, patents or trademarks, you must
think about them separately.  The first step is declining to lump them
together as "intellectual property".                  - Richard Stallman


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

Date: Tue, 05 Jun 2001 10:26:34 -0400
From: "Luan, Hao [SKY:QE21:EXCH]" <hluan@americasm01.nt.com>
Subject: Matching expresions problem
Message-Id: <3B1CEC1A.E60073B5@americasm01.nt.com>

Hi here,

I have some problems to understand the behavior of the matching
result. Here is the code
=========================
#!/usr/bin/perl -w
open (IN_FILE, $ARGV[0]) or die "Can't open the input file !\n";
open (LOG_FILE, "> $ARGV[1]") or die "Can't open the output file !\n";
while (defined ($line = <IN_FILE>)) {
        if (($line =~ /force/) && ( $line !~ /^\#/)){
#                            <-----------1
-<---2----->----><-3-><---4------>
        ($new_line = $line ) =~
s/(force.*-(pins|nets)\s+"?)(\s*)([^\$|\[]\S*)/$1TOP\.$4/;
        $final_line = $new_line;
        print LOG_FILE 
"===========================================================================\n";
        print LOG_FILE  $line;
        print LOG_FILE  "                                   
|                                      \n";
        print LOG_FILE  "                                   
V                                      \n";
        print LOG_FILE  $final_line;
        print LOG_FILE 
"===========================================================================\n";
        print $final_line;
        }
        else
        {
        print $line;
        }
}
            
close(IN_FILE);
close(LOG_FILE);
#===============================================eof============================
The purpose of the code is to add in extra string the signal name in 
force -nets/pins  clause.
The signal name sometimes is plain string, sometimes is plain string
with ""
However, I don't want to add in this extra string if the signal name
start with
$ or [. 
here is my test file
==============================================================================
force -pins "GND"
force -pins vdd
force -pins  vdd
force -phase * -pins  vdd
force -pins             vdd
force -nets "high_fanout"
force -nets [high_fanout]
force -nets $high_fanout]
force -nets "   $high_fanout]
force -nets "   [high_fanout]
force -nets "   high_fanout]"
force -nets low_fanout
=================eof==========================================================
Now is the result
====
process_force.pl test.set log.set
force -pins "TOP.GND"
force -pins TOP.vdd
force -pins  TOP.vdd
force -phase * -pins  TOP.vdd
force -pins             TOP.vdd
force -nets "TOP.high_fanout"
force -nets [high_fanout]
force -nets $high_fanout]
force -nets "TOP. $high_fanout] <-------A
force -nets "TOP. [high_fanout] <-------B
force -nets "TOP.high_fanout]"
force -nets TOP.low_fanout
===========================================
everything is fine expect A, B lines should not be changed.

Could somebody tell me why.

Thanks,

-- 
Hao Luan
==============================================
The message above only represents the sender's
own ideas/probelms, not from the company he/she
is working with.
==============================================


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

Date: Tue, 05 Jun 2001 14:39:01 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: Newbie guide
Message-Id: <3b1ced3f.539432423@news.isholf.is>

On Tue, 5 Jun 2001 08:35:42 -0400, "Kevin Kirwan"
<kkirwan@emory.edu> wrote:

>All,
>I'm just starting out learning PERL.  Anyone have any suggestions as to
>"how-to" guides, or web-tutorials that would help an old ksh script hack
>learn PERL?

1 - Don't use Newbie in the subject header.  It annoys
    the regulars and conveys no useful information.

2 - The language is Perl.  The compiler is perl.  There
     is no such thing as PERL.

3 - The first and foremost how-to guide is the perldoc
     tool that comes with every perl installation.  Learn
     it and learn to love it.  perldoc is a command line
     program that turns the imbedded documentation in
    all Perl code into readable text. To start with:
    perldoc perldoc
    perldoc perlfaq
    perldoc perlfunc
    perldoc perlsyn

4 - On the web, the following are immensely useful:
    www.perl.com/pub
    www.perldoc.com
    search.cpan.org
    www.activestate.com

5 - Universally recommended books are:
     Learning Perl, 3rd ed, from www.oreilly.com
     Programming Perl 3rd ed, same publisher
     The Perl Cookbook, same publisher

6 - Have fun and good luck

Regards,
Helgi Briem


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

Date: 5 Jun 2001 06:59:22 -0700
From: phooper@nebs.com (Patrick Hooper)
Subject: Perl on AS/400
Message-Id: <afee0876.0106050559.41bed970@posting.google.com>

There appears to be a port of Perl to AS/400. I know nothing about as/400 but
have been asked to investigate Perl on this platform.  Can anyone tell me how
reliable this port is?  Any caveats?

Any insite is appreciated.

Patrick Hooper


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

Date: Tue, 05 Jun 2001 22:33:49 +0800
From: chquek <chquek@yahoo.com>
Subject: Problem with STAT function
Message-Id: <3B1CEDCD.2C9507E2@yahoo.com>

Hi :

I am trying to get the size of files in a directory.  I used the stat
function, and the 7th element is suppose to contain the size.

However, ocassionally, the stat function fails, returning a NULL list.
I noticed that this usually happens when the file exceeds 2Gb.  Ls -l ,
and 'more|less' is able to list the file and view it.

It leads me to think that stat may be having a 32bit problem.  I am
running on AIX 64 bit.  I wonder if there is a 64bit version of stat.  I
have search CPAN and could not find anything.

Any idea or pointers ?

TIA.



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

Date: Tue, 05 Jun 2001 08:53:44 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: releasing array memory
Message-Id: <3B1CE468.5CD26BDC@home.com>

Stefan Weiss wrote:
> 
> Michael Carman suggested:
> Don't make anything global that doesn't have to be. Use my()
> prodigously to localize variables to the smallest possible scope.
> Memory freed by variables that have gone out of scope can be 
> reused elsewhere, preventing the need for additional allocations.
> > ------------------------------------------------------------------
> 
> Ilya Zakharevich wrote:
> This ignores the fact that memory used by locals *is* reused, but
> one used by lexicals *is not*.
> ------------------------------------------------------------------
>
> Michael Carman wrote:
> Whoa there! That's news to me.
> 
> So if I do this:
> 
> SOME_BLOCK: {
>     my @array = (0 .. 1000);
>     # ...
> }
> 
> and no references to @array exist outside the block, the memory
> allocated to it still won't be freed up for use elsewhere in the
> program after I leave the block?
> ------------------------------------------------------------------
 
> I could understand that lexicals that are not declared/assigned 
> inside a block will not return their memory to the process if 
> they are reassigned or undef()ined.

It didn't say that at all -- what it did say is that lexicals won't
return memory when they go out of scope.

> But I did not find any definitive answer to your question
> with the SOME_BLOCK example

It wasn't really a question, more of an incredulous statement. :) I had
been led to believe that my() would release memory, and this came as
something of a revelation to me.

> these variables are localized, and the will go out of scope at
> some time.

You're getting lost in the semantics here. In Perl-speak, "local" means
a localized copy of a global variable, via the local() keyword. This is
not the same as a lexical variable declared using my(). When Ilya said
that local variables release their memory, he was talking about
localized globals.

If the choice of keywords seems confusing to you, that's understandable,
but it's for historical reasons -- local() was around before my(), and
used to be used in all the places we use my() now. The local() keyword
is in fact rarely needed anymore.

> Are you really sure that the memory used by variables
> like @array will be lost beyond recovery?

No, it isn't lost. As Dan said, it will be reused if you ever enter the
block again. Once you get the misinformation about my() returning memory
out of your head, it makes perfect sense.
 
> What would be a usable workaround for this behavior? Do you have to
> explicitly use local() to force the release of used memory?

No, don't do that. Only use local() when you need to temporarily
redefine a global. You can undef() large vars if you want to.

In general, it's not very Perlish to worry about saving memory. It's a
lot more trouble than it's worth. Just try to avoid wasting it. 
With that in mind, when I look back at the original post I would
question whether the OP *needs* to have the whole file in memory at once
before I would worry about releasing the memory the used to hold it.

-mjc


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

Date: Tue, 5 Jun 2001 09:17:26 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: todo console script
Message-Id: <slrn9hpmv5.2ee.tadmc@tadmc26.august.net>

jmd2121@email.com <jmd2121@email.com> wrote:
>I wrote a script to manage a 'todo' list
>
>it is here:
>http://bowser.stanford.edu/cgi-bin/scripts#todo
>
>I'm pretty new to perl, and I was wondering if people could give me
>comments on it.  


You should not ask for humans to comment until after you have
asked the machine for comments. It is inefficient (and a bit
demeaning) to ask people to do a machine's job.

Enable warnings and strictures *before* requesting a code review!

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


Please ask us again after you get those worked in.

   perldoc strict

to find out what "use strict" does.


>Maybe other people would find it useful too.
>
>Some areas I'd like to have comments on:
>
>-  Coding style...  any criticism would be helpful.  I'm sure there
>are things I could do better / more eloquently.


You don't need to initialize the arrays to empty. They are guaranteed
to be empty anyway.

   my @list;

-----

You can eliminate some of the punctuation, which may make your
code easier to maintain:

   $storefile = $ARGV[0] if $ARGV[0];  #if ($ARGV[0]){$storefile = $ARGV[0]};

   if ( $key eq "a" or $key eq "A"){   #if (($key eq "a") ||($key eq "A")){

-----

To call a subroutine, you need one of the below. You have zero of them :-)

   1) use parenthesis after sub name:   PrintList();

   2) use ampersand before sub name:   &PrintList;

   3) subroutine definition seen in code before subroutine call

   4) forward declaration of sub before sub call

-----

You might want to recast the multiple "if $key eq ..."s to something
like the answer given for this Perl FAQ:

   "How do I create a switch or case statement?"

-----

Don't call backticks in a void context:

   `$cal_command`;   # bad

   !system $cal_command or die "problem running '$cal_command'  $!";

-----

Choice of data structure can make a big difference in how easy/hard
the implementation will be. You seem to be maintaining 3 separate
yet parallel arrays (@list, @add_time, @due_time). If they are
related (parallel), then they should be grouped together in a
multilevel data structure (LoL in this case: perldoc perllol).

-----

You don't need to concern yourself with "numberness", perl will
convert a string to a number when you use a string as a number:

   # not needed (unless you want to truncate a float):  $number = int($key);

-----

use Perl's localtime() and sprintf() instead of the *nix 'date' command
for portability.

-----

write "!~" instead of "! ... =~" for "negative" pattern matches.

   $txt !~ /now|tom|today/;   # !($txt =~ /now|tom|today/)

probably should have word boundaries in the match too:

   $txt !~ /\b(now|tom|today)\b/;

or other anchors:

   $txt !~ /^(now|tom|today)$/;

-----

    if ($_[0]) {$outfile = $_[0];}
    else {$outfile = $storefile;}

can be replaced with:

   $outfile = $_[0] or $storefile;

-----

diag messages should include the $! special variable:

    $fileh->open("> $outfile") || die "unable to open file: $outfile  $!";

-----

You can eliminate the unportable use of "cat" in ReadData():

   open STOREFILE ...
   my @lines = <STOREFILE>;  # slurp the entire file, one line per element
   close STOREFILE;

you could at least do away with the unnecessary $data temp var:

   my @lines = `cat $storefile`;  # backticks in list context
   chomp @lines;

-----

Booleans are *always* scalars, no need to force it with scalar().

-----



>-  I tried to write a signal handler, but it only appears to catch the
>first SIGINT (which I expected).  I tried to reset the handler after
>the call, (or even in the main loop) but I wasn't ableto get the
>handler to continue work.  Am I missing something?


You call exit() inside of your handler. Your program itself is gone
for 2nd and subsequent signals   :-)


>-  It currently will not work on Windows platforms -- some of the
>changes are obvious, but others, (like calling system (stty)) are not.
>Any suggestions for making it portable?


   perldoc -q keyboard


>I'd appreciate any (constructive) comments people have!


HTH!


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


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