[18445] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 613 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 3 03:10:56 2001

Date: Tue, 3 Apr 2001 00:10:38 -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: <986281837-v10-i613@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 3 Apr 2001     Volume: 10 Number: 613

Today's topics:
        Free perl interpreter <mick@farragher77.freeserve.co.uk>
    Re: Free perl interpreter nobull@mail.com
    Re: Free perl interpreter <asdfasdf@ccc.com>
    Re: Free perl interpreter <andras@mortgagestats.com>
    Re: Free perl interpreter <bowman@montana.com>
    Re: Free perl interpreter <fayolle@enseirb.fr>
    Re: Free perl interpreter (Jesse Sheidlower)
    Re: Funny behavior? (Philip Lees)
    Re: Funny behavior? (Tad McClellan)
    Re: GD::Graph help needed (Martien Verbruggen)
    Re: Help with CGI scripts <keesh@users.pleaseremovethisbit.sourceforge.net>
    Re: HELP: need simple replacement for IPC::Run run() fu (Garry Williams)
    Re: how do you pass 2 hash to a sub (Logan Shaw)
    Re: How to create " Who is OnLine " page ? (David Efflandt)
    Re: How to matching multiple patterns in a string in an (John Joseph Trammell)
    Re: How to matching multiple patterns in a string in an (Tad McClellan)
        How to split or sub on multiple spaces <admin@gatordev.net>
    Re: How to split or sub on multiple spaces (Logan Shaw)
    Re: How to split or sub on multiple spaces <admin@gatordev.net>
    Re: Installing Packages or Win 98 Installation Problem? <bjoern@hoehrmann.de>
    Re: list all subdirectories..... (BUCK NAKED1)
    Re: list all subdirectories..... (Damian James)
    Re: list all subdirectories..... (Gwyn Judd)
    Re: list all subdirectories..... (Gwyn Judd)
    Re: list all subdirectories..... (Garry Williams)
    Re: list all subdirectories..... <whataman@home.com>
    Re: log files in sub routines (Garry Williams)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 1 Apr 2001 20:14:57 +0100
From: "Michael Farragher" <mick@farragher77.freeserve.co.uk>
Subject: Free perl interpreter
Message-Id: <9a7uol$v0h$1@newsg3.svr.pol.co.uk>

Can anyone suggest where I can get a free perl interpreter from ?

TIA,

Michael Farragher




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

Date: 01 Apr 2001 20:54:27 +0100
From: nobull@mail.com
Subject: Re: Free perl interpreter
Message-Id: <u9itko8kgc.fsf@wcl-l.bham.ac.uk>

"Michael Farragher" <mick@farragher77.freeserve.co.uk> writes:

> Can anyone suggest where I can get a free perl interpreter from ?

Off of the web - a few clicks away from at the blindingly obvious
URL.  You know http:/www.XXXX.com/ ... but replace XXXX with, well
I'll let you guess.

Or are you looking for an off-line source?

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


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

Date: Sun, 1 Apr 2001 21:26:17 +0200
From: "Ðyl@ñ" <asdfasdf@ccc.com>
Subject: Re: Free perl interpreter
Message-Id: <9a7uhd$f5c$1@fe2.cs.interbusiness.it>

FAQ u.

"Michael Farragher" <mick@farragher77.freeserve.co.uk> ha scritto nel
messaggio news:9a7uol$v0h$1@newsg3.svr.pol.co.uk...
> Can anyone suggest where I can get a free perl interpreter from ?
>
> TIA,
>
> Michael Farragher
>
>




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

Date: Sun, 01 Apr 2001 20:03:34 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: Free perl interpreter
Message-Id: <3AC7C1D6.40B4C13C@mortgagestats.com>



Michael Farragher wrote:

> Can anyone suggest where I can get a free perl interpreter from ?
>
> TIA,
>
> Michael Farragher

A totally free interpreter may be hard to come by, but for only $19.99,
I'll sell you my gently used copy of Perl. And for just $99 more, I can
throw in a bridge, if you are interested in New York City real estate.




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

Date: Sun, 1 Apr 2001 19:13:02 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: Free perl interpreter
Message-Id: <PhQx6.585$584.4410@newsfeed.slurp.net>


Michael Farragher <mick@farragher77.freeserve.co.uk> wrote in message
news:9a7uol$v0h$1@newsg3.svr.pol.co.uk...
> Can anyone suggest where I can get a free perl interpreter from ?

