[16184] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3596 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 18:58:56 2000

Date: Mon, 10 Jul 2000 15:58:46 -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: <963269926-v9-i3596@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 10 Jul 2000     Volume: 9 Number: 3596

Today's topics:
        Removing the directory recursivley <maciek@treko.net.au>
    Re: Removing the directory recursivley <news@fido.workone.com>
    Re: Removing the directory recursivley <brendon@shipreg.com>
    Re: Removing the directory recursivley <randy@theoryx5.uwinnipeg.ca>
    Re: Removing the directory recursivley <lr@hpl.hp.com>
    Re: Removing the directory recursivley thgibbs@my-deja.com
        Removing white spaces <abouf066@aix2.uottawa.ca>
    Re: Removing white spaces (Clinton A. Pierce)
    Re: Removing white spaces (Decklin Foster)
    Re: Removing white spaces (Tad McClellan)
    Re: Repleace "/" with "\" <aakbari@crosskeys.com>
    Re: Repleace "/" with "\" (Villy Kruse)
        Retrieving Get Variables <six4eight@NOSPAMhotmail.com>
    Re: Retrieving Get Variables <six4eight@NOSPAMhotmail.com>
    Re: Retrieving Get Variables (brian d foy)
    Re: return by value (Abigail)
        Return image <jumigas@ctv.es>
    Re: Return image <bwalton@rochester.rr.com>
    Re: running unix commands in CGI <lr@hpl.hp.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 06 Jul 2000 12:18:39 +0800
From: Maciej Mastalarczuk <maciek@treko.net.au>
Subject: Removing the directory recursivley
Message-Id: <3964089F.467F534@treko.net.au>

Hello Everyone,

Probably that question has been here hundreds of times, but I missed
that hundreds of responses. Sorry.

How to remove the directory recursively?
rmdir function removes it only when the directory is empty. Is there any
simple way to do it in Perl? Certainly the script is invoked by
superuser.

Regards,
Maciej



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

Date: Thu, 6 Jul 2000 09:52:07 +0200
From: Kirill Miazine <news@fido.workone.com>
Subject: Re: Removing the directory recursivley
Message-Id: <Pine.LNX.4.21.0007060943540.1262-100000@escamillo.uio.no>


hi,
You should run thugh the directory and delete all files, if you see
another directory, repaeat the same thing there etc...
Something like:

&rm_dir("/home/me/tmp") and print "Removed\n";
sub rm_dir {
    my $foo = shift;
    opendir(DIR, $foo);
    foreach (readdir(DIR)) {
        next if ($_ eq "." or $_ eq "..");
        if (!-l "$foo/$_" and -d "$foo/$_") {
            &rm_dir("$foo/$_");
        } else {
            unlink("$foo/$_");
        }
    }
    closedir DIR;
    return rmdir($foo) ? 1 : 0;
}

I think that should work... 

There should also be a module do do the job.


On Thu, 6 Jul 2000, Maciej Mastalarczuk wrote:

# Hello Everyone,
# 
# Probably that question has been here hundreds of times, but I missed
# that hundreds of responses. Sorry.
# 
# How to remove the directory recursively?
# rmdir function removes it only when the directory is empty. Is there any
# simple way to do it in Perl? Certainly the script is invoked by
# superuser.
# 
# Regards,
# Maciej
# 
# 



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

Date: Thu, 6 Jul 2000 11:39:15 +0200
From: "Brendon Caligari" <brendon@shipreg.com>
Subject: Re: Removing the directory recursivley
Message-Id: <8k1gks$m8j$1@news.news-service.com>

"Maciej Mastalarczuk" <maciek@treko.net.au> wrote in message
news:3964089F.467F534@treko.net.au...
> Hello Everyone,
>
> Probably that question has been here hundreds of times, but I missed
> that hundreds of responses. Sorry.
>
> How to remove the directory recursively?
> rmdir function removes it only when the directory is empty. Is there any
> simple way to do it in Perl? Certainly the script is invoked by
> superuser.
>
> Regards,
> Maciej

why do in perl what the shell can do in a one liner?
"rm -R" under unix
"del /s" in windows

