[18103] in Perl-Users-Digest
Perl-Users Digest, Issue: 263 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 10 00:05:33 2001
Date: Fri, 9 Feb 2001 21:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981781511-v10-i263@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 9 Feb 2001 Volume: 10 Number: 263
Today's topics:
Re: *perl newbie* asking for hash-of-hashes basics <lincwils@teleport.com>
Re: *perl newbie* asking for hash-of-hashes basics <joe+usenet@sunstarsys.com>
Re: Best Way To Split & Initialize <kstep@pepsdesign.com>
Re: Best Way To Split & Initialize (Tad McClellan)
Re: CFP: Yet Another Perl Conference 2001 (Tad McClellan)
chown not allowed <bart.lateur@skynet.be>
copy all files to remoteserver folder <a246456@fmr.com>
Re: Devel DProf and " dprofpp " <godzilla@stomp.stomp.tokyo>
Re: Devel DProf and " dprofpp " (Chris Fedde)
Re: Devel DProf and " dprofpp " <godzilla@stomp.stomp.tokyo>
Re: Free Movie Ticket Give-away for solving the basic p <godzilla@stomp.stomp.tokyo>
Re: General Tool(s) for browsing/editing DB tables? <ron@savage.net.au>
Get all files name in a directory <lxq79@hotmail.com>
Re: Get all files name in a directory (Chris Fedde)
Re: Help! Good Perl Training class recomendation in Sil <nospam@nospam.com>
How to map (undef,undef) to (), but (undef,$y) to (unde <johnlin@chttl.com.tw>
Re: passing in a regex (Tad McClellan)
Re: Perl & Recursion : Why doesn't this work? (Gwyn Judd)
Re: Perl & Recursion : Why doesn't this work? <kstep@pepsdesign.com>
Re: Perl & Recursion : Why doesn't this work? (Abigail)
Re: Perl & Recursion : Why doesn't this work? <vaton@pacbell.net>
Re: Perl & Recursion : Why doesn't this work? <vaton@pacbell.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 9 Feb 2001 18:12:40 -0800
From: "Dennis Wilson" <lincwils@teleport.com>
Subject: Re: *perl newbie* asking for hash-of-hashes basics
Message-Id: <Lp1h6.50$jo.41317@nntp2.onemain.com>
Perl is such a wonderful tool. What you have discovered is that
there is a shorthand for reference notation. Randall Schwarz has explained
it beautifully in some of his articles. I think they are viable on his web
site at stonehenge.com.
If I declare the following:
my %h1 = {}
$h1{'KEY1'} = ( "one" => "uno", "two" => "dos");
I have created a hash of hashes. What is actually stored in $h1{'KEY1'} is a
hash reference. Using the full notation, I would say
print $h1{'KEY1'}->{'one'}, "\n";
The result would be one.
One is allowed to leave out the -> in this situation.
Hope this helps.
Perique des Palottes wrote in message
<3A83D058.CD561DB2@nowhere.noland.etc>...
>Perique des Palottes wrote:
>> ...
>> foreach $key1 (keys $assoc) {
>> foreach $key2 (keys $assoc{$key1}){
>> print $key1." ".$key2." ".$assoc{$key1}{$key2}."\n";
>> }
>> }
>
>Mmm, experimenting, it seems now to make sense to the interpreter,
>and its result makes sense to me...
>
>foreach $key1 (keys %assoc) {
> foreach $key2 (keys %{$assoc{$key1}}){
> print $key1." ".$key2." ".$assoc{$key1}{$key2}."\n";
> }
>}
>
>--
> All true believers shall break their eggs at the convenient end.
------------------------------
Date: 09 Feb 2001 21:32:35 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: *perl newbie* asking for hash-of-hashes basics
Message-Id: <m366ijnu7w.fsf@mumonkan.sunstarsys.com>
"Dennis Wilson" <lincwils@teleport.com> writes:
[please don't post upside down-
put you reply under the cited post. thanks]
> Perl is such a wonderful tool. What you have discovered is that
> there is a shorthand for reference notation. Randall Schwarz has explained
> it beautifully in some of his articles. I think they are viable on his web
> site at stonehenge.com. ^^^^^^
> ^^^^^^
From
http://www.dictionary.com/cgi-bin/dict.pl?term=viable
...
vi·a·ble
adj.
1.Capable of living, developing, or germinating under favorable conditions.
2.Capable of living outside the uterus. Used of a fetus or newborn.
3.Capable of success or continuing effectiveness; practicable: a viable
plan; a viable national economy. See Synonyms at possible.
[French from vie, life, from Old French from Latin vta;
see gwei- in Indo-European Roots.]
...
What a perfect freudian ship!
--
Joe Schaefer "It is dangerous to be sincere unless you are also stupid."
-- George Bernard Shaw
------------------------------
Date: Fri, 9 Feb 2001 21:34:04 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: Best Way To Split & Initialize
Message-Id: <96298n$v4h$1@slb3.atl.mindspring.net>
<redinger@maine.rr.com> wrote in message news:961m3k$l8g$1@nnrp1.deja.com...
> I'm wondering if there are any shortcuts that people use to split and
> initialize a list of values from a file at the same time?
>
> An example follows. My concern is, if one of the fields in the input
> file is empty, split will return undef. I'm wondering if there's a
> shortcut to changing that to '' without going through each field:
> $fld1 ||= ''; $fld2 ||= '', etc.
See perldoc -f map
my $values = 'Value 1|Value 2||Value 4';
my ($fld1, $fld2, $fld3, $fld4) = map {$_ ||= ''} split /\|/, $values ;
print join "\n", $fld1, $fld2, $fld3, $fld4;
HTH,
Kurt Stephens
------------------------------
Date: Sat, 10 Feb 2001 02:54:46 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Best Way To Split & Initialize
Message-Id: <slrn9893la.fon.tadmc@tadmc26.august.net>
redinger@maine.rr.com <redinger@maine.rr.com> wrote:
>
>My concern is, if one of the fields in the input
>file is empty, split will return undef. I'm wondering if there's a
>shortcut to changing that to '' without going through each field:
>My reference example (This code isn't actually meant to be runnable,
^^^^^ ^^^^^^^^^^^^^^^^^^^^
Why not?
>just a representation of an idea. Please excuse any errors):
>
>#!/usr/bin/perl -w
>use strict;
Very good so far.
>open FILE, "my_file";
You should always, yes *always*, check the return value from open():
open FILE, 'my_file' or die "could not open 'my_file' $!";
>while (<FILE>) {
> my ($fld1, $fld2, $fld3, $fld4) = split /\|/;
my ($fld1, $fld2, $fld3, $fld4) = map {defined() ? $_ : ''} split /\|/;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 10 Feb 2001 02:54:47 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: CFP: Yet Another Perl Conference 2001
Message-Id: <slrn98940f.fon.tadmc@tadmc26.august.net>
Terrence Monroe Brannon <terrence.brannon@oracle.com> wrote:
>You have posted spam for your conference in a technical newsgroup.
>Long-standing usenet tradition... [[ blah blah blah s/David Adler's rant on job
>postings/conference post/g ]]]
Please do not quote 230 lines just to add 3 lines of comment,
that can get all of your future articles scored down.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 10 Feb 2001 00:52:23 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: chown not allowed
Message-Id: <7g398ts1ftgpaigghbuvabg663la1bd5nc@4ax.com>
Forgive me if this is an off topic question.
I have, on Un*x, a (read often, update now and then) file which I want
to replace. In order not to spend too much time in locking a file when a
script only want to read it, I use another way to update it: by writing
to a new file, and then renaming that so it replaces the old file. The
advantage is that programs that are currently reading the old file, can
continue to do so, unhindered. So you never get to read an incomplete or
currpted file. You just either get the old file, or the new one. (I
assume that replacing a file by renaming another file to the same name,
is atomic?).
Of course, I still need some locking to make sure only one script
updates the file at the same time.
The problem is in the file permissions and the file ownership. This runs
as a CGI script, so the owner of the new file is "www". Not me. It turns
out that, if I don't watch out, the replacement file cannot be manually
edited or removed by me, the owner of the web site. By chmod'ding the
file so it's writable by anybody, I can take care of that.
But I want the new file to have the same basic properties as the old
file: same file permissions, and the same owner.
How? Perlfunc says for chmod: "On most systems, you are not allowed to
change the ownership of the file unless you're the superuser", which is
precisely my problem. Is there a way around it?
I'd prefer not to first make a copy of the old file, and overwrite the
contents of the copy, and then renaming it to replace the old file.
--
Bart.
------------------------------
Date: Fri, 09 Feb 2001 12:44:43 -0500
From: a246456 <a246456@fmr.com>
Subject: copy all files to remoteserver folder
Message-Id: <3A842C8B.42B1419E@fmr.com>
--------------D164A99AFD751F6681AEE790
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
I wrote a simple script which has to copy all files from my
workstation folder to a remoteserver folder. I am getting a error
message like "The process tried to write to a nonexistent page."
No problem with creating directories. It works if i mention a single
filename to copy instead of all files.
Could you please tell me where i went wrong.
Thanks in advance.
-------------------------------------------------------------------
open(LST, "srv.txt") || die "File does`nt exist:$!\n";
open(RCMDFAIL, ">rcfail.txt") || die "can`t create file $!\n";
chomp($currentserver=<LST>);
while($currentserver ne "") {
print "Connecting to $currentserver....\n";
open(PATH, "rcmd \\\\$currentserver set|"); #it displays NT
environment variables
chomp(@lines=<PATH>);
if (@lines[0] =~/^Error/) #if it cannot connect to server.
{
print RCMDFAIL "$currentserver\n";
}
elsif(@lines[2] =~/^AGENTWORKS_DIR/) #if it matches the
appln path
{
($agent,$dir) = split("=", @lines[2]);
($drv,$pat) = split(":", $dir); #looking for the $drv drive(C
or D or E)
}
open(PACH1, "rcmd \\\\$currentserver md
$drv:\\tng\\patches\\Lo76560|"); #create directory on remote server
open(PACH2, "rcmd \\\\$currentserver md
$drv:\\tng\\patches\\Lo80699|");
open(PACH3, "rcmd \\\\$currentserver md
$drv:\\tng\\patches\\Lo81246|");
open(CMD, "copy \\Lo76560\\*.\*
\\\\$currentserver\\$drv\:\\tng\\patches\\Lo76560|"); #copy all files
from this folder to remote server folder
open(CMD, "copy \\Lo80699\\*.\*
\\\\$currentserver\\$drv\:\\tng\\patches\\Lo80699|");
open(CMD, "copy \\Lo81246\\*.\*
\\\\$currentserver\\$drv\:\\tng\\patches\\Lo81246|");
print "successfully copied all patch files to the folders\n";
$currentserver=<LST>;
}
close PACH1;
close PACH2;
close PACH3;
close LST;
close CMD;
close RCMDFAIL;
--------------D164A99AFD751F6681AEE790
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi,
<p> I wrote a simple script which has to copy all files
from my
<br>workstation folder to a remoteserver folder. I am getting a error
<br>message like "The process tried to write to a nonexistent page."
<p>No problem with creating directories. It works if i mention a single
filename to copy instead of all files.
<br>Could you please tell me where i went wrong.
<p>Thanks in advance.
<br>-------------------------------------------------------------------
<br>open(LST, "srv.txt") || die "File does`nt exist:$!\n";
<br>open(RCMDFAIL, ">rcfail.txt") || die "can`t create file $!\n";
<br> chomp($currentserver=<LST>);
<br> while($currentserver ne "") {
<p> print "Connecting to $currentserver....\n";
<p> open(PATH, "rcmd \\\\$currentserver set|"); #it displays
NT environment variables
<br> chomp(@lines=<PATH>);
<p> if (@lines[0] =~/^Error/) #if it cannot
connect to server.
<br> {
<br> print RCMDFAIL "$currentserver\n";
<br> }
<p> elsif(@lines[2]
=~/^AGENTWORKS_DIR/) #if it matches the appln path
<br> {
<br>
($agent,$dir) = split("=", @lines[2]);
<br> ($drv,$pat) = split(":", $dir);
#looking for the $drv drive(C or D or E)
<br> }
<br>
<br>
<br> open(PACH1, "rcmd \\\\$currentserver md $drv:\\tng\\patches\\Lo76560|");
<b>#create directory on remote server</b>
<br> open(PACH2, "rcmd \\\\$currentserver md $drv:\\tng\\patches\\Lo80699|");
<br> open(PACH3, "rcmd \\\\$currentserver md $drv:\\tng\\patches\\Lo81246|");
<br> open(CMD, "copy \\Lo76560\\*.\* \\\\$currentserver\\$drv\:\\tng\\patches\\Lo76560|");
<b>#copy all files</b>
<br><b>from this folder to remote server folder</b>
<br> open(CMD, "copy \\Lo80699\\*.\* \\\\$currentserver\\$drv\:\\tng\\patches\\Lo80699|");
<br> open(CMD, "copy \\Lo81246\\*.\* \\\\$currentserver\\$drv\:\\tng\\patches\\Lo81246|");
<br> print "successfully copied all patch files to the folders\n";
<br>
<br> $currentserver=<LST>;
<br> }
<br> close PACH1;
<br> close PACH2;
<br> close PACH3;
<br> close LST;
<br> close CMD;
<br> close RCMDFAIL;</html>
--------------D164A99AFD751F6681AEE790--
------------------------------
Date: Fri, 09 Feb 2001 19:26:59 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Devel DProf and " dprofpp "
Message-Id: <3A84B503.BA811086@stomp.stomp.tokyo>
Ben Kennedy wrote:
> Godzilla! wrote:
> > I am not having very good luck with any Perl documentation
> > for DProf, dprofpp and Pod Html. Bothers me a bit to say
> > this, not having completed my testing for fairness. It does
> > appear documentation for all three of those devices is in
> > error. DProf does run and work as it should but its dprofpp
> > feature does not. I am keeping a fairness factor in mind;
> > Perl documentation is so poorly written, it could very well
> > be I cannot correctly decipher these attempts at documentation.
> I just installed the latest .msi package from www.activestate.com, and in a
> cmd box the command "perldoc dprofpp" works fine (I'm not sure what you find
> confusing about it). There is also documentation at "perldoc Devel::DProf".
> If the perldoc command is not working for you, you should consider checking
> your enviromental path variable and/or reinstalling Perl.
Read for comprehension, Mr. Kennedy. This is no longer a problem
with pulling documentation. This is problem with documentation
providing erroroneous syntax for running these programs.
Godzilla!
------------------------------
Date: Sat, 10 Feb 2001 03:52:45 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Devel DProf and " dprofpp "
Message-Id: <hW2h6.5$zN2.188320256@news.frii.net>
In article <3A8454E8.68B6E3B0@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>
>Yes, under Apache. There many good reasons for this and,
>it is clear running scripts under a web server is quite
>superior to running scripts via ActiveState / DOS.
>
I finaly understand why your posted code is always in a CGI wrapper.
That's pretty clever. Congratulations on working out a way of
surviving under windows.
Even in your mode of working though a more powerful command line
might be of some use. If you are a Unix fan of any kind you might
be attracted by the cygwin port of bash:
http://sources.redhat.com/cygwin/
On the other hand there are several command.com extensions that
give you a degree of editing capability and command history. One
of the most simple that appears to still ship with windows is
doskey:
c:> doskey
From that point on the up and down arrow keys will scroll through
previous commands.
YMMV
chris
--
This space intentionally left blank
------------------------------
Date: Fri, 09 Feb 2001 20:16:23 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Devel DProf and " dprofpp "
Message-Id: <3A84C097.79A45CC9@stomp.stomp.tokyo>
Chris Fedde wrote:
> Godzilla! wrote:
> >Yes, under Apache. There many good reasons for this and,
> >it is clear running scripts under a web server is quite
> >superior to running scripts via ActiveState / DOS.
> I finaly understand why your posted code is always in a CGI wrapper.
> That's pretty clever. Congratulations on working out a way of
> surviving under windows.
It isn't really surviving under Windows. It is developing
the greatest potential of Windows. I will share something
of a personal nature. I am a hard core fan of Dos 6.x and
Win 3.1 interface. I still have an IBM sitting here next
to my new system. This old IBM 486 is a gigantic paper
weight really, which runs DOS 6.x and Win 3.1. Although
it is slow and is not rich in features, it is an extremely
powerful system. Win 3.x is easily modified and programmed.
DOS 6.x allows you to do 'stuff' you cannot do with this
new DOS / Win 9.x system.
Anyhow, my years of experience with early DOS and
the first release of Deskmate and Windows, has taught
me how to extract the most out of Windows. This Win 9.x
is not too bad of a system, once you learn what Gates
would rather you not know.
> Even in your mode of working though a more powerful command line
> might be of some use. If you are a Unix fan of any kind you might
> be attracted by the cygwin port of bash:
> http://sources.redhat.com/cygwin/
> On the other hand there are several command.com extensions that
> give you a degree of editing capability and command history. One
> of the most simple that appears to still ship with windows is
> doskey:
> c:> doskey
> From that point on the up and down arrow keys will scroll through
> previous commands.
Yes, there are some lingering functions from DOS 6.x which are nice.
Nonetheless, this new DOS isn't new; it is a stripped down, less
powerful version. Stereotypically, I am not a patient woman. Suppose
this is related to being an English teacher for so many years. I also
expect clean crisp easy-to-read text. Using a browser interface for
interaction with Perl, affords me a layout which is comfortable. It
also affords me speed in script development, satiating my lack of
patience and, helps to prevent me from beating my computer with
my deadly kitchen spatula.
Not long back, I had ActiveState Perl installed but have since
removed it. At times, I became so frustrated with a lack of scroll,
a need to constantly retype commands and parameters, having to
jump through hoops to save data results to a file, I would begin
cussing much like a drunken sailor in a Tijuana bar. My daughter
doesn't allow me to do this and often sent me to my room for
quiet time as punishment. ActiveState had to go; in time, my
girl threatened to take away my credit cards and my 'Vette keys.
Godzilla!
------------------------------
Date: Fri, 09 Feb 2001 19:18:23 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Free Movie Ticket Give-away for solving the basic problem on Time:HiRes.pm module
Message-Id: <3A84B2FF.6C653C50@stomp.stomp.tokyo>
Carmari wrote:
> I am writing a TIMER program with HiResolution requirement. Basically, we
> can get 4.34 double precision seconds from timeofday function ( from
> TIME::HiRes) . However, I got problem on the very simple implementation.
> Here is the detail:
> Please read and let me know what is the problem. Thank you. I will send you
> a free movie ticket as reward. Promise!!!
Your problem is you forgot to include the details.
Keep the ticket. We are exhibitionists and put on
a better show than any movie. Wanna free ticket?
Godzilla!
--
$Ø = "24S4E2S7E¿18S24E¿15S4E3C25E¿13S4E6C28E¿12S2E8C3E3C25E¿10S8E
4C1E11C20E¿8S3E1S1E2C6E18C11E3S3E¿11S2E4C8E4C1E10C11E4S1E¿9S18E1C
1E11C13E¿8S20E12C15E¿8S22E9C17E¿9S22E7C19E¿8S16E2C5E6C21E¿6S17E3C
5E5C16E3S4E¿5S17E3C5E4C1E2C16E4S2E¿4S17E3C4E5C1E11C8E4S1E¿3S17E4C
2E6C1E1C1E11C9E¿2S19E3C1E6C1E2C3E8C11E7S1E¿2S2E3S10E2C2E4C1E4C1E1
3C15E1S4E¿1S2E2S11E3C1E9C1E10C1E2C2E1C17E¿1S1E2S13E11C1E2C9E4C18E
¿2S11E1C3E10C1E5C5E5C18E¿1S10E4C2E9C3E13C21E¿10E5C1E9C6E9C24E¿9E5
C1E9C30E3S8E¿6E1S1E15C10E7C16E3S7E¿4E3S1E14C12E6C17E4S5E¿1S3E3S1E
13C15E5C17E4S4E¿2S3E2S1E12C5E1C12E4C1E2C7E1S6E3S4E¿3S2E2S1E12C4E1
C17E6C3E3S5E3S3E¿3S2E2S1E10C5E2C5E2C12E7C7E4S2E¿3S1E3S2E8C5E3C4E5
C12E8C3E5S1E¿7S2E7C5E5C3E7C2E3C7E8C2E4S1E¿6S4E5C5E7C2E8C1E5C6E3C1
E5C1E¿5S5E5C5E8C1E11C1E4C4E4C1E4C1E¿4S6E5C2E1C1E10C1E11C1E3C4E6C1
E2C1E¿3S2E1S5E3C3E1C1E23C1E1C4E9C1E1C¿3S1E1S6E3C2E2C1E23C2E1C2E12
C1E¿5S6E3C2E2C1E10C4E10C1E1C2E14C1E¿4S7E3C2E2C1E9C6E9C1E2C2E14C1E
¿4S8E2C2E2C2E8C6E9C1E3C1E14C2E¿4S5E2S1E3C1E2C2E9C4E10C1E17C4E¿4S4
E3S2E6C2E21C2E17C4E¿5S3E4S1E7C2E19C2E2C1E16C2E¿5S3E4S2E7C3E16C2E3
C2E15C1E¿6S2E5S1E8C4E11C4E5C2E12C2E¿7S2E4S2E9C15E8C3E8C3E¿8S2E4S2
E12C7E14C10E¿9S2E3S3E34C6E¿10S1E3S4E22C1E3C1E8C2E¿14S5E18C2E6C2E6
C2E¿13S7E15C3E7C2E5C2E¿13S8E13C3E9C3E3C1E¿12S10E11C3E11C2E3C1E¿11
S2E1S8E9C3E14C1E3C1E¿11S1E2S6E1S1E7C2E17C1E3C1E1C¿14S6E1S1E6C1E19
C1E3C2E¿13S6E2S1E5C1E24C1E1C1E¿13S6E2S1E5C1E9C1E14C1E2C1E¿13S5E3S
1E14C2E15C1E2C1E¿12S5E3S1E14C3E16C1E2C1E¿11S5E3S1E15C2E18C1E2C1E¿
10S5E3S1E5C1E10C1E10C2E7C1E3C1E¿10S4E3S1E5C1E23C2E7C1E3C1E¿9S4E3S
1E5C1E23C3E8C1E3C1E¿8S3E4S1E5C2E22C3E9C1E4C1E¿6S4E4S2E4C2E21C4E9C
1E2C1E3C1E¿5S3E6S1E5C1E20C3E12C1E2C2E3C1E¿2S4E7S2E25C2E13C2E2C2E3
C1E1C¿13S1E25C1E15C2E2C2E3C2E¿12S2E6C1E35C1E2C2E3C2E¿12S1E8C1E35C
1E2C1E3C2E¿11S2E9C1E13C1E21C1E1C1E3C2E¿11S1E11C3E9C1E23C2E2C3E¿11
S1E12C11E24C2E2C2E¿11S1E13C9E25C1E2C2E¿11S1E14C7E25C1E2C2E¿11S1E1
5C6E25C1E1C2E¿11S1E17C3E26C3E¿11S1E19C1E26C3E¿11S2E17C1E26C3E¿12S
1E17C1E26C3E¿12S2E15C1E26C3E¿13S1E15C1E25C3E¿13S2E13C1E25C3E¿14S1
E13C1E24C3E¿14S2E11C1E24C3E¿15S1E11C1E23C3E¿15S2E9C1E23C3E¿16S1E9
C1E22C3E¿16S2E7C1E22C3E¿17S2E6C1E21C3E¿17S2E5C1E21C3E¿18S2E4C1E20
C3E¿18S2E3C1E20C3E¿19S2E2C1E19C3E¿19S2E1C1E19C3E¿20S3E18C3E¿20S2E
18C3E¿21S1E17C3E¿20S2E16C3E¿20S2E15C3E¿20S2E4C1E9C3E1C¿20S3E4C2E7
C4E¿21S3E11C3E1C1E¿21S3E3C1E7C1E1C1E1C1E¿22S2E2C4E7C1E1C1E¿22S2E2
C3E8C1E1C1E¿22S3E2C2E8C1E1C1E¿23S2E2C2E9C1E1C1E¿23S2E2C2E10C1E1C1
E¿23S2E3C1E11C2E¿23S3E15C1E1C¿23S3E15C1E1C¿23S3E16C1E¿23S3E16C1E¿
23S3E16C2E¿24S2E16C2E¿24S3E15C2E¿24S3E15C2E¿24S3E15C2E¿24S3E15C2E
¿25S2E14C3E¿25S3E13C2E¿25S3E13C2E¿25S3E12C2E¿26S2E12C2E¿26S2E12C2
E¿26S2E11C2E¿26S3E10C2E¿26S3E10C2E¿27S2E9C2E¿27S3E8C2E¿27S3E8C2E¿
28S2E8C2E¿28S3E6C2E¿28S3E6C2E¿29S2E6C2E¿29S2E6C2E¿30S2E5C2E¿30S2E
5C2E¿30S2E5C1E¿30S2E5C1E¿30S2E6C1E¿29S1E1C1E7C1E¿28S1E3C1E6C1E¿27
S1E4C1E6C1E¿26S1E5C1E7C1E¿25S1E6C2E7C1E¿25S1E7C1E8C1E¿25S2E1C1E4C
1E9C1E¿25S1E1C1E1C1E3C1E10C1E¿25S2E1C1E1C1E2C1E8C1E1C1E¿26S2E1C1E
2C2E7C1E1C2E¿27S2E2C3E6C1E1C1E1C1E¿28S4E1S2E4C1E1C1E1C2E¿34S2E4C1
E1C2E¿35S2E4C2E¿36S2E2C2E¿37S4E";$Ø=~tr/\n//d;@©=split(/¿/,$Ø);
foreach$§(@©){$§=~s/(\d)([^\d])/$1:$2/g;$§=~s/([^\d])(\d)/$1 $2/g;
@®=split(/ /, $§);foreach$¶(@®){($¢,$¡)=split(/:/, $¶);if($¡eq"C")
{print":"x$¢;}if($¡eq"E"){print"8"x$¢;}if($¡eq"S"){print" "x$¢;}}
print"\n";}print"\n\n"," "x32,"Godzilla Rocks!";exit;
------------------------------
Date: Sat, 10 Feb 2001 14:13:36 +1100
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: General Tool(s) for browsing/editing DB tables?
Message-Id: <lu1h6.1067$FU5.34393@ozemail.com.au>
My Perl tool for MySQL is at: http://savage.net.au/Perl.html#myadmin.pl
Different versions of Perl have different ideas about what is or is not
tainted, which affects the backup option of my program.
A color-coded diff between 2 tables, eg the 'same' table on 2 servers, is
here: http://savage.net.au/Perl-tutorials.html#tut-26
Or try the competition: http://www.dajoba.com/projects/mysqltool/index.html
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
------------------------------
Date: Sat, 10 Feb 2001 13:36:34 +0900
From: LXQ <lxq79@hotmail.com>
Subject: Get all files name in a directory
Message-Id: <20010210133634.1ca34428.lxq79@hotmail.com>
Hello,
I'm trying to make a script that will change the word in a file for me.
When I run this script in a directory say: /home/bk/ it will check all the
file in there, and change the word $old_word to $new_word in every file in
that directory. I tried using -p option for Perl, but that made me had to
type all the filename I want to change as arguments. How can I do this
automatically? Thanks so much ^_^
------------------------------
Date: Sat, 10 Feb 2001 04:49:28 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Get all files name in a directory
Message-Id: <sL3h6.6$zN2.188617728@news.frii.net>
In article <20010210133634.1ca34428.lxq79@hotmail.com>,
LXQ <lxq79@hotmail.com> wrote:
>Hello,
>
>I'm trying to make a script that will change the word in a file for me.
>When I run this script in a directory say: /home/bk/ it will check all the
>file in there, and change the word $old_word to $new_word in every file in
>that directory. I tried using -p option for Perl, but that made me had to
>type all the filename I want to change as arguments. How can I do this
>automatically? Thanks so much ^_^
I'll guess that from the direction of your slashes you are running on unix
of some kind.
perl -p -i.bak -e '/oldword/newword/g' /home/bk/*
When this gets done trashing your files you can at least recover from the
damage by moving the .bak files to their original names.
chris
--
This space intentionally left blank
------------------------------
Date: 10 Feb 2001 02:23:42 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: Help! Good Perl Training class recomendation in Silicon Valley needed!
Message-Id: <9628ne$8cm$2@216.155.32.222>
In article <3A831E11.8513C24D@oracle.com>, Terrence Monroe Brannon
<terrence.brannon@oracle.com> wrote:
| Maybe you should consult the Silicon Valley Perl mongers. I'm sure they
| would know of some good resources.
on a similar note, where would I look for similar resources here in
Delaware, USA? Is there a website that lists such things by area?
--
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw";
# ( damn spammers. *shakes fist* take a hint. =:P )
------------------------------
Date: Sat, 10 Feb 2001 12:24:25 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: How to map (undef,undef) to (), but (undef,$y) to (undef,$y)?
Message-Id: <962fsr$h9o@netnews.hinet.net>
Dear all,
Today I found a bug in my program:
sub foo {
# some query here
my($x,$y) = (undef,undef); # got undef results after query
return map { if(defined) { s/^\s+//; s/\s+$// } $_ } ($x,$y);
}
if(my $found = my($x,$y) = foo) { print "found: $x,$y" }
else { print "not found" }
I didn't notice that if the query in foo() returns (undef,undef)
I still got $found == 2, not $found == 0.
To get rid of the bug, I have to modify the original return map {...}
which was used to trim the leading and trailing spaces of the result.
I found I couldn't write such a map to get all the possible results:
($x,$y) or ($x,undef) # ($x) is also OK # or (undef,$y)
or () # instead of (undef,undef), because I want to make $found==0
Can you help me?
Thank you very much.
John Lin
------------------------------
Date: Sat, 10 Feb 2001 02:54:45 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: passing in a regex
Message-Id: <slrn9890ro.fon.tadmc@tadmc26.august.net>
[ Please put your comments *following* the quoted text that you
are commenting on.
Please do not quote an entire article.
Please do now quote .sigs.
Jeopardectomy performed.
]
ericr@yankthechain.com <ericr@yankthechain.com> wrote:
>In article <961gee$fmc$1@nnrp1.deja.com>,
> aramis1631@my-deja.com wrote:
>> In article <961eb1$do9$1@nnrp1.deja.com>,
>> ericr@yankthechain.com wrote:
>> > Let's say I want to do something like this:
>> >
>> > my $regex = shift;
>> > $string =~ $regex;
>> >
>> > passing the entire regular expression in as a variable. Obviously
>the
>> > above example itself doesn't work, but what will?
>>
>> I do it like this...
>>
>> $string =~ /$regex/;
>I'm talking about being able to pass in a whole regex, like s/\n|\s//g
No you're not.
If you're talking about passing "s/\n|\s//g", then you are NOT
passing a regex. The "\n|\s" is a regex. What you suggest
passing is not a regex, it is an operator, eval() it and tremble.
The s/// operator has a regex in the first part, but the second
part and the delimiters and the options are not part of a regex.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 10 Feb 2001 02:11:29 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Perl & Recursion : Why doesn't this work?
Message-Id: <slrn9898qg.8ar.tjla@thislove.dyndns.org>
I was shocked! How could Robert Shockley <vaton@pacbell.net>
say such a terrible thing:
>I am new to Perl and having problems with recursive routines in Perl.
>The following
>code produces a 0 instead of 720, as it should, on input 6:
>
>sub factorial{
> $number = shift @_;
> return 1 if $number == 0;
> return ( $number * factorial( $number - 1 ) );
>}
>print factorial(6) . "\n";
The reason why the version in C works while the Perl version does not is
because the variable "number" in the C version is a local variable,
whereas the variable "$number" in the Perl version is a global variable.
If you print out the value of $number both before and after you make the
recursive call you will see what happens to the value. To fix this you
need to declare $number as being local to the enclosing function using
the my() function (not the confusingly named local() function).
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
How much does it cost to entice a dope-smoking UNIX system guru to Dayton?
-- Brian Boyle, UNIX/WORLD's First Annual Salary Survey
------------------------------
Date: Fri, 9 Feb 2001 21:14:14 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: Perl & Recursion : Why doesn't this work?
Message-Id: <96285f$clj$1@slb0.atl.mindspring.net>
"Robert Shockley" <vaton@pacbell.net> wrote in message
news:3A849E92.5B7FD9C3@pacbell.net...
> I am new to Perl and having problems with recursive routines in Perl.
> The following
> code produces a 0 instead of 720, as it should, on input 6:
>
> sub factorial{
> $number = shift @_;
> return 1 if $number == 0;
> return ( $number * factorial( $number - 1 ) );
> }
> print factorial(6) . "\n";
This is a scoping issue - if you were using 'strict' then perl would have
caught the problem for you. In your code, $number is a dynamic (global)
variable. During the course of recursion you decrement $number until it
reaches 1. At this point, calling factorial($number-1) sets $number to zero
($number = shift @_;). As the recursion unzips, return ( $number *
factorial($number-1)) correctly returns zero - remember when you set $number
to zero?
If you declare $number as a lexical variable using my(), the problem
magically goes away. Now $number is lexically scoped to within sub
factorial() and the recursion works as intended.
Lesson: Always use strict. Always declare variables using my() unless
there is a really good reason to use local() or 'use vars' instead.
Laziness excluded ;-)
HTH
Kurt Stephens
------------------------------
Date: 10 Feb 2001 02:14:46 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Perl & Recursion : Why doesn't this work?
Message-Id: <slrn98990m.doc.abigail@tsathoggua.rlyeh.net>
Robert Shockley (vaton@pacbell.net) wrote on MMDCCXX September MCMXCIII
in <URL:news:3A849E92.5B7FD9C3@pacbell.net>:
}} I am new to Perl and having problems with recursive routines in Perl.
}} The following
}} code produces a 0 instead of 720, as it should, on input 6:
}}
}} sub factorial{
}} $number = shift @_;
}} return 1 if $number == 0;
}} return ( $number * factorial( $number - 1 ) );
}} }
}} print factorial(6) . "\n";
}}
}} The same algorithm in C works fine (I know - Perl ain't C):
}}
}} #include <stdio.h>
}} int factorial(int number){
}} if(number == 0)
}} return 1;
}} else
}} return ( number * factorial( number - 1 ) );
}} }
}}
}} void main(){
}} int c;
}} printf("%d\n",factorial(6));
}} c = getchar();
}} }
But that *isn't* the same algorithm. This is the same algorithm in C:
#include <stdio.h>
int number;
int factorial(int n){
number = n;
if(number == 0)
return 1;
else
return ( number * factorial( number - 1 ) );
}
void main(){
int c;
printf("%d\n",factorial(6));
c = getchar();
}
And that prints 0 too.
Note the subtle difference.
You are using a global variable to as a scratch variable, modifying it
in recursion, then using it after the recursion returns as if it was
unchanged.
This is be the equivalent of your C code:
sub factorial{
return 1 if $_ [0] == 0;
return ( $_ [0] * factorial( $_ [0] - 1 ) );
}
print factorial(6) . "\n";
And that prints 720.
If you are going to use a variable $number, you should my() (or, technically,
local() is an option too, but you'll prefer my()) it.
See also 'man perlsub'.
Abigail
--
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_=sub{print/::(.*)/};
$\=$/;q<Just another Perl Hacker>->();
------------------------------
Date: Fri, 09 Feb 2001 18:36:36 -0800
From: Beto Recluta <vaton@pacbell.net>
Subject: Re: Perl & Recursion : Why doesn't this work?
Message-Id: <3A84A934.5FF26B6C@pacbell.net>
Yep, that was it. Thanks a lot. I still have to unlearn C.
Dennis Wilson wrote:
> Try using the pragmas strict and warnings with this code.
> They should be place right after the shebang if you are on unix
> otherwise on lines 1 and 2.
>
> Do that before you read the rest, please.
>
> Variables are global by default in perl. Without my to make it local your
> $number variable is global and that affects the result.
>
> Robert Shockley wrote in message <3A849E92.5B7FD9C3@pacbell.net>...
> >I am new to Perl and having problems with recursive routines in Perl.
> >The following
> >code produces a 0 instead of 720, as it should, on input 6:
> >
> >sub factorial{
> > $number = shift @_;
> > return 1 if $number == 0;
> > return ( $number * factorial( $number - 1 ) );
> >}
> >print factorial(6) . "\n";
> >
> >The same algorithm in C works fine (I know - Perl ain't C):
> >
> >#include <stdio.h>
> >int factorial(int number){
> > if(number == 0)
> > return 1;
> > else
> > return ( number * factorial( number - 1 ) );
> >}
> >
> >void main(){
> > int c;
> > printf("%d\n",factorial(6));
> > c = getchar();
> >}
> >
------------------------------
Date: Fri, 09 Feb 2001 18:38:22 -0800
From: Beto Recluta <vaton@pacbell.net>
Subject: Re: Perl & Recursion : Why doesn't this work?
Message-Id: <3A84A99E.63806B03@pacbell.net>
Thank you That did it. C still plagues me.
Gwyn Judd wrote:
------------------------------
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 263
**************************************