www.danglingpreposition.org





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

Date: Mon, 2 Apr 2001 12:55:00 +0200
From: "Pierre-Alain Fayolle" <fayolle@enseirb.fr>
Subject: Re: Free perl interpreter
Message-Id: <9a9lsj$c9t$1@news.u-bordeaux.fr>

If you are under Windows try Active State Perl: www.activestate.com
If you are under Linux you can too use Active State Perl, but generaly there
is a Perl environment with your distribution.
If you are under mac try MacPerl, I think you will find it via www.perl.com,
the official web site of the perl mongers.

> Can anyone suggest where I can get a free perl interpreter from ?
>
> TIA,
>
> Michael Farragher
>
>
>




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

Date: 2 Apr 2001 11:09:19 -0400
From: jester@panix.com (Jesse Sheidlower)
Subject: Re: Free perl interpreter
Message-Id: <9aa4mv$8u4$1@panix2.panix.com>

In article <9a8pl9$5r6$1@boomer.cs.utexas.edu>,
Logan Shaw <logan@cs.utexas.edu> wrote:
>In article <PhQx6.585$584.4410@newsfeed.slurp.net>,
>bowman <bowman@montana.com> wrote:
>>
>>Michael Farragher <mick@farragher77.freeserve.co.uk> wrote in message
>>news:9a7uol$v0h$1@newsg3.svr.pol.co.uk...
>>> Can anyone suggest where I can get a free perl interpreter from ?
>>
>>www.danglingpreposition.org
>
>"Ending a sentence with a preposition is something up with which we
> will not put."  (Winston Churchill)
>
>Actually, supposedly the Oxford English Dictionary has now changed
>their opinion, i.e. it's something they approve of.

Actually, the Oxford English Dictionary does not discuss the issue,
but if it did, it would merely discuss the history of its usage;
the OED is not in the business of approving grammatical constructions.

Jesse Sheidlower
<jester@panix.com>


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

Date: Mon, 02 Apr 2001 09:31:51 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: Funny behavior?
Message-Id: <3ac84518.6355779@news.grnet.gr>

On Sat, 31 Mar 2001 02:28:32 -0000, Chris Stith
<mischief@velma.motion.net> wrote:

>Philip Lees <pjlees@ics.forthcomingevents.gr> wrote:
>> On Fri, 30 Mar 2001 06:50:16 -0500, tadmc@augustmail.com (Tad
>> McClellan) wrote:
>
>>>Operator error is not the same as a broken tool.
>>>
>>>   perldoc -q '\bhere'
>
>> No documentation for perl FAQ keyword `'\bhere'' found
>
>> However, I find that
>
>> perldoc -q "\bhere"
>
>> produces the desired result.
>
>This is a Microsoft issue, not a Perl or perldoc issue.

<snip>

I've been over this a bit with Tad and Chris over the weekend through
e-mail and I thank them both for their time. Let me repeat my apology
to Chris for not making it clearer that my 'unhelpful' implication was
intended to  refer only to the 'read the FAQ' reference and not to
Chris' other advice, which was indeed helpful.

I was intending to copy some of my response to the group, but looking
through the other posts, there doesn't seem to be much point at this
stage. It's interesting that there appears to be a consensus that, in
the case of here docs, the relevant Perl documentation should be
easier to find. Perhaps it would be easier if they were called
something else - where does the term come from, anyway?

Since I now know that my news server keeps messages long enough for
them to survive the weekend, I won't go the e-mail route again. Next
time I'll just wait for Monday.

Phil
--
@x=split//,'Just another Perl decoder,';split//,'*'x@x;%i=split/=/,
'AA=a=aa= =1=,';for$i(0..$#x){$_[$i]=chr($=+5);while($_[$i]ne$x[$i])
{$_[$i]=$i{$_[$i]}if$i{++$_[$i]};print@_,"\r";while(rand!=rand){}}}
Ignore coming events if you wish to send me e-mail


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

Date: Mon, 2 Apr 2001 07:16:15 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Funny behavior?
Message-Id: <slrn9cgnrv.852.tadmc@tadmc26.august.net>

Philip Lees <pjlees@ics.forthcomingevents.gr> wrote:
>On Sat, 31 Mar 2001 02:28:32 -0000, Chris Stith
><mischief@velma.motion.net> wrote:
>
>>Philip Lees <pjlees@ics.forthcomingevents.gr> wrote:
>>> On Fri, 30 Mar 2001 06:50:16 -0500, tadmc@augustmail.com (Tad
>>> McClellan) wrote:
>>
>>>>Operator error is not the same as a broken tool.
>>>>
>>>>   perldoc -q '\bhere'
>>
>>> No documentation for perl FAQ keyword `'\bhere'' found