however please check the right parameters, etc as i'm not sure and let's
face it...such a delete is not something i do on a regular basis

B.




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

Date: 6 Jul 2000 14:51:29 GMT
From: Randy Kobes <randy@theoryx5.uwinnipeg.ca>
Subject: Re: Removing the directory recursivley
Message-Id: <8k26dh$p82$1@canopus.cc.umanitoba.ca>

In comp.lang.perl.misc, Maciej Mastalarczuk <maciek@treko.net.au> wrote:

> How to remove the directory recursively?

Try the rmtree function of File::Path - see 'perldoc File::Path'.

best regards,
randy kobes


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

Date: Thu, 6 Jul 2000 11:05:42 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Removing the directory recursivley
Message-Id: <MPG.13ce6a4dc5483b8198abaf@nntp.hpl.hp.com>

In article <Pine.LNX.4.21.0007060943540.1262-100000@escamillo.uio.no> on 
Thu, 6 Jul 2000 09:52:07 +0200, Kirill Miazine <news@fido.workone.com> 
says...

 ...

> &rm_dir("/home/me/tmp") and print "Removed\n";
> sub rm_dir {
>     my $foo = shift;
>     opendir(DIR, $foo);
>     foreach (readdir(DIR)) {
>         next if ($_ eq "." or $_ eq "..");
>         if (!-l "$foo/$_" and -d "$foo/$_") {
>             &rm_dir("$foo/$_");
>         } else {
>             unlink("$foo/$_");
>         }
>     }
>     closedir DIR;
>     return rmdir($foo) ? 1 : 0;
> }
> 
> I think that should work... 

It cannot work, because the dirhandle DIR is global.  If you encounter a 
subdirectory while reading a directory, the rest of the directory being 
read will not be found.

You must use a local dirhandle, as discussed in perlfaq5: "How can I 
make a filehandle local to a subroutine? ..."

> There should also be a module do do the job.

There is, as others have pointed out.

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


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

Date: Thu, 06 Jul 2000 20:43:21 GMT
From: thgibbs@my-deja.com
Subject: Re: Removing the directory recursivley
Message-Id: <8k2r16$g05$1@nnrp1.deja.com>

Also, in Unix you might want to add the -f flag to prevent
prompting for files without write permission.

rm -rf * will remove all files in all directories and all directories.
(note: -R and -r are synonomous)

In article <8k1gks$m8j$1@news.news-service.com>,
  "Brendon Caligari" <brendon@shipreg.com> wrote:
> "Maciej Mastalarczuk" <maciek@treko.net.au> wrote in message
> news:3964089F.467F534@treko.net.au...
> > Hello Everyone,
> >
> > Probably that question has been here hundreds of times, but I missed
> > that hundreds of responses. Sorry.
> >
> > How to remove the directory recursively?
> > rmdir function removes it only when the directory is empty. Is
there any
> > simple way to do it in Perl? Certainly the script is invoked by
> > superuser.
> >
> > Regards,
> > Maciej
>
> why do in perl what the shell can do in a one liner?
> "rm -R" under unix
> "del /s" in windows
>
> however please check the right parameters, etc as i'm not sure and
let's
> face it...such a delete is not something i do on a regular basis
>
> B.
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 9 Jul 2000 13:25:36 -0400
From: <abouf066@aix2.uottawa.ca>
Subject: Removing white spaces
Message-Id: <Pine.A41.3.96.1000709132358.19952A-100000@aix2.uottawa.ca>

Greetings, 
Wondering whether anybody could tell me how can I remove white spaces from
a string (AND LEAVE ONLY ONE SPACE BETWEEN THE WORDS) .

Thanks a lot

_____________________________________________________________
							
					LaBoufarikoise




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

Date: Sun, 09 Jul 2000 18:33:34 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Removing white spaces
Message-Id: <2A3a5.29601$fR2.276073@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <Pine.A41.3.96.1000709132358.19952A-100000@aix2.uottawa.ca>,
	<abouf066@aix2.uottawa.ca> writes:
> Greetings, 
> Wondering whether anybody could tell me how can I remove white spaces from
> a string (AND LEAVE ONLY ONE SPACE BETWEEN THE WORDS) .
> 

