[9641] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3235 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 23 15:07:22 1998

Date: Thu, 23 Jul 98 12:00:34 -0700
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, 23 Jul 1998     Volume: 8 Number: 3235

Today's topics:
    Re: 'eval' and 'require' (M.J.T. Guy)
    Re: @INC not working from within prog? (Craig Berry)
        [Perl for WIn32] -e Command line script? <marms@sandia.gov>
    Re: Coding Quiz (was Re: efficiency: print<<"xxx" vs. p <nguyend7@egr.msu.edu>
    Re: comparing files in perl (Mark-Jason Dominus)
        Control Characters (e.g. ^J, ^M), and the newline chara (Joe Wickremasinghe)
    Re: Control Characters (e.g. ^J, ^M), and the newline c (Matthew Bafford)
    Re: Control Characters (e.g. ^J, ^M), and the newline c (Craig Berry)
    Re: delete while iterating over array (M.J.T. Guy)
    Re: delete while iterating over array (Larry Rosler)
    Re: delete while iterating over array <maraism@sterlingdi.com>
    Re: exec return ? ((null))
    Re: Expanding $1 in a variable substitution <dannyv@tibco.com>
    Re: Expanding $1 in a variable substitution (Ilya Zakharevich)
    Re: extracting price from string (Andre L.)
    Re: extracting price from string <simonf@conduit.co.uk>
    Re: extracting price from string <simonf@conduit.co.uk>
    Re: field <simonf@conduit.co.uk>
    Re: File File Creation date <tonylabb@infonline.net>
    Re: File File Creation date (Larry Rosler)
    Re: Hash tree problems. <mkbowler@nortel.com>
    Re: Help!  Memory leak in code!  (I think) <blok@physics.ubc.ca>
        HELP! Hash of refs to objects <rhakim@cyberus.ca>
    Re: How to know the number of hash items without runnin <mkbowler@nortel.com>
        htpasswd <webmaster@ent-media.org>
    Re: Installation of Perl V5.004_04 on IBM AIX V4.2 (Woodward S. Aichner)
    Re: installing perl in a different directory, @INC <Eric.Zylberstejn@wanadoo.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 23 Jul 1998 16:57:10 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: 'eval' and 'require'
Message-Id: <6p7q16$rpb$1@pegasus.csx.cam.ac.uk>

Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Aaron Harsh
><ajh@rtk.com>],
>who wrote in article <6p5ith$5qn$1@brokaw.wa.com>:
>> You could check the return value from eval, which will be true iff the
>> require'd file exists and ran succesfully:
>> 
>>   unless ( eval 'require "foo"' )
>
>I got bitten by this several times.  Nowadays I always add "; 1" at
>the end of eval string when testing for a successful compilation:
>
>   unless ( eval 'require "foo"; 1' )

How exactly did you get bitten?

I note that  perldoc -f require   doesn't actually define the value
of a require, but simple experiment suggests it is in fact the value
of the last expression.    So the test ought to work OK.