>where does the term come from, anyway?


"here-docs" are borrowed from the shell. 

I think the name is too ingrained to be changed...


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


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

Date: Mon, 02 Apr 2001 02:37:37 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: GD::Graph help needed
Message-Id: <slrn9cfpfh.jrg.mgjv@verbruggen.comdyn.com.au>

On Fri, 30 Mar 2001 16:45:26 -0800,
	Bryan Coon <bcoon@sequenom.com> wrote:
> I have an image that I created using the GD module, which works fine.
> I draw some lovely pictures, and have a nice image.
> 
> However I wish to slap a graph on my image, and I am having trouble
> doing it.  Heres a snip of what I have:
> 
> my $im = new GD::Image(100, 100 );
> my $white = $im->colorAllocate(255, 255, 255);
> my $red = $im->colorAllocate(255, 0, 0);
> $im->transparent($white);
> $im->interlaced('true');
> 
> $im->rectangle(10, 10, 20, 20, $red);
> 
> Everything is cool so far........
> 
> Then I try (unsuccessfully) to do this:
> (using GD::Graph::bars)
> @empty = some array of elements, as spaceholders for x axis
> @full = same number of elements but with values for each increment on x
> axis
> my @data = ([\@empty], [\@full]);

Try either

my @data = ([@empty], [@full]);

or

my @data = (\@empty, \@full);

> my $graph = new GD::Graph::bars(50, $bary);
> $graph->set(x_label=>"X label",
>               y_label=>"Y label",
>               title=>"Title",
>               y_max_value=>400,
>               x_max_value=>50,
>               y_tick_number=>40,
>               y_label_skip=>2);
> $graph->gd($im);

What is this supposed to do?

Oh, I think I see what you're trying to do. You're trying to pass $im
to GD::Graph as the object to draw on? I guess I'll have to update the
documentation a bit. This is not how it works. The only thing the gd()
method does is _hand_ you the GD::Image object that it internally has
allocated to draw on. You can then use GD calls to work on it, either
before or after the plot. You cannot, however, pass it an object.

It looks like you are trying to paste the chart on top of the GD object
you have, right? The best way to go about that is something like:

my $im = GD::Image::new($w, $h);
# draw on $im

my $graph = GD::graph::bars->new($wg, $hg);
# do stuff with $graph
my $g_im = $graph->plot(\@data);

# Both $im and $g_im are GD::Image objects
$im->copy($g_im, 0, 0, 0, 0, $wg, $hg);

Of course, you can use any coordinates you want there. In this case,
$im is larger than #g_im, so you need to do it this way. If $im is
smaller, it may be better to do something like:

$g_im = $graph->gd;
$g_im->copy($im, 0, 0, 0, 0, $w, $h);
$g_im = $graph->plot(\@data); # this assigment isn't necessary, but
                              # clearer

> $graph->plot(\@data);
> open(OUT, "> somefile.png");
> print OUT $im->png;
> close OUT;
> 
> This fails, I see no output, and it takes a LOOOONG time.

That's a bit odd... Could you email me some data that goes in @empty
and @full, so I can see why it does?

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd.   | again. Then quit; there's no use
NSW, Australia                  | being a damn fool about it.


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

Date: Sun, 01 Apr 2001 14:31:09 +0100
From: "Ciaran McCreesh" <keesh@users.pleaseremovethisbit.sourceforge.net>
Subject: Re: Help with CGI scripts
Message-Id: <9a7ahp$gkp$1@newsg3.svr.pol.co.uk>

In article <slrn9cct50.rl0.garry@zfw.zvolve.net>, garry@ifr.zvolve.net 
wrote:
> How about skipping all that guessing and read the server's error log to
> find out?  Why is that so hard?  

That's only if you have access to the error logs, and they're verbose
enough to be of help, and you aren't sharing a server with several
thousand other people... Sure, if it's your own server it's dead easy but
if you're using someone else's it isn't always...


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

Date: Tue, 03 Apr 2001 05:15:06 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: HELP: need simple replacement for IPC::Run run() function
Message-Id: <slrn9cin2p.sak.garry@zfw.zvolve.net>

