[8981] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2600 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 14 18:08:16 1998

Date: Thu, 14 May 98 15:01:37 -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, 14 May 1998     Volume: 8 Number: 2600

Today's topics:
        newbie: looping through a directory to open various fil <llussier@newscorp.com>
    Re: newbie: looping through a directory to open various <sowmaster@juicepigs.com>
    Re: newbie: looping through a directory to open various <rootbeer@teleport.com>
    Re: NT IIS #exec cgi <rootbeer@teleport.com>
    Re: OO perl and speed <jll@skynet.be>
    Re: Perl Not Showing Errors (Ilya Zakharevich)
        Perl to C Compiler for Windows <bobras@erols.com>
    Re: Perl to C Compiler for Windows <rootbeer@teleport.com>
    Re: perl5.004_04 bug/weakness?: tie %hash and scalar(%h <rootbeer@teleport.com>
        PERL5LIB, @INC, and "Can't locate loadable object..." eryq@zeegee.com
    Re: PERL5LIB, @INC, and "Can't locate loadable object.. <rootbeer@teleport.com>
        POP mail cgi client mikhael@my-dejanews.com
    Re: POP mail cgi client <rootbeer@teleport.com>
    Re: REGEX Question <kmiles@erols.com>
    Re: regexp for strings of chars (Ilya Zakharevich)
        sorting an array of associative arrays? <lyonsd@atl.hp.com>
    Re: sorting an array of associative arrays? <rootbeer@teleport.com>
    Re: TIMTOWTDI - regex vs. if (function) <ward.kaatz@pss.boeing.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 14 May 1998 16:25:28 -0400
From: Laurie Lussier <llussier@newscorp.com>
Subject: newbie: looping through a directory to open various files
Message-Id: <355B5338.E9066830@newscorp.com>

Hi,

I am new at Perl, and I need to loop through a directory which consists
of 100
subdirectories.  Go into each sub-directory, and open the files in the
subdirectory
one at a time to grab info.  Can anyone tell me how to do what I am
trying to do?
I've looked in the FAQs, the perl man pages, and a few perl books, and
I'm still
lost.  It works for the first file opened, but after that it says that
I'm accessing a closed filehandle.

foreach(@files_in_dir)
{
                              #Open the current file.
     open(FILE, $_);
                              #Read file into lines array.
                              #Each line a different entry.
     @lines = <FILE>;
                              #Close file.
      close(FILE);
                              #loop through the array
      foreach(@lines)
      {
                            #Set $_ to each entry in the array.
           chop;
                              #Match the fields that are needed.
         .....do a bunch of stuff
       }
  }
Thanks,
Laurie Lussier



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

Date: Thu, 14 May 1998 17:04:13 -0400
From: Bob Trieger <sowmaster@juicepigs.com>
To: Laurie Lussier <llussier@newscorp.com>
Subject: Re: newbie: looping through a directory to open various files
Message-Id: <355B5C4D.14AB@juicepigs.com>

[mailed and posted]

Laurie Lussier wrote:

> foreach(@files_in_dir)
> {
>                               #Open the current file.
>      open(FILE, $_);

Did the open work? You should always check the status:
	open(FILE, "$_") or die "can't open $_: $!";

 ...

>       close(FILE);

Can't hurt to check the status of your close too.

 ...

>            chop;

Use "chomp" it's a lot safer.


HTH
-- 
Bob Trieger               |  Titanic: big boat, bigger
sowmaster@juicepigs.com   |           iceberg, big deal


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

Date: Thu, 14 May 1998 21:33:51 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Laurie Lussier <llussier@newscorp.com>
Subject: Re: newbie: looping through a directory to open various files
Message-Id: <Pine.GSO.3.96.980514143047.17330I-100000@user2.teleport.com>

On Thu, 14 May 1998, Laurie Lussier wrote:

> I am new at Perl, and I need to loop through a directory which consists
> of 100 subdirectories.  Go into each sub-directory, and open the files
> in the subdirectory one at a time to grab info.  Can anyone tell me how
> to do what I am trying to do? 

It sounds like a job for File::Find.

> It works for the first file opened, but after that it says that
> I'm accessing a closed filehandle.

That's probably because you are. :-) Remember that if you re-open a
filehandle on a second file, you close it on the first one. This means
that you can't use the same filehandle (or, for a parallel reason, the
same directory handle) in a recursive routine without saving and restoring
it (say, via local). That's another good reason to use a module like
File::Find.

>      open(FILE, $_);

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 14 May 1998 21:22:24 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Scott Williams <swilliams@NOSPAM.cshore.com>
Subject: Re: NT IIS #exec cgi
Message-Id: <Pine.GSO.3.96.980514142151.17330F-100000@user2.teleport.com>

On Thu, 14 May 1998, Scott Williams wrote:

> It used to work, but when we re-installed IIS I can't remember what we did.

Sounds a lot like a problem with the server, rather than with Perl. Hope
this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 14 May 1998 23:33:48 +0200
From: Jean-Louis Leroy <jll@skynet.be>
Subject: Re: OO perl and speed
Message-Id: <VA.00000057.0061a776@enterprise>

> But the fget_four is unrealistic.  Few access methods are so simple.

Hmm, I dare disagree...fget_four is your typical inlined C++ accessor. In my 
book, accessors are brainless methods. Anyway, if the method does more than a 
hash access, the relative importance of the method call overhead diminishes.

Did you follow the thread I initiated on immediate subroutines? If they could 
be made to work in a strongly typed OO Perl, they would allow writing accessors 
that guard against future changes without costing performance in the present...

Dual accessors deserve a discussion of their own. They're cute all right, but 
two remarks spring to mind.

1) Perl doesn't support dual accessors well, because Perl doesn't have 
overloded methods. Please note the plural: overloaded methods are *different* 
methods. Perl, thanks to its great support for variable argument lists, allows 
you to fake overloading, but in reality what's going on smells more like 
polymorphism.