Though I have always regarded the Right Way to be to test $@.
(It's even documented.)


Mike Guy


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

Date: 23 Jul 1998 18:01:50 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: @INC not working from within prog?
Message-Id: <6p7tqe$d1l$1@marina.cinenet.net>

Tom Robert (trobert@wpine.com) wrote:
: Thanks for the advice.  What you say makes sense.
: However when I insert the line (before other 'use' calls)
: 
: use lib '/Perl/lib';
: 
: It now generates a compile time error of:
: 
: Can't locate lib.pm in @INC at myprog.pl line 2

Oops.  What version of Perl are you running?  Do 'perl -v' to see.  Either
you have a backlevel or a misinstalled Perl.  One way to tell which it is
is to go to the Perl lib dir (if you know where that is, or should be) and
check manually for the existence of lib.pm.  If it's there, your problem
is a misinstallation.

: The documentation I mention in my initial post came
: from the book "teach yourself PERL in 21 days".
: It even states to use "unshift" so that it's added to the
: front of the search path as opposed to the end.

I've heard uncomplimentary things about that book.  This just provides one
more piece of evidence that it's not a good Perl learning tool.  Note that
the unshift method will work fine for 'require' but not for 'use' (unless
you put the unshift in a BEGIN block, but then why not just do 'use
lib'?). 

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Thu, 23 Jul 1998 12:33:02 -0600
From: Mike Arms <marms@sandia.gov>
Subject: [Perl for WIn32] -e Command line script?
Message-Id: <35B781DE.428A@sandia.gov>

I am an experienced perl user under Unix, and have just started
with perl for Win32. I cannot figure out how to pass a simple
perl script via the command line in a Win95 MSDOS window. Should
be something like:

   perl -e 'print "Hello world\n"'

It complains about the quote delimiters. I have tried backslashing
the quotes, no luck. What would I need to type to get MSDOS to
correctly pass my command line perl script. (I do this so often
under Unix that it has become second nature to me.) Yes, I did 
search both of the perl for Win32 FAQ's.

Thanks for any feedback.

-- 
Mike Arms
marms@sandia.gov
: 1.  What is the possibility of this being added in the future?
In the near future, the probability is close to zero.  In the distant
future, I'll be dead, and posterity can do whatever they like...  :-)
--lwall


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

Date: 23 Jul 1998 17:20:40 GMT
From: Dan Nguyen <nguyend7@egr.msu.edu>
Subject: Re: Coding Quiz (was Re: efficiency: print<<"xxx" vs. print)
Message-Id: <6p7rd8$btn$1@msunews.cl.msu.edu>

In comp.lang.perl.misc Uri Guttman <uri@sysarch.com> wrote:

: 1. Who is main the PERSON you should think about while you are writing code?

My Girlfriend  OR the person who will mantain the code (me). 

: 2. Other than comments, what is the most important HUMAN aspect of code?

There's enough whitespace so the code is readable and understandable

: 3. What is the main PURPOSE of comments?

So that 6 months from now, when you need to update (fix) the code, you
understand (remember) what you were thinking when you wrote a chunk of
code that seems to be gibberish yet works.

: Bonus: What is the OPPOSITE of spaghetti code?

Code that 1.) works all the time (at least 50%)
	  2.) is readable
	  3.) is maintainable

-- 
Dan Nguyen                         |
nguyend7@cse.msu.edu               |   I am Grey.
http://www.cps.msu.edu/~nguyend7   |   



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

Date: 23 Jul 1998 14:17:21 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: comparing files in perl
Message-Id: <6p7unh$nnu$1@monet.op.net>


In article <35B7642A.2619@min.net>, John Porter  <jdporter@min.net> wrote:
>Maybe my intuition is way off; but I wonder whether memoize would
>actually work in this case.  You need to pass two arrays to LCS, and
>that means passing two (or at least one) array-ref.  And even when
>the contents of the two arrays are identical to a previous call, the
>actual arguments to the subroutine are most likely going to be
>different.
>Or does memoize have a way of handling this?

Well, there's two answers to that.  The first answer is that I
imagined that the real work of the LCS subroutine would be done by a
recursive helper function whose arguments were indices into the two
sequences, rather than the two sequences themselves, and the indices
would be two integers.  But the other answer is that yes, memoize has
a way of handling this; you can use the NORMALIZER feature to solve
this problem.

You might want to look at the URL I referred to in my original
article; it's full of clever ideas.


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

Date: Thu, 23 Jul 1998 17:27:54 GMT
From: exet0068@sable.ox.ac.uk (Joe Wickremasinghe)
Subject: Control Characters (e.g. ^J, ^M), and the newline character
Message-Id: <35b90e1d.4153488@news.clara.net>


I'm writing a simple filter in perl to convert dos text to unix
(ocassionally I download text philes :) which, when viewed in notepad
don't have any line feeds. I want my fillter to replace the ^M with
^J, or whatever to give the correct linefeed. Two problems. How do you
encode these characters in perl (e.g. how would I print a ^J out to a
file), and what are the dos / ascii / unix conventions for newlines? I
know one is ^J^M and the other is ^M alone, but I don't know which is
which.

Thanks for all the help.

	Joseph Wickremasinghe


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

Date: Thu, 23 Jul 1998 18:24:42 GMT
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Control Characters (e.g. ^J, ^M), and the newline character
Message-Id: <MPG.102142f37b376687989689@news.scescape.net>

In article <35b90e1d.4153488@news.clara.net> on Thu, 23 Jul 1998 
17:27:54 GMT, Joe Wickremasinghe (a) felt the following 
information to be of use:
> 
> I'm writing a simple filter in perl to convert dos text to unix
> (ocassionally I download text philes :) which, when viewed in notepad
> don't have any line feeds. I want my fillter to replace the ^M with
> ^J, or whatever to give the correct linefeed. Two problems. How do you
> encode these characters in perl (e.g. how would I print a ^J out to a
> file), and what are the dos / ascii / unix conventions for newlines? I
> know one is ^J^M and the other is ^M alone, but I don't know which is
> which.
> 