On Mon, 2 Apr 2001 17:58:05 +0000 (UTC), Michael Friendly
<friendly@hotspur.psych.yorku.ca> wrote:

[snip]

> I can do this with a piped-open, but I'm not sure how to handle
> the fact that the  name of the output variable is passed by reference.
> 
> Here's what I tried.  Can someone help?

Yes.  *You* can.  

You shouldn't ask many others to do what perl will do for you.  


> #! /usr/local/bin/perl

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


Actually, just enabling warnings would have given you a *strong* clue
what the problem was.  


> sub run {
> 	my ($program, $input, $output) = @_;


You have now declared (and initialized) three lexically-scoped
variables that will only be "visible" within this subroutine.
Although you have chosen names that match names outside this
subroutine, these are *not* the same as the varibales with the same
name outside of this subroutine.  This may have been some of your
confusion below.  


        my $lines;

> 	open(RUN, "$$program $$input|");

        open(RUN, "$$program $$input|")
	  || die "can't fork $$program $$input: $!";


*Always* check the result of open().  


> 	while ($in = <RUN>) {

        while (my $in = <RUN>) {

> 		$lines .= $in;
> 	}
> 	print $lines;
> 	$$output = $lines;

        close(RUN) || die "$$program $$input failed: $!";

If there are problems running the program, they will likely be
reported here, but only if you close the pipe from the program and
check the result of close().  


> }
> 
> $program = "ls";
> $input = '*.pl';

  my $program = "ls";
  my $input   = '*.pl';
  my $output;

> run \$program, \$input, \$output;
> 
> print "Got:\n$$output";


With only warnings enabled, perl would have warned you that you are
using an unitialized variable here.  With strictures enabled, perl
would have printed a fatal error at run time.  

You are dereferencing a reference to a scalar.  It could also be
written: 

    ${ $output }

But $output now contains the built-up results of running the command
in the run() subroutine.  It does *not* contain a reference to
anything.  You wanted this instead: 

    print "Got:\n$output";

Re-read the perlreftut manual page for the details.  

Incidentally, you must know that 

    $output = `$program $input`;

will produce the same result as calling your run() subroutine.  Right?  

-- 
Garry Williams


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

Date: 1 Apr 2001 23:28:00 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: how do you pass 2 hash to a sub
Message-Id: <9a8v4g$6jb$1@boomer.cs.utexas.edu>

In article <3AC773B5.2F230F94@sympatico.ca>,
afshin akbari  <afshin.akbari@sympatico.ca> wrote:
>Is there a way to pass two hash to a sub and return
>two hash from the sub. A pointer pr an example would be great.

You'd have to use references:

	sub munge
	{
		my ($arg1, $arg2) = @_;
		my ($foo, $bar);
	
		$foo = { reverse %$arg1 };
		$bar = { reverse %$arg2 };

		return ($foo, $bar);
	}

	%hash1 = ( a => 1, b => 2 );
	%hash2 = ( welch => "guild", rawlings => "arch-top" );

	($hashref3, $hashref4) = munge (\%hash1, \%hash2);

This is a contrived example, certainly.  But then again, I can't think
of a way to make it not a contrived example.  (I don't know what
problem you're trying to solve, but often when you find yourself
passing way too many things into and out of a function, you should be
using objects and storing some of the data in the object itself.)

  - Logan
-- 
whose?  my  your   his  her   our   their   _its_
who's?  I'm you're he's she's we're they're _it's_


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

Date: Tue, 3 Apr 2001 05:34:45 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: How to create " Who is OnLine " page ?
Message-Id: <slrn9cio7s.mq.efflandt@efflandt.xnet.com>

On Fri, 30 Mar 2001 18:12:48, Support <kwakeb@arabicteam.com> wrote:
>Hi
>I created a small script that need a username and password
>but I need a Page to tell Who is online from the users ?
>can I do this by cookies , and how ?
>Regards
>Perl Lover

If this is a system question, you neglected to state your OS.

If this is a web related question, the answers are, you have the wrong
newsgroup, and you cannot.  The web is stateless (browser makes 1 request,
server sends 1 response).  You have no way of knowing if they will
return or have gone elsewhere.

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Mon, 02 Apr 2001 04:21:19 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: How to matching multiple patterns in a string in any order.
Message-Id: <slrn9cftgs.78m.trammell@bayazid.hypersloth.net>

On Mon, 02 Apr 2001 04:11:37 GMT, joeybach <unknown@spammesenseless.com> wrote:
> What I am looking to do is match any line containing foo
> and bar no matter how it is listed in the line.

if (/foo/ && /bar/) { ... }



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

Date: Mon, 2 Apr 2001 07:22:27 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to matching multiple patterns in a string in any order.
Message-Id: <slrn9cgo7j.852.tadmc@tadmc26.august.net>

joeybach <unknown@spammesenseless.com> wrote:

>Can any one tell me how to match muliple patterns in a string that would
>not be dependant on the order the that the patterns appear in the string?

>What I am looking to do is match any line containing foo and bar no
>matter how it is listed in the line.


There was a thread on this last week here. Word-wrapped the long URL.

   Subject: Search x keywords in a string ?

   http://groups.google.com/groups?hl=en&lr=&safe=off&ic=1&th=
      579b7ac27b096627&seekd=908728160#908728160


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


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

Date: Mon, 02 Apr 2001 03:05:45 GMT
From: Scott <admin@gatordev.net>
Subject: How to split or sub on multiple spaces
Message-Id: <3AC788FA.69E715B2@gatordev.net>

I'm receiving some output from a unix program in my perlscript:

asdflksad          sadfasffsdad                  sadfsadfas
sadfsadfas

I tried to split on tabs but it didn't work, substituting spaces for
colons revealed that
it's multiple spaces between the fields.
How do I split the lines into an array?
I'm a reg exps newbie,
I tried  s/\s.*?/ but that doesn't work.  Any help, along with an
explanation would
be appreciated.

Thanks,
Scott



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

Date: 1 Apr 2001 22:16:26 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: How to split or sub on multiple spaces
Message-Id: <9a8qua$5uo$1@boomer.cs.utexas.edu>

In article <3AC788FA.69E715B2@gatordev.net>, Scott  <admin@gatordev.net> wrote:
>I'm receiving some output from a unix program in my perlscript:
>
>asdflksad          sadfasffsdad                  sadfsadfas
>sadfsadfas
>
>I tried to split on tabs but it didn't work, substituting spaces for
>colons revealed that
>it's multiple spaces between the fields.
>How do I split the lines into an array?

Split does this by default if you don't give it a regular expression
as an argument:

	while (<>)
	{
		push (@stuff, split);
	}

	foreach $thing (@stuff)
	{
		print "$thing\n";
	}

"perldoc -f split" for more info.

Hope that helps.

  - Logan
-- 
whose?  my  your   his  her   our   their   _its_
who's?  I'm you're he's she's we're they're _it's_


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

Date: Mon, 02 Apr 2001 05:15:08 GMT
From: Scott <admin@gatordev.net>
Subject: Re: How to split or sub on multiple spaces
Message-Id: <3AC7A713.33F89EDC@gatordev.net>



Logan Shaw wrote:

> Split does this by default if you don't give it a regular expression
> as an argument:
>
>         while (<>)
>         {
>                 push (@stuff, split);
>         }
>
>         foreach $thing (@stuff)
>         {
>                 print "$thing\n";
>         }
>
> "perldoc -f split" for more info.
>
> Hope that helps.
>
>   - Logan
> --
> whose?  my  your   his  her   our   their   _its_
> who's?  I'm you're he's she's we're they're _it's_

This is too simple, surely there has to be a more complicated answer.  This really
works, wow!  I only need the 1st and third field.  I can do:
while(<>){
@stuff=split;
$alittlestuff{@stuff[0]}=@stuff[2];
}
There's probably a more elegant one liner for this eh?
Anyway, you helped me immensley.  I was about to study reg exps, now I can put it
off a tad longer.  Thanks, the beer, cheetos, and women are on me, lol

Scott



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

Date: Sun, 01 Apr 2001 15:07:00 +0200
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: Installing Packages or Win 98 Installation Problem?
Message-Id: <3ad527d5.107848778@news.bjoern.hoehrmann.de>

* JR wrote in comp.lang.perl.misc:
>I next try to install CGI or DBI and get the same response:
>
>PPM> install cgi

The package is actually named 'CGI'...
-- 
Björn Höhrmann ^ mailto:bjoern@hoehrmann.de ^ http://www.bjoernsworld.de
am Badedeich 7 ° Telefon: +49(0)4667/981028 ° http://bjoern.hoehrmann.de
25899 Dagebüll # PGP Pub. KeyID: 0xA4357E78 # http://learn.to/quote [!]e
            -- listen, learn, contribute -- David J. Marcus             


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

Date: Sun, 1 Apr 2001 13:48:29 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: list all subdirectories.....
Message-Id: <7649-3AC777FD-134@storefull-243.iap.bryant.webtv.net>

> > BuckNaked wrote:
> > Why not tell the guy how to glob? 
> > @files =3D glob "DIR*";

> tjla@guvfybir.qlaqaf.bet (Gwyn=A0Judd) 
> And would you also tell him how to use > glob to get the
subdirectories? He wants > File::Find. 

I said that because I find that the documentation on File::Find is too
brief and not easy to understand for most of us newbies. What I meant
was... why not just give him the raw perl codes to do it.

Why is "glob" incorrect? "glob" will grab directories and file names,
too. I guess you could just do a conditional statement, something like
"if (-d)" and take that directory name, and glob again in some sort of
loop, but I haven't figured out how to get "glob" to grab
sub-directories and their related files yet. If I knew how, I would have
gladly given him the code to help him out.

Now, if someone can point to some clear explanations and a few examples
on File::Find, I might change my mind. :-) 