2) One has to wonder, what do dual accessors bring besides their *suspiciuous* 
cuteness? Even in C++, which provides perfect support for them, I can't help 
asking, what's the point?

> In fact, I'm the only one I've ever caught writing in so abbreviated
> a fashion.

In:

> sub fset_four { shift->{"fourth"} = shift }

 ..are the two 'shift' guaranteed to be evaluated in a determined order?

> :ps why do you sometimes write $obj->{"fourth"} and sometimes $obj->{fourth}?
>  
> To make you ask these questions. :-)

For a moment I forgot that Perl was a natural language :o)

Jean-Louis Leroy
http://ourworld.compuserve.com/homepages/jl_leroy/



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

Date: 14 May 1998 20:24:08 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl Not Showing Errors
Message-Id: <6jfjt8$4rb$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Tom Phoenix 
<rootbeer@teleport.com>],
who wrote in article <Pine.GSO.3.96.980514100418.21974c-100000@user2.teleport.com>:
> > I have a problem when running large Perl programs where if there is an
> > error someplace, Perl will throw its hands up in the air and report
> > only: 
> > 
> > "XXXX had compilation errors."
> > 
> > and not tell me *anything* about those errors.  
> 
> For real? That message should show up only at the end of a 'perl -c'
> check, and only after other diagnostic messages. If that's not happening
> for you, are you using a recent version of Perl? Cheers! 

I think I have seen it with quite recent Perls.  Some $@-overwrite
is possible still.  If some object is DESTROYed before the error
message has a chance to be shown, $@ may be overwritten.

Do not remember how it would happen, and with which version of Perl,
but definitely during the last year (thus with a version which is
younger than one year old).

Ilya


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

Date: Thu, 14 May 1998 16:55:15 -0400
From: Bob Rasmussen <bobras@erols.com>
Subject: Perl to C Compiler for Windows
Message-Id: <355B5A33.29B5@erols.com>

Afternoon, all...

I am in need of a Windows 95 version of the Perl to
C source which I successfully use on my Unix box.

I have converted Unix Perl to C source, but, my Windows
C compiler balks at some of the include statements in
the C source file.

I also can find no equivalent for the dump/undump
commands in Windows.  

Prior to the announcement of Perl 5, there was some
talk about providing a compiled version of Perl.  I'm
developing software that cannot be left in a readable/
changeable state for both Unix and Windows 95.  Anyone
have any suggestions?  

Any help appreciated...Bob


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

Date: Thu, 14 May 1998 21:45:36 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Bob Rasmussen <bobras@erols.com>
Subject: Re: Perl to C Compiler for Windows
Message-Id: <Pine.GSO.3.96.980514144412.17330L-100000@user2.teleport.com>

On Thu, 14 May 1998, Bob Rasmussen wrote:

> Subject: Perl to C Compiler for Windows

Have you seen what the FAQ says about this?

> I'm developing software that cannot be left in a readable/ changeable
> state for both Unix and Windows 95. 