Yes.  I can tell you.  But I'd prefer to let you learn it yourself.

You'll probably want to use a regular expression, along with the substitution
operator.  "perldoc perlre" and "perldoc perlop" for information on those.

Next, you'll need to describe exactly what it is you want the pattern to 
match and substitute.  My first shot at it sounds like:

	find occurances of multiple adjacent spaces
	replace this with...
	a single space

Now just write the regular expression, the substitution and follow the examples
on how to use the s/// operator and you're all set.

-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours! 
  clintp@geeksalad.org         for details see http://www.geeksalad.org
"If you rush a Miracle Man, 
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: 9 Jul 2000 18:43:30 GMT
From: fosterd@hartwick.edu (Decklin Foster)
Subject: Re: Removing white spaces
Message-Id: <8kah4i$22p1g$2@ID-10059.news.cis.dfn.de>

abouf066@aix2.uottawa.ca <abouf066@aix2.uottawa.ca> writes:

> Wondering whether anybody could tell me how can I remove white
> spaces from a string (AND LEAVE ONLY ONE SPACE BETWEEN THE WORDS).

Is this one of those "what is the sound of one hand clapping" things?

-- 
There is no TRUTH. There is no REALITY. There is no CONSISTENCY. There
are no ABSOLUTE STATEMENTS. I'm very probably wrong. -- BSD fortune(6)


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

Date: Sun, 9 Jul 2000 15:54:31 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Removing white spaces
Message-Id: <slrn8mhm3n.s7t.tadmc@magna.metronet.com>

On Sun, 09 Jul 2000 18:33:34 GMT, Clinton A. Pierce <clintp@geeksalad.org> wrote:
>[Posted and mailed]
>
>In article <Pine.A41.3.96.1000709132358.19952A-100000@aix2.uottawa.ca>,
>	<abouf066@aix2.uottawa.ca> writes:
>> Greetings, 
>> Wondering whether anybody could tell me how can I remove white spaces from
>> a string (AND LEAVE ONLY ONE SPACE BETWEEN THE WORDS) .
>> 
>
>Yes.  I can tell you.  But I'd prefer to let you learn it yourself.
>
>You'll probably want to use a regular expression

>Next, you'll need to describe exactly what it is you want the pattern to 
>match and substitute.  My first shot at it sounds like:
>
>	find occurances of multiple adjacent spaces
>	replace this with...
>	a single space


I don't think a regular expression is the Right Tool for this
job (If "job" is as Clinton describes above).

   tr/ \r\n\f\t/ /s;


But then, you'll probably need s/// for any leading/trailing 
whitespaces anyway...

 ... so never mind    :-)


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 07 Jul 2000 10:01:43 -0400
From: Afshin Akbari <aakbari@crosskeys.com>
To: Marc Loosli <marcNOmaSPAM@loosli.ws.invalid>
Subject: Re: Repleace "/" with "\"
Message-Id: <3965E2C7.A59E7A32@crosskeys.com>

Hi Marc,

If I understand your problem correct:   replace "/" with "\".

#!/xkeys/local/bin/perl               # set the path to whatever you have.

$in = "C:/dir/dir/file";

print "This is IN: $in\n";
$in =~ s/\//\\/g;                        ######## This is what you need
print "This is IN: $in \n";
exit 1; #return trutfully

Shoud do.

AA

Marc Loosli wrote:

> Hi,
> I am currently facing a problem of replacing "/" with "\".
>
> Also, if I do this:
> $in = "C:/dir/dir/file";
> xxxxxxxxxxxxxxxxxxxxxxxxxx
> print $in; #now print c:\dir\dir\file
>
> If anyone has the idea how to deal with the "/", would you
> please reply to this newsgroup? Thank you very much for the help.
>
> Best Regards
> Marc Loosli
>
> * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
> The fastest and easiest way to search and participate in Usenet - Free!



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

Date: 7 Jul 2000 15:23:29 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Repleace "/" with "\"
Message-Id: <slrn8mbtfh.s9u.vek@pharmnl.ohout.pharmapartners.nl>