Regards,
--Dennis



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

Date: 1 Apr 2001 20:56:18 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: list all subdirectories.....
Message-Id: <slrn9cf5e0.dr8.damian@puma.qimr.edu.au>

BUCK NAKED1 chose Sun, 1 Apr 2001 13:48:29 -0500 (CDT) to say this:
>...
>Why is "glob" incorrect? "glob" will grab directories and file names,
>too. I guess you could just do a conditional statement, something like
>"if (-d)" and take that directory name, and glob again in some sort of
>loop, but I haven't figured out how to get "glob" to grab
>sub-directories and their related files yet. If I knew how, I would have
>gladly given him the code to help him out.
>

You need to wrap your globbing in some some of recursive sub:

[ warning: untested code ]
sub recursive_glob {
	my $path = $_[0];
	my $contents = {};
	for (glob("$path/*") {
		$contents->{$_} = -d ? 
			recursive_glob("$path/$_") : 
			{};
	}
	return $contents;
}

But as has been pointed out, it's easier to use File::Find.
	
>Now, if someone can point to some clear explanations and a few examples
>on File::Find, I might change my mind. :-) 
>

Well, the File::Find docs were pretty clear to me, though it took a little
playing around to make things crystal :-). Here's a short example that I
used to get to know File::Find, but which I found useful enough to keep in
my ~/bin directory (for when the 'find' syntax is just too challenging :-):