$DOS eq '\r\n'
$UNIX eq '\n'

perl -i -pe 'tr/\r//d' file1 file2 file3 etc

or

perl -i -pe 's/\r//g' file1 file2 file3 etc

Hope this helps!
--Matthew


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

Date: 23 Jul 1998 18:24:24 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Control Characters (e.g. ^J, ^M), and the newline character
Message-Id: <6p7v4o$d1l$4@marina.cinenet.net>

Joe Wickremasinghe (exet0068@sable.ox.ac.uk) wrote:
: I'm writing a simple filter in perl to convert dos text to unix
: (ocassionally I download text philes :)

If you download through FTP, setting 'ASCII mode' (as opposed to binary)
should do this automagically.

: which, when viewed in notepad
: don't have any line feeds. I want my fillter to replace the ^M with
: ^J, or whatever to give the correct linefeed. Two problems. How do you
: encode these characters in perl (e.g. how would I print a ^J out to a
: file),

There are several ways to represent control chars, but I tend to favor
\c{letter}.  So ctrl-J is \cJ, ctrl-M is \cM, and so forth.

: and what are the dos / ascii / unix conventions for newlines? I
: know one is ^J^M and the other is ^M alone, but I don't know which is
: which.

DOS used \cM\cJ, Unix uses \cJ.

So, to turn DOS text into Unix text you'd use

  s/\cM\cJ/\cM/g;

while to go from Unix text to DOS text it'd be

  s/\cJ/\cM\cJ/g;

Actually, when going either way, it can be useful to reduce to
newlines-only, then add returns back in if needed.  This guards against
various weird formats you might sometimes see in abused text files, like
\cM\cJ\cJ.  To do this:

  tr/\cM//d;

  s/\cJ/\cM\cJ/g if $to_dos;

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 23 Jul 1998 17:11:42 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: delete while iterating over array
Message-Id: <6p7qse$s0a$1@pegasus.csx.cam.ac.uk>

Larry Rosler <lr@hpl.hp.com> wrote:
> To prevent warnings if there are undefined elements also, use:
>
>@array = grep defined($_) && length, @array;

Curious asymmetry there.   Why not

 @array = grep defined && length, @array;

?


Mike Guy


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

Date: Thu, 23 Jul 1998 10:38:14 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: delete while iterating over array
Message-Id: <MPG.102114e34567194998973c@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy sent to M.J.T. Guy 
<mjtg@cus.cam.ac.uk>.]

In article <6p7qse$s0a$1@pegasus.csx.cam.ac.uk> on 23 Jul 1998 17:11:42 
GMT, M.J.T. Guy <mjtg@cus.cam.ac.uk> says...
> Larry Rosler <lr@hpl.hp.com> wrote:
> > To prevent warnings if there are undefined elements also, use:
> >
> >@array = grep defined($_) && length, @array;
> 
> Curious asymmetry there.   Why not
> 
>  @array = grep defined && length, @array;
> 
> ?

Because neither the Blue Camel (5.003) nor the copy of perlfunc that I 
happened to look at (5.002) says that defined defaults to $_.  But of 
course it does, and even in 5.002 (which I just tested again).

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 23 Jul 1998 13:12:13 -0400
From: Michael Maraist <maraism@sterlingdi.com>
Subject: Re: delete while iterating over array
Message-Id: <35B76EED.14FB7F70@sterlingdi.com>

> : I have an array where some keys are empty ( "" ). How do I do to delete them?
> : I understand that I can't use splice when iterating over the array.
> 
> : Any suggestions?
> 
>    I assume you mean a real array (@array) and not a hash.
> 
>    Your use of "key" is confusing...
> 
>    @array = grep /./s, @array;  # eliminate empty array elements

	The reg ex doesn't work in all cases.  '.' only takes normal chars,non
chars and carrage returns.  If you were to garuntee the reg ex to work,
you'd need to represent the entire character space.  Not really a big
deal.
	However, I ran benchmark, and the reg ex is significantly slower than a
simple comparison.. 

if you are not concerned with zero resultant values, the fastest is:
   @array = grep $_, @array;