On Fri, 07 Jul 2000 10:01:43 -0400, Afshin Akbari <aakbari@crosskeys.com> wrote:
>Hi Marc,
>
>If I understand your problem correct:   replace "/" with "\".
>
>#!/xkeys/local/bin/perl               # set the path to whatever you have.
>
>$in = "C:/dir/dir/file";
>
>print "This is IN: $in\n";
>$in =~ s/\//\\/g;                        ######## This is what you need
>print "This is IN: $in \n";
>exit 1; #return trutfully
>



or if you don't like the leaning touthpicks:

  $in ~= s(/)(\\)g;

or

  $in ~= s!/!\\!g';

You pick the one you prefer.


Villy


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

Date: Fri, 07 Jul 2000 14:38:21 GMT
From: "Eelke Kleijn" <six4eight@NOSPAMhotmail.com>
Subject: Retrieving Get Variables
Message-Id: <xXl95.5979$T3.58517@Typhoon.bART.nl>

Hi all,

To retrieve variables which we posted using GET, I use the url_param()
function.
I want to be able to retrieve every variable posten, even if for instance
extra one are typed behind the url to the script. So if someone submits a
forms, stops it from sending, en then adds a '&Test=This is a test' it
should be able to filter it out as well. The problem is these variables have
to be posted to another CGI script. This is the code I use:

$count = 0;
$countb = 0;

foreach $key(url_param()) {
  $$count = param($key);  # Note this doesn't work. How do I autocreate
different variables everytime perl runs through the foreach loop??
  $$counb = $key; # Same problem here
  $count = $count + 1;
  $ countb = $countb + 1;
}

$count = $equal;
$count = 0;
$countb = 0;

$submit = 'test.cgi'.'?'.'

until ($count == $equal) {
  $submit = $submit.$$count.'='.$$countb;
     if ($count =! $equal) {
       $submit = $submit.'&';
     }
  $count = $count + 1;
  $countb = $countb + 1;
}

# $submit is used later on in the GET http://xx.xx.xx.xx/cgi-bin/$submit
HTTP/1.0\n\n

How do I get this code to work. If you don't understand what I am trying to
do, or if you know of an easier way, please ask me. (or email)

Thnx in advance,
Eelke Kleijn




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

Date: Fri, 07 Jul 2000 15:10:20 GMT
From: "Eelke Kleijn" <six4eight@NOSPAMhotmail.com>
Subject: Re: Retrieving Get Variables
Message-Id: <wpm95.5983$T3.58568@Typhoon.bART.nl>

Never mind I forgot to use my brains :) Figured it out already :-)

L8r

"Eelke Kleijn" <six4eight@NOSPAMhotmail.com> schreef in bericht
news:xXl95.5979$T3.58517@Typhoon.bART.nl...
> Hi all,
>
> To retrieve variables which we posted using GET, I use the url_param()
> function.
> I want to be able to retrieve every variable posten, even if for instance
> extra one are typed behind the url to the script. So if someone submits a
> forms, stops it from sending, en then adds a '&Test=This is a test' it
> should be able to filter it out as well. The problem is these variables
have
> to be posted to another CGI script. This is the code I use:
>
> $count = 0;
> $countb = 0;
>
> foreach $key(url_param()) {
>   $$count = param($key);  # Note this doesn't work. How do I autocreate
> different variables everytime perl runs through the foreach loop??
>   $$counb = $key; # Same problem here
>   $count = $count + 1;
>   $ countb = $countb + 1;
> }
>
> $count = $equal;
> $count = 0;
> $countb = 0;
>
> $submit = 'test.cgi'.'?'.'
>
> until ($count == $equal) {
>   $submit = $submit.$$count.'='.$$countb;
>      if ($count =! $equal) {
>        $submit = $submit.'&';
>      }
>   $count = $count + 1;
>   $countb = $countb + 1;
> }
>
> # $submit is used later on in the GET http://xx.xx.xx.xx/cgi-bin/$submit
> HTTP/1.0\n\n
>
> How do I get this code to work. If you don't understand what I am trying
to
> do, or if you know of an easier way, please ask me. (or email)
>
> Thnx in advance,
> Eelke Kleijn
>
>




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