#!/usr/local/bin/perl
use warnings;
use strict;
use File::Find;

die "Usage: $0 pattern [directory]\n" unless @ARGV;

finddepth(
    sub {
        my @grep;local $" = '';
        print "$File::Find::name:\n@grep\n",
            if @grep = `grep "$ARGV[0]" $_`;
    }, $ARGV[1] || '.'
);
__END__

Note, this requires a working unix-like grep program -- you'd need cygwin
or similar (with grep in your path) to use this on win32.

Cheers,
Damian
-- 
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;){;(
$:=rand$;+$|)==$;&&next;@;[$;,$:]=@;[$:,$;]}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3 -- a JAPH in progress, I guess...


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

Date: Sun, 01 Apr 2001 21:24:43 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: list all subdirectories.....
Message-Id: <slrn9cf74p.747.tjla@thislove.dyndns.org>

I was shocked! How could Tad McClellan <tadmc@augustmail.com>
say such a terrible thing:
<I said>:
>>> This question has been asked several 
>>> times in the last week. You want the > File::Find module. 
>
>I wonder who it was that said that?

*Raises hand*

>   You are really beginning to wear on me Dennis...

You too huh

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Teutonic:
	Not enough gin.


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

Date: Sun, 01 Apr 2001 21:27:11 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: list all subdirectories.....
Message-Id: <slrn9cf79d.747.tjla@thislove.dyndns.org>

I was shocked! How could BUCK NAKED1 <dennis100@webtv.net>
say such a terrible thing:
>I said that because I find that the documentation on File::Find is too
>brief and not easy to understand for most of us newbies. What I meant
>was... why not just give him the raw perl codes to do it.

Well since you are admitedly a newbie, you shouldn't be attempting to
help. I limit my responses to areas I am sure about.