The next fastest is surprisingly:
   @array = grep length $_, @array;

I believe that 'length' is an operator, not a function.  So really, all
this does is get the size field out of the $_ scalar, which is much
faster than parsing a regular expression.

I ran the following benchmark ( not cut and paste )

timethese( 1000, { "bare"   => 'grep $_, @array',
	 	   "length" => 'grep length $_, @array',
	 	   "reg"    => 'grep /./s, @array',
		   "zero"   => 'grep $_ ne "", @array' } );

Results:
   bare:  7
 length: 10
    reg: 23
   zero: 11

If you ment deleting entries from a hash, you'd have to do something
more complex, such as:

for ( ( $key, $value ) = each %hash ) {
   delete $hash{ $key } unless length $value;
}


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

Date: 23 Jul 1998 18:02:32 GMT
From: mike@stok.co.uk ((null))
Subject: Re: exec return ?
Message-Id: <6p7tro$5pk@news-central.tiac.net>

In article <35B6EC53.2773@ifi.uio.no>,
Kamran Iranpour  <kamrani@ifi.uio.no> wrote:
>Hei
>
>Does "exec" and "system" return any value, i.e. 0 or 1 ?
>Another question is I like to store the output of the
>exec in a variable. I have the following line in my program:

exec returns false if it fails, if it succeeds then the program expecting
the return value shouldn't be there any more...

>exec("rsh $machine hosttype");
>
>which opens a shell on a remote machine and execute the
>the hosttype command. Lets say the output is sgi, standing
>for silicon graphics. I want to assign this to a text
>variable. How should I do it ?

If it's known that the rsh will work then

  chomp ($type = `rsh $machine hosttype`);

might be the easiest way to do it, but the possibility of failure means
that you may want to consider something more complicated.

Section 8 of the frequently asked questions docs distributed with recent
perls contains the question How can I capture STDERR from an external
command? and an answer to it which may be of use to you.

  perldoc perlfaq8

might work on your system, if not fisit http://www.perl.com and follow the
FAQs link.

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Thu, 23 Jul 1998 11:24:41 -0700
From: Danny van der Rijn <dannyv@tibco.com>
To: Robert Seals <rseals@fore.com>
Subject: Re: Expanding $1 in a variable substitution
Message-Id: <35B77FE9.D95AC641@tibco.com>

Robert Seals wrote:
> 
> 
> In other words, I want to refer to the matched
> text in the replacement string.

i think what you're looking for is
$pat = "abcdefghijklmnop";
$pat =~ s/abc(.*)m/\1\1\1/;
print $pat;

> 
> Help?
> 
> Rob


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

Date: 23 Jul 1998 18:41:24 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Expanding $1 in a variable substitution
Message-Id: <6p804k$nmj$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Tony Curtis 
<Tony.Curtis+usenet@vcpc.univie.ac.at>],
who wrote in article <7xiukod3vs.fsf@fidelio.vcpc.univie.ac.at>:
> Re: Expanding $1 in a variable substitution, Robert
> <rseals@fore.com> said:
> 
> Robert> #!/usr/local/bin/perl -w
> Robert> $m = "abc(.*)m";
> Robert> $r = '$1$1$1';
> Robert> $pat = "abcdefghijklmnop";
> Robert> $pat =~ s/$m/$r/;
> Robert> print "$pat\n";
> 
> eval "\$pat =~ s/...../";
> 
> perldoc -f eval

Do not!  Useless use of eval considered harmful.

If $r is known at compile time, just do

   $pat =~ s/$m/$1$1$1/;

Otherwise you need

   $pat =~ s/$m/"$r"/e;

Hope this helps,
Ilya


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

Date: Thu, 23 Jul 1998 13:11:29 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: extracting price from string
Message-Id: <alecler-2307981311290001@dialup-909.hip.cam.org>

In article <6p7it4$qs8$1@nnrp1.dejanews.com>, dwiesel@my-dejanews.com wrote:

> Hi,
> 
> I have a small problem. I have a string could look either like this
> 
> $string = 'product||500.00||';
> 
> or like this
> 
> $string = 'product|||500.00||';
> 
> I want to extract the price from $string. I have done it like this...
> 
> $string =~ /\|\|(.*?)\|\|/;
> 
> but then $1 eq '|500.00'.
> 
> Can you help me?
> 
> // Daniel