Date: Fri, 07 Jul 2000 11:30:52 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: Retrieving Get Variables
Message-Id: <brian-ya02408000R0707001130520001@news.panix.com>

In article <xXl95.5979$T3.58517@Typhoon.bART.nl>, "Eelke Kleijn" <six4eight@NOSPAMhotmail.com> posted:

> How do I get this code to work. If you don't understand what I am trying to
> do, or if you know of an easier way, please ask me. (or email)

use the CGI module that comes standard with Perl.  it has great
documentation.

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>


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

Date: 05 Jul 2000 19:28:15 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: return by value
Message-Id: <slrn8m7i64.ibb.abigail@alexandra.delanet.com>

Kuross [WOLL:4009-I:EXCH] (kamri@asiapacificm01.nt.com) wrote on
MMCDLXXXVIII September MCMXCIII in <URL:news:8ius3l$bvs$1@bcrkh13.ca.nortel.com>:
!! Hello,
!! 
!! I have a hash say -> %hash
!! 
!!  I have passed it by value to a subroutine but now when I try to pass it

You cannot. It's impossible to pass hashes or arrays by value. What you
most likely did was passing a *list*, as hashes get flattened out to
lists in list context.

!! back, I can't get the values from it.
!! 
!! How do you pass a value already passed by value it it like
!! 
!! return %$hash; ?
!! 
!! or return $hash; ?
!! 
!! or return \%hash;  ?
!! 
!! I'd like to return it by value as well.


That question cannot be answered, as it's impossible to figure out
what you have, and what you want.



Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'


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

Date: Wed, 05 Jul 2000 19:54:18 GMT
From: "Juan Miguel" <jumigas@ctv.es>
Subject: Return image
Message-Id: <KnM85.48$M%4.3145@m2newsread.uni2.es>

Hello,
Does anybody know how to make a CGI in Perl that it returns me an image (as
if it was a counter) or that it returns me its link so that in the HTML page
can appear the following:

<img src="cgi-bin/prova.pl" width="120" height="20"
alt="Prova">

Thanks.


--
________________________________________
web personal: http://www.ctv.es/USERS/jumigas





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

Date: Wed, 05 Jul 2000 20:30:34 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Return image
Message-Id: <39639B42.B1CC0E72@rochester.rr.com>

Juan Miguel wrote:
 ...
> Does anybody know how to make a CGI in Perl that it returns me an image (as
> if it was a counter) or that it returns me its link so that in the HTML page
> can appear the following:
> 
> <img src="cgi-bin/prova.pl" width="120" height="20"
> alt="Prova">
 ...
> web personal: http://www.ctv.es/USERS/jumigas

What you have should work, assuming that that is how your web server
picks up Perl scripts to run.  In your Perl script which generates the
image, make sure to include an appropriate header line, like:

   print "Content-type: image/gif\n\n";

for example.  Then do:

   binmode STDOUT;

in case your OS is brain life impaired.  Then write your "gif" image (or
whatever image format you wish to use, assuming you modified the header
line appropriately) using whatever Perl tools you want to generate the
image.  GD from the 1st edition of the Perl Resource Kit works good if
you want to use gif -- current versions of GD don't seem to support
gif.  Works great!
-- 
Bob Walton


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

Date: Tue, 4 Jul 2000 14:45:39 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: running unix commands in CGI
Message-Id: <MPG.13cbfae217e1373d98aba1@nntp.hpl.hp.com>

In article <8j8529$lr5$1@internal-news.uu.net>, 
newsposter@cthulhu.demon.nl says...
> Ian FALCAO <ifalc@students.cs.mu.oz.au> wrote:
> 
> > Can anyone tell me why the following script generates a 500 internal
> > server error when it is run while some commands just don't display their
> > output in my browser.
> 
> > system "/usr/bin/ls";
> 
> perldoc -f system
> 
> This is NOT what you want to use to capture
> the output from a command, for that you should use merely backticks or
> qx//, as described in perlop/"`STRING`".

The original poster wasn't trying to capture the output from the 
'ls' command, but to print it to STDOUT.  The problem was the buffering 
of STDOUT by the Perl program.  The solution is

    $| = 1;

before doing any output.

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


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

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 V9 Issue 3596
**************************************


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