Did you realize that compiled Perl can also be de-compiled? :-)

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 14 May 1998 21:21:12 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Paul Fardy <pdf@morgan.ucs.mun.ca>
Subject: Re: perl5.004_04 bug/weakness?: tie %hash and scalar(%hash)
Message-Id: <Pine.GSO.3.96.980514141203.17330E-100000@user2.teleport.com>

On 14 May 1998, Paul Fardy wrote:

> But I now find that the test suggested in the man page does not
> work for me: not for hashes instantiated by tie(). 

That sounds like a bug to me. Use the perlbug command to report it. (Or
contact the module's author directly, if that's where the bug lies.)

> What should I do in the mean time?  I could test whether each()
> immediately returns an end-of-list indicator, but how do I reset
> the iterator?  

Use keys() in a scalar or void context to reset the iterator. But, of
course, you should be able to use keys() in a scalar context to find out
the number of elements, if that's what you want. 

> To fix my original problem, all I need is an efficient means
> checking that the tie() succeeded; 

> I could just use the ref/undef returned by tie().

That's the way to do it!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 14 May 1998 20:25:55 GMT
From: eryq@zeegee.com
Subject: PERL5LIB, @INC, and "Can't locate loadable object..."
Message-Id: <6jfk0j$9ap$1@nnrp1.dejanews.com>

I'm trying to put together an application under 5.00404
on HP/UX which uses GDBM_File... one problem: this site's
Perl installation doesn't include GDBM_File.  Fortunately,
though, it *does* do dynamic loading.

I was able to assemble a libgdbm.a and I grabbed the
GDBM_File extension from the Perl sources... everything
works *fine* so long as I have my local perl lib
directory in my PERL5LIB part.

When I try to just "use lib ..." that directory, though,
and erase the PERL5LIB environ var, I get...

    Can't locate GDBM_File.pm in @INC (@INC contains...)

where @INC contains the same path to my Perl modules as was
in my PERL5LIB environment variable!  It *seems* as though
"use lib X" does not work *quite* the same as
having X in PERL5LIB, but I find that hard to believe.
Somehow, I must be doing something wrong... right?

My question: assuming I keep the application's
modules in /home/eryq/lib/perl, and thus have
/home/eryq/lib/perl/GDBM_File.pm, where should
libgdbm.a be placed?

TIA,

Eryq.










-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Thu, 14 May 1998 21:37:37 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: eryq@zeegee.com
Subject: Re: PERL5LIB, @INC, and "Can't locate loadable object..."
Message-Id: <Pine.GSO.3.96.980514143441.17330J-100000@user2.teleport.com>

Hi, Eryq!

On Thu, 14 May 1998 eryq@zeegee.com wrote:

> When I try to just "use lib ..." that directory, though,
> and erase the PERL5LIB environ var, I get...
> 
>     Can't locate GDBM_File.pm in @INC (@INC contains...)
> 
> where @INC contains the same path to my Perl modules as was
> in my PERL5LIB environment variable!  

Weird! Are you absolutely sure that you've got the exact same path in both
places? (For example, could there be control characters or whitespace in
the name somewhere? Printing unpack("H*", $whatever) can be informative.)
Also, can you set PERL5LIB within a BEGIN block in your program to get it
to work?

But you may have uncovered a real bug....

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 14 May 1998 20:19:55 GMT
From: mikhael@my-dejanews.com
Subject: POP mail cgi client
Message-Id: <6jfjlb$8j0$1@nnrp1.dejanews.com>

Is there a way to recieve pop mail... and display it in HTML for a user?? I
have a pop3 mail server.??

Something like the way hotmail does it.. I don't want to use java or activeX
because some of the browsers may be on old unix machines...

Mike

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Thu, 14 May 1998 21:26:56 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: mikhael@my-dejanews.com
Subject: Re: POP mail cgi client
Message-Id: <Pine.GSO.3.96.980514142606.17330G-100000@user2.teleport.com>

On Thu, 14 May 1998 mikhael@my-dejanews.com wrote:

> Is there a way to recieve pop mail... and display it in HTML for a user?? 

Yes. You can even do this with ease, via a Perl script and a couple of
modules.

> I have a pop3 mail server.?? 

I don't know. Do you? :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 14 May 1998 16:43:04 -0400
From: Kevin Miles <kmiles@erols.com>
Subject: Re: REGEX Question
Message-Id: <355B5758.9427B2B3@erols.com>

Try this:

if (/\s*(\S*)\s*(\d+\.\d+)\s*(.*?)\d/)


Gary Chambers wrote:

> #!/usr/bin/perl -w
>
> while (<>)
> {
>     if (/\s*(\S*)\s*(\d+\.\d+)\s*(\S*){1,3}/)
>     {
>        $login = $1; $totalpmt = $2; $frequency = $3;
>        print "$login\t$totalpmt\t$frequency\n";
>     }
> }
>
> Why am I only extracting "Twice" in the "Twice a year" field?  Should
> I not be getting all three of the words with {1,3} in the regexp?  Any
> help is *GREATLY* appreciated...





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

Date: 14 May 1998 20:18:18 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: regexp for strings of chars
Message-Id: <6jfjia$4bk$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Tom Christiansen 
<tchrist@mox.perl.com>],
who wrote in article <6jf8vo$4oh$1@csnews.cs.colorado.edu>:
> For overlapping matches, do this:
> 
>     my $string = 'aaaaaabbb,,,xyfooffff';
>     push(@trips, $1) while $string =~ m/(?=((.)\2{2}))/g;

After almost-successful //h debate (heirarchical match) on p5p I
decided to postpone implementing (?.REX) construct (which would hide
parens/backrefs from the enclosing RE, and would start counting groups
from 1).  With such a construct, this might have been optimized to

    @trips = m/(?=((?.(.)\1{2})))/g

and it might have been beautified to

    $triple = qr/(?.(.)\1{2})/;

    @trips = m/(?=($triple))/go;

Note that I would be a little bit wary to use //g with zero-length
expression - unless necessary.  Though it looks hard to avoid it in
the above construct.  This

    @trips = m/.(?<=(?=($triple)).)/go;

is completely overboard.  :-(

Ilya


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

Date: Thu, 14 May 1998 16:12:11 -0400
From: "David A. Lyons" <lyonsd@atl.hp.com>
Subject: sorting an array of associative arrays?
Message-Id: <355B501B.30D39013@atl.hp.com>

Here's what I need:

Suppose I want to read a bunch of data from a number of files.  All the
data out of a file must be kept together.  The data in the files is as
such:

file 1:
k1 = v1
k2 = v2
k3 = v3
 ...
 ...

file 2, 3, 4, ... are formated the same way; they keys will be the same,
but the values will be different from other files.

How can I read in the data from all these files (the number of files is
dynamic), sort and subsort the data on certain keys, yet keeping all the
data from each file together, so I can print it out together.

Or is there an easier way to accomplish the same goal besides using
mutiple files to store the data?

Basically, what I'm trying to do is allow users to input their data, and
display the previously inputted data from all other users sorted &
subsorted on any give field.

Dave


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

Date: Thu, 14 May 1998 21:30:32 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: "David A. Lyons" <lyonsd@atl.hp.com>
Subject: Re: sorting an array of associative arrays?
Message-Id: <Pine.GSO.3.96.980514142723.17330H-100000@user2.teleport.com>

On Thu, 14 May 1998, David A. Lyons wrote:

> How can I read in the data from all these files (the number of files is
> dynamic), sort and subsort the data on certain keys, yet keeping all the
> data from each file together, so I can print it out together. 

There Is More Than One Way To Do It. One way would be to use the methods
of perldsc to build a data structure. Another would be to keep separate
arrays of parallel data and sort their indices. Would one of those do what
you want? Hope this helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/




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

Date: Thu, 14 May 1998 20:47:42 GMT
From: Ward Kaatz <ward.kaatz@pss.boeing.com>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: TIMTOWTDI - regex vs. if (function)
Message-Id: <355B586E.31C6@pss.boeing.com>

Larry Rosler wrote:
 
> Do you need a module for something this trivial?
> 
> my ($mday, $mon, $year) = (localtime)[3 .. 5];
> sprintf '%d%.2d%.2d', 1900 + $year, $mon + 1, $mday;

Larry, thanks for the alternative!  I agree that using a module in this
case is not desirable.  Not necessarily for performance as that is not
an issue with this particular task, but due to the desire to not add any
more variables in my environment which is not especially "perl
friendly".

I considered but avoided use of (s)printf based on the camel book
observation (pg 200, 2nd ed.).

I posed my question to get some other ideas on the subject and so far so
good!  two different approaches in additon to the two I listed.

aparently my regex is OK.  my (perl) focus right now is to become more
comfortable using regex's, in addition to getting more insight as to
when to use and not use them in place of "traditional" methods (or
should I say, semi-perlish methods) like my first cut, using a function
to test the length.

thanks again,
Ward

PS:  I did try your example, but it's not working (as written) on my
box...


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 2600
**************************************

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