You specified exactly two '|' before the price field. State "one or more
|", and problem solved.

   ($price) = $string =~ /\|+(.*)\|{2}$/;

(Greediness of * not an issue here.)

Another possible solution using split():

   $price = (split /\|/, $string, -1)[-3];

(The reason for the -1 limit is left to the reader to find out. :-)

HTH,
Andre


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

Date: Thu, 23 Jul 1998 16:57:48 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: extracting price from string
Message-Id: <35b75ca1.0@nnrp1.news.uk.psi.net>

Hi,

Try using the following regexp:

$string =~ /[|]+([^|]+[|]+/;

It will match as long as you have at least one '|' either side of the price.

Have Fun

Simon
dwiesel@my-dejanews.com wrote in message
<6p7it4$qs8$1@nnrp1.dejanews.com>...
>Hi,
>
>I have a small problem. I have a string could look either like this
>
>$string = 'product||500.00||';
>
>or like this
>
>$string = 'product|||500.00||';
>
>I want to extract the price from $string. I have done it like this...
>
>$string =~ /\|\|(.*?)\|\|/;
>
>but then $1 eq '|500.00'.
>
>Can you help me?
>
>// Daniel
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




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

Date: Thu, 23 Jul 1998 17:00:47 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: extracting price from string
Message-Id: <35b75d50.0@nnrp1.news.uk.psi.net>

Eeeek missing a ')' it should be:

$string =~ /[|]+([^|]+)[|]+/;

Simon

Simon Fairey wrote in message <35b75ca1.0@nnrp1.news.uk.psi.net>...
>Hi,
>
>Try using the following regexp:
>
>$string =~ /[|]+([^|]+[|]+/;
>
>It will match as long as you have at least one '|' either side of the
price.
>
>Have Fun
>
>Simon
>dwiesel@my-dejanews.com wrote in message
><6p7it4$qs8$1@nnrp1.dejanews.com>...
>>Hi,
>>
>>I have a small problem. I have a string could look either like this
>>
>>$string = 'product||500.00||';
>>
>>or like this
>>
>>$string = 'product|||500.00||';
>>
>>I want to extract the price from $string. I have done it like this...
>>
>>$string =~ /\|\|(.*?)\|\|/;
>>
>>but then $1 eq '|500.00'.
>>
>>Can you help me?
>>
>>// Daniel
>>
>>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>>http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
>
>




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

Date: Thu, 23 Jul 1998 17:42:39 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: field
Message-Id: <35b76722.0@nnrp1.news.uk.psi.net>

The solution is easily found by looking in the documentation and FAQ.

Essentially you want the following
(verbose but easier to read version)

open LIST, "ypcat hosts byaddr|" or die "Can't run ypcat: $!";
while( $line = <LIST> ) {

   # Stick whatever seperates the fields in between the slashes (I used ';')
   @field = split /;/, $line;

   # Remeber array subscripts start at 0 so print whichever you want.
   print "Field 5 - $field[4]\n";
}
close LIST;

Simon

Kamran Iranpour wrote in message <35B5A72F.781B@ifi.uio.no>...
>Hi
>
>I am new to perl and my question may seem elementary but
>please help.
>I am looking for some function in perl that does the same
>thing as awk does, i.e. print only a field of a line. To be
>more specific I need to list all the machines belonging to
>a certain network, which I does with :
>exec('ypcat hosts.byaddr');
>The output consists of several fields, like the ip, the full name...
>I want to extract just the name of the machine without the domain name.
>I would have done that in awk by just doing "print $3", where "3"
>is the field I am looking for. Is there a similiar thing in perl ?
>And why can't I do :
>exec('ypcat hosts.byaddr | awk "{print $3}"');
>This does not work in my perl script, as if it just ignores the
>awk command.
>
>
>Thanks in advance
>
>Kamran




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

Date: Thu, 23 Jul 1998 13:29:46 -0400
From: Tony Labbiento <tonylabb@infonline.net>
Subject: Re: File File Creation date
Message-Id: <35B7730A.584B5FFF@infonline.net>

Have you read your Perl docs? The return value for month is a number
ranging from 0-11. This makes things easy. Consider this:

@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
$month = $months[(stat FILE)[9]];

$month will now = Jul or whatever month it is.

Simon Ross wrote:
> 
> Greetings
> 
> This may have been answered many times before but I can't find a referance
> to it.
> 
> I am using the stat() function to get the file creation date on certain
> files. This works fine however the displayed month is always a month behind
> the real creation date. I am using version 5.003_07 on a WindowsNT machine.
> 
> Can anybody help ???
> 
> Simon Ross
> simon.ross@baesema.co.uk

-- 
			****************************************
			*    Tony Labbiento                    *
			*    Infinity Online, Inc.             *
			****************************************


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

Date: Thu, 23 Jul 1998 11:26:08 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: File File Creation date
Message-Id: <MPG.1021201d1bef6de798973d@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy sent to Tony Labbiento 
<tonylabb@infonline.net>.]

In article <35B7730A.584B5FFF@infonline.net> on Thu, 23 Jul 1998 13:29:46 
-0400, Tony Labbiento <tonylabb@infonline.net> says...
> Have you read your Perl docs? The return value for month is a number
> ranging from 0-11. This makes things easy. Consider this:
> 
> @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
> $month = $months[(stat FILE)[9]];
> 
> $month will now = Jul or whatever month it is.

Afraid not -- it will be undefined.  Test before posting!

(stat FILE)[9] is an integer like 901217863.  You have to hand that to 
(local|gm)time in list context to get the month.

Try

$month = $months[(localtime((stat $0)[9]))[4]];

and then gag me.  (This horror has been tested.)

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 23 Jul 1998 13:26:19 -0400
From: Michael Bowler <mkbowler@nortel.com>
Subject: Re: Hash tree problems.
Message-Id: <35B7723B.9A7EE80D@nortel.com>

Mark-Jason Dominus wrote:
> 
> But I thought that `exists' was not supposed to trigger any sort of
> autovivification; if it does, that is certainly a bug.  I wonder what
> version of Perl Michael is using?

I am using 5.002.  I suppose that this is pretty old.  If this is a bug that
has been fixed in later releases I will push our sys admin to upgrade.

-- 
   Michael Bowler                     Phone:    613-765-3432
   IC Design Tools - 5T11             ESN:          39+53432
   Nortel Semiconductors              Email: mkbowler@nt.com


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

Date: Thu, 23 Jul 1998 10:36:46 -0700
From: Rik Blok <blok@physics.ubc.ca>
To: Stefaan A Eeckels <Stefaan.Eeckels@ecc.lu>
Subject: Re: Help!  Memory leak in code!  (I think)
Message-Id: <35B774AE.B7DCED65@physics.ubc.ca>

Stefaan:

Thanks for the help.  Lots of good information.  The data files are
~500kB each and I loop through 20-40 of them.  No, BuildProb doesn't
crash on the first loop, but just anywhere.  If you're interested I can
send you a small data file you could duplicate and test.  Also, you can
just replace the `ChooseFile` command with an output filename (It just
pops up a Windows Save File dialog.

I do have access to Perl 5.004_04 on Unix so I will try it there.  (Good
idea!)

I'm afraid I don't understand the 'close' warning.  How could closing a
file cause a problem?

Anyways, thanks for your help.  It's given me some good ideas.  Let me
know if you're want some sample data.

Thanks, Rik.

Stefaan A Eeckels wrote:
> 
> [Posted and mailed.]
> 
> In article <35B6B2A8.B631E885@physics.ubc.ca>,
>         Rik Blok <blok@physics.ubc.ca> writes:
> > This is a multi-part message in MIME format.
> Please don't post MIME. It really scrambles the display
> on many news readers, and ensures that the real gurus
> won't even look at your post (so you're stuck with me ;-)
> >
> > I hope somebody can help me.  I'm running the attached code I have
> > written with Perl 5.00402 for Win32 but it keeps locking up my system.
> > Must be a memory leak right?  Anyways, I'm a newbie (been using Perl a
> > couple weeks now) and I am *WAY* over my head with this code.
> Why should it be a memory leak? Are you running this on Win95 or
> WinNT? If you didn't run it on NT, try that and see if it leaks
> memory with the Task Manager (there might be a similar utility on
> Windows95 but I don't use Windows95; there are limits ;-).
> >
> > Could somebody take a quick look at it and let me know if I'm doing
> > anything obviously wrong or dangerous?
> You could try to add '#!/usr/bin/perl -w' to all your source
> files. I know it doesn't work in Windows, but Perl will honour
> the flags, and give you useful information such as:
> 
> :Name "main::filenotfound" used only once: possible typo at BuildProb.pl line 16.
> :Value of <HANDLE> construct can be "0"; test with defined() at ReadData.pl line 65535.
> :sh: C:\My Documents\CBuilder\Projects\ChooseFile\ChooseFile.exe: command not found
> :Couldn't open file for output: No such file or directory at BuildProb.pl line 36.
> :Saving results...
> 
> > The program file is
> > "BuildProb.pl" (I've also attached the included files) and it crashes at
> > arbitrary (and inconsistent) points (like between "flag 2" and "flag 3"
> > in the first loop.
> Does it crash after processing one file, or more files (it's
> unlikely to be a leak unless you process a significant number
> of files). The fact that it crashes on a 'close' seems to
> indicate that your file handle might be suspect (see the warning
> above).
> >
> > Any help would be appreciated.  Sorry for the big code but I can't
> > really break it down any further...
> You really should try to isolate the various routines
> (like reading the SPS file into the array) and test these
> individually for leaks; try to test on a Unix platform using
> the latest stable version (5.004_04) and see if they are OK
> (Linux is quite nice because you can watch both memory and
> file handle leakage through /proc). I've noticed that
> Win32 Perl isn't as stable as Unix Perl, and leaks handles
> when using the Net modules; your problem might be related.
> 
> BTW, I couldn't run your code because I don't have data files
> nor the ChooseFile.exe program you call.
> 
> HTH
> 
> --
> Stefaan
> --
> 
> PGP key available from PGP key servers (http://www.pgp.net/pgpnet/)
> ___________________________________________________________________
> Perfection is reached, not when there is no longer anything to add,
> but when there is no longer anything to take away. -- Saint-Exupery

-- 
Rik Blok  <blok@physics.ubc.ca>
Department of Physics and Astronomy,
University of British Columbia, Canada
http://www.physics.ubc.ca/~blok/


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

Date: Thu, 23 Jul 1998 18:38:55 GMT
From: Richard Hakim <rhakim@cyberus.ca>
Subject: HELP! Hash of refs to objects
Message-Id: <35B783B6.92BB3FA0@cyberus.ca>

Hi -

I'm really hoping someone can help me with this.  I have an object
called Global.pm.  In my script, I create a hash of these objects like
this:

%hash = (
            'GLOBAL' => new Global,
            );

Then, I want to call a function process() which is part of the global
class.  But when I try to do

$hash{GLOBAL}->process(), of course, it bails.  I've also tried
&$hash{GLOBAL}->process, &{ $hash{GLOBAL}->process }() and probably a
few others I can't remember.  I've read through the faqs and man pages,
and, well, I can't figure it out.

Hope someone out there can help!

Thanks -

Richard



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

Date: Thu, 23 Jul 1998 13:13:27 -0400
From: Michael Bowler <mkbowler@nortel.com>
Subject: Re: How to know the number of hash items without running loop.
Message-Id: <35B76F37.349F1B47@nortel.com>

Michele Beltrame wrote:
> 
> >Without running loop, is there way to count how many items the hash has?
> 
> You can use something like:
> 
> @hkeys = keys(%myhash);
> $numitems = $#hkeys;
> 

That probably should be: $numitems = $#hkeys + 1;
as $#<array> returns the last valid index of an array which is one less than the
number of elements in the array.

However, the 'keys' function returns the number of hash keys when used in a
scalar context. ie. the above code can simply be written:
   $numitems = keys(%myhash);

-- 
   Michael Bowler                     Phone:    613-765-3432
   IC Design Tools - 5T11             ESN:          39+53432
   Nortel Semiconductors              Email: mkbowler@nt.com


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

Date: Thu, 23 Jul 1998 14:22:00 -0400
From: "J.Adams" <webmaster@ent-media.org>
Subject: htpasswd
Message-Id: <35B77F47.C0F8D64D@ent-media.org>



Im attempting to write a perl script to
update my .htaccess files but i see two problems..
if i use the system command htpasswd to update theres no way i
know of to update confirm the password...

if i use the crypt method the password file...

help.. i can't pay someone 40 dollars for this script like they want on
cgi-resources because i know it is something small that i am missing
--
____________________
One Life, One Love
Peace
J.Adams
LowBudget Ent...
http://ent-media.org/
adamsj@ent-media.org
adamsj@yodelf.com
icq: 1995945
page: wwp.mirabilis.com/1995945
phone:(803)318-0209 -cell
____________________
pppppp   eeeeeee   aaa    cccc   eeeeeee
ppppppp  eeeeeee aaaaaaa ccccccc eeeeeee
pp   ppp eee     aa   aa cc   cc eee
pp   ppp eeeeee  aa   aa cc      eeeeee
ppppppp  eeeeee  aaaaaaa cc      eeeeee
pppp     eee     aaaaaaa cc   cc eee
pppp     eeeeee  aa   aa ccccccc eeeeeee
pppp     eeeeee  aa   aa  ccccc  eeeeeee

             -Low Budget designz/Entertainment-




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

Date: Thu, 23 Jul 1998 15:58:44 GMT
From: aichner@us.ibm.com (Woodward S. Aichner)
Subject: Re: Installation of Perl V5.004_04 on IBM AIX V4.2
Message-Id: <35b75ce2.13555020@rtpnews.raleigh.ibm.com>

On Thu, 23 Jul 1998 12:12:31 +0200, Daniel Hams <dhm@ficsgrp.com>
wrote:

Daniel,
   Thanks for the response. I got farther along......Now I get.

        ../../miniperl "-I../../lib" "-I../../lib" -e 'use
ExtUtils::Mksymlists;
  Mksymlists("NAME" => "IO", "DL_FUNCS" => {  }, "DL_VARS" => []);'
        ../../miniperl -I../../lib -I../../lib
 ./../lib/ExtUtils/xsubpp -noprot
otypes -typemap ../../lib/ExtUtils/typemap IO.xs >IO.tc && mv IO.tc
IO.c
        cc -c  -qmaxmem=8192 -D_ALL_SOURCE -D_ANSI_C_SOURCE
-D_POSIX_SOURCE -O
   -DVERSION=\"1.1504\"  -DXS_VERSION=\"1.15\"  -I../..  IO.c
Running Mkbootstrap for IO ()
        chmod 644 IO.bs
        LD_RUN_PATH="" ld -o ../../lib/auto/IO/IO.none   IO.o
ld: 0711-327 WARNING: Entry point not found: __start
ld: 0711-244 ERROR: No csects or exported symbols have been saved.
make: 1254-004 The error code from the last command is 8.  

Should LD_RUN_PATH be set?

Woody Aichner


>When running configure, try resetting it to _not_ use nm to extract
>symbols from libs.
>
>AIX nm seems to be a bit pants and socks.
>
>Mr Thinly Sliced.
>
>Gary K. Waugaman wrote:
>> 
>> I'm a Perl neophyte. I'm attempting to install Perl5.004 because the DBI
>> interface that we are trying to install does not run on our Perl5.002
>> level. I'm not the installer of the 5.002 level. My system is a RS6000
>> running AIX.
>> 
>> Anyway, I accepted all the defaults for sh Configure and this is what I
>> got from make....
>> 
>>         AutoSplitting perl library



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

Date: Thu, 23 Jul 1998 20:13:03 +0200
From: Eric Zylberstejn <Eric.Zylberstejn@wanadoo.com>
To: Danny van der Rijn <dannyv@tibco.com>
Subject: Re: installing perl in a different directory, @INC
Message-Id: <35B77D2F.C44348ED@wanadoo.com>

Hello,

Danny van der Rijn wrote:
> 
> Eric Zylberstejn wrote:
> > Jello,

This was meant to be Hello.

> > Danny van der Rijn wrote:
> > > i want to be able to compile perl (5.00404) and then have people install
> > > it whereever they want to.
> > >
> > > on Solaris 2.6, this doesn't work so fine, since the @INC list is
> > > compiled into PERL and therefore PERL finds none of its libraries.
> > > [...]
> >
> > Set PERL5LIB, do a 'man perlrun'.
> >
> > Remember to put your platform specific librairies path in PERL5LIB.
> >
> 
> did i forget to mention that i don't want the user to have to do
> anything like changing his environment?  (web servers, etc.)

I thought, that since they could install Perl where they wanted to, they could
also change an environment variable.

Some thoughts (haven't tried) :
 . probably can't 'use Config' because Perl won't find it ;
 . by doing a 'which perl', I can know where it is installed ;
 . I can hope that Perl has been installed in a standard way, which means the
libraries are in ../lib/perl5 (relative to the bin directory) ;
 . could try to change @INC on the fly with `which perl` . '../lib/perl5'.


	Eric.pl


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3235
**************************************

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