[25012] in Perl-Users-Digest
Perl-Users Digest, Issue: 7262 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 17 00:07:11 2004
Date: Sat, 16 Oct 2004 21:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 16 Oct 2004 Volume: 10 Number: 7262
Today's topics:
Re: A perl reporting paradigm?? <- Thanks! <noemail@#$&&!.net>
Re: A perl reporting paradigm?? <noemail@#$&&!.net>
Re: A perl reporting paradigm?? <1usa@llenroc.ude.invalid>
Active State Perl with Unix-line endings -- Help <greybria@direct.ca>
Re: Active State Perl with Unix-line endings -- Help <see@sig.invalid>
Re: Active State Perl with Unix-line endings -- Help <tim@vegeta.ath.cx>
Re: Active State Perl with Unix-line endings -- Help <greybria@direct.ca>
Re: DBD-ODBC - Running stored procs, can't bind default <perl&nntp@rhesa.com>
Re: disappearing arguments when one package function ca <ioneabu@yahoo.com>
Finding duplicate sub-expressions in calculator grammar <arsf10@yahoo.com>
Re: Finding duplicate sub-expressions in calculator gra <postmaster@castleamber.com>
Is this really legal? <ioneabu@yahoo.com>
Re: Is this really legal? <tadmc@augustmail.com>
Re: Is this really legal? <tim@vegeta.ath.cx>
Re: Is this really legal? (Malcolm Dew-Jones)
Re: Is this really legal? <jurgenex@hotmail.com>
Re: Is this really legal? <sbryce@scottbryce.com>
Re: Modified example from Camel book doesn't work right (Vijai Kalyan)
Re: perl and time <noreply@gunnar.cc>
Recursive directory removing? <dobedidoo@yahoo.se>
Re: Recursive directory removing? <jurgenex@hotmail.com>
Re: String and Array Programming in Perl <wyzelli@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 16 Oct 2004 10:18:03 -0400
From: Fred <noemail@#$&&!.net>
Subject: Re: A perl reporting paradigm?? <- Thanks!
Message-Id: <pan.2004.10.16.14.18.03.929915@#$&&!.net>
Thanks to all!
Fred
------------------------------
Date: Sat, 16 Oct 2004 10:17:07 -0400
From: Fred <noemail@#$&&!.net>
Subject: Re: A perl reporting paradigm??
Message-Id: <pan.2004.10.16.14.17.05.549398@#$&&!.net>
On Sat, 16 Oct 2004 00:55:03 +0000, A. Sinan Unur wrote:
>> Thanks in advance, and I *think* it was Sinaur (?) who I got this style
>> from.
>
> Assuming you are referring to me, let me point out that, while I would
> very much like to, I cannot take credit for here-docs.
>
> Do read
>
> perldoc perlop
>
> as Sherm has recommended.
>
> S i n a n
it was, you are correct. Sorry about the name thing, I pulled it out of
memory. Thank you Sinan!
------------------------------
Date: Sat, 16 Oct 2004 21:36:02 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: A perl reporting paradigm??
Message-Id: <Xns9584B30ADEC4Easu1cornelledu@204.127.36.1>
Fred <noemail@#$&&!.net> wrote in news:pan.2004.10.16.14.17.05.549398@#
$&&!.net:
> On Sat, 16 Oct 2004 00:55:03 +0000, A. Sinan Unur wrote:
>> S i n a n
> it was, you are correct. Sorry about the name thing, I pulled it out of
> memory. Thank you Sinan!
You are welcome. Don't worry about the name, I just thought I'd pick on you
a little.
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Sat, 16 Oct 2004 09:04:27 -0700
From: "Brian & Colleen" <greybria@direct.ca>
Subject: Active State Perl with Unix-line endings -- Help
Message-Id: <C5adnV-ssIET2-zcRVn-2g@look.ca>
I'm using Active State Perl on a WinXP machine. I also run Cygwin and I
decided I wanted a utility to clean my .bash_history file to remove some
commands and duplicate lines.
The line endings are driving me nuts because I think Perl assumes it's on a
Win Platform but bash is writing Unix-style line endings. I keep ending up
with spurious ^M's in my .bash_history. I'm trying to force things with $/
and $\ but it isn't working. As you can tell from the code, I'm new to Perl
so it's probably something really simple.
----------------------------
use strict;
$/ = "\012"; # force use of Unix-style line endings as created
$\ = "\012"; # bash. Strip them on input and restore on output.
my $delstr = qr /exit|cd|ls|rm|cat|pwd|which/ ;
my $oldline = "zzzzzzz";
my $line = "";
open(INFILE,"<.bash_history");
open(OUTFILE,">.bash_history2");
while ($line=<INFILE>){
chomp $line;
if (($line !~ /$delstr/) && ($line ne $oldline)){
print OUTFILE "$line";
$oldline = $line;
}
}
close INFILE;
close OUTFILE;
if (rename ".bash_history2",".bash_history") {
print "Done.";
}
----------------
Thanks.
Brian
------------------------------
Date: Sat, 16 Oct 2004 12:24:06 -0400
From: Bob Walton <see@sig.invalid>
Subject: Re: Active State Perl with Unix-line endings -- Help
Message-Id: <41714915$1_2@127.0.0.1>
Brian & Colleen wrote:
> I'm using Active State Perl on a WinXP machine. I also run Cygwin and I
> decided I wanted a utility to clean my .bash_history file to remove some
> commands and duplicate lines.
>
> The line endings are driving me nuts because I think Perl assumes it's on a
> Win Platform but bash is writing Unix-style line endings. I keep ending up
> with spurious ^M's in my .bash_history. I'm trying to force things with $/
> and $\ but it isn't working. As you can tell from the code, I'm new to Perl
> so it's probably something really simple.
...
> Brian
Check out the binmode() function:
perldoc -f binmode
You might also try the version of Perl that comes with Cygwin -- it's
probably already installed and ready to go. You might also try a
Unix-aware editor, such as VIM.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Sat, 16 Oct 2004 18:26:30 -0000
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Active State Perl with Unix-line endings -- Help
Message-Id: <slrncn2pnk.gb9.tim@vegeta.saiyix>
Brian & Colleen <greybria@direct.ca> wrote:
> I'm using Active State Perl on a WinXP machine. I also run Cygwin and I
> decided I wanted a utility to clean my .bash_history file to remove some
> commands and duplicate lines.
>
> The line endings are driving me nuts because I think Perl assumes it's on a
> Win Platform but bash is writing Unix-style line endings. I keep ending up
> with spurious ^M's in my .bash_history. I'm trying to force things with $/
> and $\ but it isn't working. As you can tell from the code, I'm new to Perl
> so it's probably something really simple.
> ----------------------------
> use strict;
>
> $/ = "\012"; # force use of Unix-style line endings as created
> $\ = "\012"; # bash. Strip them on input and restore on output.
>
> my $delstr = qr /exit|cd|ls|rm|cat|pwd|which/ ;
> my $oldline = "zzzzzzz";
> my $line = "";
> open(INFILE,"<.bash_history");
> open(OUTFILE,">.bash_history2");
>
> while ($line=<INFILE>){
> chomp $line;
> if (($line !~ /$delstr/) && ($line ne $oldline)){
> print OUTFILE "$line";
> $oldline = $line;
> }
> }
> close INFILE;
> close OUTFILE;
>
> if (rename ".bash_history2",".bash_history") {
> print "Done.";
> }
> ----------------
In addition to the other suggestions, you might just want to use the
tools already at your disposal. Most of the above could be done using
the grep(1) and uniq(1) commands already on your system.
Of course, doing it in perl is more fun!
Tim Hammerquist
------------------------------
Date: Sat, 16 Oct 2004 14:43:27 -0700
From: "Brian & Colleen" <greybria@direct.ca>
Subject: Re: Active State Perl with Unix-line endings -- Help
Message-Id: <h_GdnSQy4pKYC-zcRVn-iw@look.ca>
Good point both Tim and Bob made about using Unix tools to solve Unix
problems. I updated my Cygwin to include Perl and that seems to take care of
the confusion over line endings. What I thought should be a good little
"learning" project turned out to be more educational than I bargained for.
Thanks for the suggestions.
Brian
------------------------------
Date: Sat, 16 Oct 2004 18:26:09 +0200
From: Rhesa Rozendaal <perl&nntp@rhesa.com>
Subject: Re: DBD-ODBC - Running stored procs, can't bind default values.
Message-Id: <41714b9e$0$78738$e4fe514c@news.xs4all.nl>
Pablo S wrote:
> Hello!
>
> I've been using DBD::ODBC and Openlink's MSSQL ODBC driver to run
> stored procs on a remote windows server, and it is working. I can get
> my return values back just fine (-IF- I use the ODCB RPC syntax and
> not the TSQL syntax), but I can't seem to run a stored proc and use
> the 'default' keyword to not have to define a parameter.
What I do is this:
$sth=$gpdbh->prepare('exec sp_foo @p1=?, @p2=?');
$sth->execute('value1', 'value2');
HTH,
Rhesa
------------------------------
Date: Sat, 16 Oct 2004 12:49:08 -0400
From: wana <ioneabu@yahoo.com>
Subject: Re: disappearing arguments when one package function calls another
Message-Id: <10n2kh71u8fidf8@news.supernews.com>
>> .
>> sub LoadFromFile
>> #takes array reference and file name as argument
>> #and clears array and fills array with file contents
>
> You claim this function takes an array refernece.....
>
>> {
>> my ($array, $filename) = @_;
>> open my $file, '<', $filename or die "Couldn't open $filename:
>> $!";
>> @{$array} = <$file>;
>> close $file or die "Error closing $filename: $!";
>> }
>> .
>> .
>> .
>> sub ReplaceInFile
>> {
>> #parameters
>> my $target = shift; #string to search for to replace
>> my $source = shift; #string to replace with
>> my $infile = shift;
>> my $outfile = shift;
>>
>> #private variables
>> my @workspace;
>>
>> LoadFromFile(@workspace,$infile);
>
> ...But here you pass the function an empty list followed by $infile. If
> you want LoadFromFile() to modify the array, you must pass a reference
> to the array. Otherwise, you are only passing the contents of the array:
>
> LoadFromFile(\@workspace, $infile);
>
>> foreach(@workspace) {s/$target/$source/g;}
>> SaveToFile(@workspace,$outfile);
>> }
>> 1;
>
> Note that alternatively, you could provide LoadFromFile a prototype that
> would specify the arguments it needs to receive:
>
> sub LoadFromFile(\@$) {
> #...
> }
>
> This would have the effect of automatically creating a reference to the
> array passed in (so no further changes would be required to either your
> LoadFromFile, nor to ReplaceInFile as you had written it).
>
> Paul Lalli
Oh, I feel like such an idiot. I made a dumb mistake and was looking for a
deep, complicated answer. My only excuse (which is not a good one) is that
C++ spoiled me with its hidden mechanism for converting to and from a
reference if you specify a reference in the parameters, similar to the
prototype you show above. Thanks. Sorry for not thinking clearly here.
wana
------------------------------
Date: Sat, 16 Oct 2004 13:02:17 -0700
From: andrew <arsf10@yahoo.com>
Subject: Finding duplicate sub-expressions in calculator grammar
Message-Id: <pan.2004.10.16.20.02.15.906653@yahoo.com>
i've written a parser in perl for a simple arithmetic grammar
{+,-,*,/,funtion ()} where each operation is potentially expensive to
evaluate. the parser outputs an AST tree that is stored for each of a set
of spreadsheet-like cells that can then be re-evaluated with different
inputs.
currently, if there are expressions like:
(A+B)+f(A+B)
A+B+A+B
the sub-expression A+B gets evaluated more than once when evaluating the
AST tree for that expression. i'd like them to be evaluated only once as
doing A+B can be expensive.
is there a clever way to pre-parse each expression with a regexp to make a
list of identical subexpressions (maybe making a list of expressions with
temporary variables, to be evaluated in succession, like C=A+B, C+f(C))?
can any compiler, like gcc, optimize for this?
andrew.
------------------------------
Date: 16 Oct 2004 20:10:57 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Finding duplicate sub-expressions in calculator grammar
Message-Id: <Xns95849A70130Fcastleamber@130.133.1.4>
andrew wrote:
>
> i've written a parser in perl for a simple arithmetic grammar
> {+,-,*,/,funtion ()} where each operation is potentially expensive to
> evaluate. the parser outputs an AST tree that is stored for each of a
> set of spreadsheet-like cells that can then be re-evaluated with
> different inputs.
>
> currently, if there are expressions like:
>
> (A+B)+f(A+B)
> A+B+A+B
>
> the sub-expression A+B gets evaluated more than once when evaluating
> the AST tree for that expression. i'd like them to be evaluated only
> once as doing A+B can be expensive.
>
> is there a clever way to pre-parse each expression with a regexp to
> make a list of identical subexpressions
if (A+B) == (B+A) holds, regexp is certainly not the way to go.
Parse the expression into a tree and read documentation on common sub
expression elimintation.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Sat, 16 Oct 2004 22:54:06 -0400
From: wana <ioneabu@yahoo.com>
Subject: Is this really legal?
Message-Id: <10n3nsh9nlfeaad@news.supernews.com>
I wrote the following simple statement today which is simple, safe, and
legal:
if (!defined $outfile) {$outfile = $infile;}
I then decided to live dangerously and see if the following would work:
$outfile = $infile if not defined $outfile;
This nearly plain English version seemed to work equally well. I knew that
the if statement could be reversed like this from my reading but I wasn't
sure about leaving out the curlies and the parentheses. I am sure there a
lot of subtle issues of precedence and precise usage rules here, but it's
very cool: I just made up something that made sense in English and it
worked.
This brings to mind an important question:
If something works in Perl, does that mean it's legal?
What I mean is that they say that 1/2 of the code that makes up a web
browser is to correct for errors in html code and such. Does Perl try to
understand what we mean ever even if it's not legal Perl? I heard that
there was an old time language that was known for that and caused a lot of
confusion. If all Perl code that works is legal Perl code, that means that
a lot of questions might be answered simply by experimenting.
Thanks!
wana
------------------------------
Date: Sat, 16 Oct 2004 22:26:39 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Is this really legal?
Message-Id: <slrncn3pjf.gm0.tadmc@magna.augustmail.com>
wana <ioneabu@yahoo.com> wrote:
> I wrote the following simple statement today which is simple, safe, and
> legal:
>
> if (!defined $outfile) {$outfile = $infile;}
>
> I then decided to live dangerously and see if the following would work:
>
> $outfile = $infile if not defined $outfile;
>
> This nearly plain English version seemed to work equally well.
The English can be even plainer:
$outfile = $infile unless defined $outfile;
> This brings to mind an important question:
>
> If something works in Perl, does that mean it's legal?
If perl compiles it with no errors, then it is a Perl program.
> Does Perl try to
> understand what we mean ever
Yes, it is a principle that has come to be called DWIM ("Do What I Mean").
> even if it's not legal Perl?
No, of course not.
If it is not Perl, then perl cannot understand it.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 17 Oct 2004 03:31:22 -0000
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Is this really legal?
Message-Id: <slrncn3pl4.gb9.tim@vegeta.saiyix>
wana <ioneabu@yahoo.com> wrote:
> I wrote the following simple statement today which is simple, safe,
> and legal:
>
> if (!defined $outfile) {$outfile = $infile;}
>
> I then decided to live dangerously and see if the following would
> work:
>
> $outfile = $infile if not defined $outfile;
This is perfectly legal Perl code and is in fact fairly idiomatic.
A Perl Guru might actually write it even more "dangerously":
$outfile = $infile unless defined $outfile;
defined $outfile or $outfile = $infile;
It's even probably that the following would work in your script:
$outfile ||= $infile;
> This nearly plain English version seemed to work equally well.
> I knew that the if statement could be reversed like this from my
> reading but I wasn't sure about leaving out the curlies and the
> parentheses. I am sure there a lot of subtle issues of precedence
> and precise usage rules here, but it's very cool: I just made up
> something that made sense in English and it worked.
The curlies aren't necessary because in this case, the "if" is modifying
a statement, rather than a block. (It is called a "statement modifier",
after all.) Following are the definitions for the two types of
if/unless constructs, all available in perlsyn;
STATEMENT if EXPR;
STATEMENT unless EXPR;
if (EXPR) BLOCK
unless (EXPR) BLOCK
In perl, blocks are enclosed in curly braces. Also notice the
parentheses are explicitly required in the compound if statement.
The are not required in the statement modifier form, but STATEMENT may
be a block if desired. IOW, as you discovered, the parens and braces are
not required for this form.
> This brings to mind an important question:
>
> If something works in Perl, does that mean it's legal?
>
> What I mean is that they say that 1/2 of the code that makes up a web
> browser is to correct for errors in html code and such. Does Perl
> try to understand what we mean ever even if it's not legal Perl?
No. If this were true of perl, the perl would correctly infer the
intent of the C-style "if" construct "if (EXPR) statement;". However,
this causes an error.
However, Perl is designed to be both flexible and intuitive. This is
probably the reason behind your success.
> If all Perl code that works is legal Perl code, that means that a lot
> of questions might be answered simply by experimenting.
You should be experimenting anyway. Anytime you try something
thinking/hoping it will work is another point tallied for Larry and the
other language designers.
HTH,
Tim Hammerquist
------------------------------
Date: 16 Oct 2004 20:46:11 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Is this really legal?
Message-Id: <4171eb03@news.victoria.tc.ca>
wana (ioneabu@yahoo.com) wrote:
: Does Perl try to
: understand what we mean ever even if it's not legal Perl?
No.
However, in perl perhaps more than some other languages, many things are
legal but may not mean quite what you thought they meant.
I suggest experimenting in conjunction with reading the files in your pod
directory. On this computer, the pod files are in
C:\Perl\lib\Pod
though that's just a hint since your files could be almost anywhere,
depending.
use perldoc or a text editor to read them.
e.g.
perldoc perlsyn
e.g.
cd C:\Perl\lib\Pod
edit perlsyn.pod
------------------------------
Date: Sun, 17 Oct 2004 03:58:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Is this really legal?
Message-Id: <J5mcd.4820$232.763@trnddc09>
wana wrote:
> I wrote the following simple statement today which is simple, safe,
> and legal:
>
> if (!defined $outfile) {$outfile = $infile;}
>
> I then decided to live dangerously and see if the following would
> work:
>
> $outfile = $infile if not defined $outfile;
>
> This nearly plain English version seemed to work equally well.
Well, both versions happen to have the same semantic, although they are
totally different concepts.
The first version is a compound statement which requires a block as the
second item.
The second version is a single statement with a statement modifier.
For further details please see "perldoc perlsyn".
It is like quadrupling a number. You can multiply it by 4 or add it 4 times.
Two different ways to achive the same result.
> I
> knew that the if statement could be reversed like this from my
> reading but I wasn't sure about leaving out the curlies and the
> parentheses.
You can leave them out because the two versions are coming from different
lines of thought in the Perl language design and they really don't have much
in common.
> I am sure there a lot of subtle issues of precedence
> and precise usage rules here, but it's very cool: I just made up
> something that made sense in English and it worked.
Even more English would be
$outfile = $infile unless defined $outfile;
> This brings to mind an important question:
>
> If something works in Perl, does that mean it's legal?
Well, neither the CIA nor the KGB will come after you.
What you got up there is perfectly legal Perl code and actually well
documented in the manuals.
> What I mean is that they say that 1/2 of the code that makes up a web
> browser is to correct for errors in html code and such. Does Perl
> try to understand what we mean ever even if it's not legal Perl?
If perl understands it then it's legitimate Perl code. The only exception
would be a bug in perl that makes it parse code that is is not supposed to
parse successfully.
> I
> heard that there was an old time language that was known for that and
> caused a lot of confusion.
One of the design principles was "Do what I mean". In general this has
proven to work very well although occasionally people have been bitten by
perl making the wrong guess.
> If all Perl code that works is legal Perl
> code, that means that a lot of questions might be answered simply by
> experimenting.
Not really. A much better method would be to consult the documentation.
jue
------------------------------
Date: Sat, 16 Oct 2004 22:04:04 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Is this really legal?
Message-Id: <10n3rpkhqjtf59e@corp.supernews.com>
wana wrote:
> a lot of questions might be answered simply by experimenting.
Should that go in the posting guidelines?
Seriously, yes, you are right. And there would be less traffic here if
people learning Perl would try things out before they posted questions here.
------------------------------
Date: 16 Oct 2004 18:23:09 -0700
From: vijai.kalyan@gmail.com (Vijai Kalyan)
Subject: Re: Modified example from Camel book doesn't work right - Please correct
Message-Id: <18b36e50.0410161723.3d4f2d84@posting.google.com>
>
> You missed that the first parameter of split is a RE.
> Using a dot as you are effectively splitting on every single character,
> leaving nothing behind that could be returned by split() as components.
>
> Escaping the dot like in
> @splitstring = split("\.",$string);
> doesn't work eitrher, because the double quotes interpolate the text into a
> single dot which in turn is interpreted as an RE again.
>
> You either have to use
> @splitstring = split("\\.",$string);
> or single quote the single escaped dot
> @splitstring = split('\.',$string);
> or much, much better: if it's used as an RE then type it like an RE
> @splitstring = split(/\./,$string);
> The main advantage is that you are not being fooled into believing the first
> parameter were a plain string.
>
> jue
Ah I see. I guess, I guess the mistake was I tried everything but
lookup the docs for split. I didn't know that split took an regexp but
since I am just starting with perl I doubt I would have seen the
significance immediately.
Thanx for the explanataion.
Regards,
-vijai.
------------------------------
Date: Sun, 17 Oct 2004 03:37:20 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: perl and time
Message-Id: <2te10jF1sfojpU1@uni-berlin.de>
Gunnar Hjalmarsson wrote:
> Drunken Canadian wrote:
>>
>> time A = 00:01:04
>> time b = 0:0:58
>>
>> how can i add the two times to be 00:02:02?
>
> sub addtime {
> my @t1 = split /:/, shift;
> my @t2 = split /:/, shift;
> my $sec = ($t1[0]+$t2[0])*3600 +
> ($t1[1]+$t2[1])*60 + $t1[2]+$t2[2];
> sprintf '%02d:%02d:%02d', (gmtime $sec)[2,1,0]
> }
>
> print addtime('00:01:04', '0:0:58'), "\n";
Or why not shorten the sub to:
sub addtime {
my $sec;
while (@_) {
my @t = reverse split /:/, shift;
$sec += $t[$_]*60**$_ for 0..2;
}
sprintf '%02d:%02d:%02d', (gmtime $sec)[2,1,0]
}
;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 16 Oct 2004 17:22:59 +0200
From: "MM" <dobedidoo@yahoo.se>
Subject: Recursive directory removing?
Message-Id: <n1bcd.6376$1p.5442@nntpserver.swip.net>
Hi,
Can anyone give me some hint on how I in a perl script can remove all
directories, subdirectories, and files (recursively) in a specific directory
that I state? Pretty much like the 'rm -fR' system command, except that I do
not want to use the 'system' command. I looked at the 'unlink' function, but
I could not see how this can be used to remove subdirectories as well.
Many thanks in advance,
MM
------------------------------
Date: Sat, 16 Oct 2004 15:35:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Recursive directory removing?
Message-Id: <9dbcd.1852$n81.1754@trnddc08>
MM wrote:
> Can anyone give me some hint on how I in a perl script can remove all
> directories, subdirectories, and files (recursively) in a specific
> directory that I state?
If you want to do it the hard way:
perldoc File::Find
and do a depth-first pass.
If you want to do it the very hard way
perldoc -f opendir
perldoc -f readdir
perldoc -f -d
If you want to do it the easy way:
perldoc File::Path
> Pretty much like the 'rm -fR' system command,
> except that I do not want to use the 'system' command. I looked at
> the 'unlink' function, but I could not see how this can be used to
> remove subdirectories as well.
perldoc -f rmdir
jue
------------------------------
Date: Sun, 17 Oct 2004 02:46:36 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: String and Array Programming in Perl
Message-Id: <g2lcd.28784$5O5.11043@news-server.bigpond.net.au>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrncn1cot.8vv.tadmc@magna.augustmail.com...
> Peter Wyzl <wyzelli@yahoo.com> wrote:
>> From: "Tad McClellan" <tadmc@augustmail.com>
>>> DeveloperGuy <Phillip.Small@gmail.com> wrote:
>>>
>>>> for ($count= 0; $count <= $#users; $count++;) {
>>>
>>> A more Perlish way to get the same thing is:
>>>
>>> foreach my $count ( 0 .. $#users ) {
>>
>> Even more 'Perlish' would be
>>
>> for my $count (@users){
>
>
> But that doesn't "get the same thing".
>
> (and you wouldn't call it "count" when it wasn't a count)
True, true. I should have pointed out the difference (thanks Jue as well).
In this case the OP _was_ comparing the elements of the arrays, but I should
have stated that difference as 'a more Perlish way to compare array elements
in a foreach loop would be:'
foreach my $element (@array) {
#compare $element with whatever...
}
would make more sense as you point out.
A less than auspicious return to clpm for me it appears... :(
Sorry about the stealth...
/me takes 2 demerits and goes to the back of the class
--
Wyzelli
print map{++$_;y{0-9A-Za-mn-z;}
{0-9A-Za-no-y z;}ds;$_}split '',
reverse 'qdjbzGykqdOyqdgsnmzysrtI';
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7262
***************************************