>Why is "glob" incorrect? "glob" will grab directories and file names,
>too. I guess you could just do a conditional statement, something like

Gah. glob also spawns a shell. Not tremendously efficient if you are
recursing over hundreds of directories. Use File::Find.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
I can't believe that we would lie in our graves, dreaming of things that
we might have been.
-Dave Matthews Band


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

Date: Sun, 01 Apr 2001 22:27:43 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: list all subdirectories.....
Message-Id: <slrn9cfar0.rsu.garry@zfw.zvolve.net>

On Sun, 01 Apr 2001 21:27:11 GMT, Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
> I was shocked! How could BUCK NAKED1 <dennis100@webtv.net>
> say such a terrible thing:
>>I said that because I find that the documentation on File::Find is too
>>brief and not easy to understand for most of us newbies. What I meant
>>was... why not just give him the raw perl codes to do it.
> 
> Well since you are admitedly a newbie, you shouldn't be attempting to
> help. I limit my responses to areas I am sure about.
> 
>>Why is "glob" incorrect? "glob" will grab directories and file names,
>>too. I guess you could just do a conditional statement, something like
> 
> Gah. glob also spawns a shell. Not tremendously efficient if you are
       ^^^^^^^^^^^^^^^^^^^^^^^^
> recursing over hundreds of directories. Use File::Find.

Not as of 5.6.0.  

-- 
Garry Williams


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

Date: Sun, 01 Apr 2001 23:08:21 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: list all subdirectories.....
Message-Id: <3AC7B561.C659A393@home.com>

Gwyn Judd wrote:
> 
> I was shocked! How could BUCK NAKED1 <dennis100@webtv.net>

> >Why is "glob" incorrect? "glob" will grab directories and file names,
> >too. I guess you could just do a conditional statement, something like
> 
> Gah. glob also spawns a shell. Not tremendously efficient if you are
> recursing over hundreds of directories. Use File::Find.
> 
I see your point.

--Dennis


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

Date: Tue, 03 Apr 2001 06:27:35 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: log files in sub routines
Message-Id: <slrn9ciram.sbs.garry@zfw.zvolve.net>

On Mon, 2 Apr 2001 15:04:26 -0400, Speakeasy <artd@speakeasy.net>
wrote:

> I have a script that writes to a log several times in it operations.
> I trying to be efficient I decided that I would be better to open
> the log file once when the first sub was call, and then check if is
> open and just write on subsequent calls.
> 
> 1>How do I know that a filehandle is created and open?

I guess you try to remember if you opened it or not.  Maybe you should
open it *before* calling the subroutine that writes to it and close it
after you're finished writing to it.  

(You might want to use an unititialized lexical in your open()
statement, if you're using perl 5.6.0 or create a lexical filehandle
with IO::File and then just pass the already opened file handle to the
subroutine that requires it.)  

> 2>Also is there a better way to complete the same task?

No clue.  Complete *what* task?  

> 3>What happens when the script end with open files?

What happened when you tried it?  

If you use a lexical as a filehandle, the file will be automatically
closed when the lexical goes out of scope.  See the perlopentut manual
page.  See the IO::File manual page.  Otherwise, why wouldn't you
close it before exiting the program?  

> 4>What the overhead of locks vs. open with exclusive/close

Huh?  

> sub logevent(TextToLog) {
>  use Fcntl ':flock'; # import LOCK_* constants
> 
>  my ($text) = @_;       #only take first scalar
>  my $date=getnow();
>  $AUTOFLUSH=1;
> 
>   if (! defined $fileopned) {      #does file handle exist?
>       open(LOGFILE,">>$LOGFILENAME") || die "Unable to open logfile
> <$LOGFILENAME>";
>       $fileopned=1;
>       print "OPEN\n";
>      }
>   flock(LOGFILE,LOCK_EX);
>   print(LOGFILE "$date $text\n");
>   flock(LOGFILE,LOCK_UN);
>   print "LOG: $date $text\n";
>   return;
> }

This does not make any sense.  Processes opening files for append mode
and writing in unbuffered mode do not need to lock the file they're
writing to.  Just write to it.  

By the way, the subroutine prototype above is invalid.  Also, you
should *always* print $! in an error message about a failed open().
It's pretty mystifying otherwise.  

One last point: check the result of close() on output files.  That's
where you learn about running out of space on the file system.  

-- 
Garry Williams


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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