[10725] in Perl-Users-Digest
Perl-Users Digest, Issue: 4324 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 30 13:07:20 1998
Date: Mon, 30 Nov 98 10:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 30 Nov 1998 Volume: 8 Number: 4324
Today's topics:
Re: changing '@INC' at runtime (Tad McClellan)
Checking site status <norman.bunn@mci.com>
Re: Checking site status (Greg Ward)
Date file created check? <stepherd@gusun.georgetown.edu>
Re: Date file created check? (Greg Ward)
Re: debugging forks <rootbeer@teleport.com>
Re: Difficult Pattern Matching <erik@cthulhu.demon.nl>
Re: Directory? (Tad McClellan)
Re: embedded while loop problem <maurerf@post.ch>
Re: embedded while loop problem (Tad McClellan)
Re: embedded while loop problem (Tad McClellan)
Encryption email@address.com
Re: Folder Recurison <Tony.Curtis+usenet@vcpc.univie.ac.at>
Re: Folder Recurison <luoni@gol.com>
Re: Globbing don't work thycotic@my-dejanews.com
GuestBook on NT with Blat TimesOnLine@my-dejanews.com
GuestBook on NT with Blat TimesOnLine@my-dejanews.com
Re: Help -- remove white spaces from end of a string (Peter J. Kernan)
Re: How to determine if child process is dead? <rootbeer@teleport.com>
Re: Open or Create a file <rootbeer@teleport.com>
perl Tk dturley@pobox.com
Re: Please help me solve three CGI problem: Make Dir, C (Tad McClellan)
Re: PROPOSAL: XML based Make for C++, Perl, Python, Ja (Tad McClellan)
Re: RegExp and Authentication Help. (Tad McClellan)
single quote problems <gary.ennis@strath.ac.uk>
Re: string match (Tad McClellan)
Re: support for the Kermit protocol? <rootbeer@teleport.com>
Re: to dbm or not to dbm? <rootbeer@teleport.com>
Re: variables in substitutions (Tad McClellan)
Re: variables in substitutions (Tad McClellan)
When does CLOSE not FLUSH? <cgormley@netcomuk.co.uk>
Re: Writing to password protected directory <dan@clockwork.net>
Re: Y2K and Programmer Denial (Leslie Mikesell)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 30 Nov 1998 10:48:50 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: changing '@INC' at runtime
Message-Id: <i9iu37.kev.ln@flash.net>
Girish Deodhar (girishd@gsslco.co.in) wrote:
: i have the perl modules in a directory
: which is not there in @INC
: to fix this i 'push' the directory name
: onto @INC and then 'use' the required
: module.
: but this doesn't seem to work
see the recent thread:
Subject: Using a variable as an argument to use lib
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 Nov 1998 17:18:41 GMT
From: "Norman Bunn" <norman.bunn@mci.com>
Subject: Checking site status
Message-Id: <RrA82.24333$8G5.7196@news.cwix.com>
I need to check whether certain web sites and FTP servers are up on a
regular basis. Any thoughts on the "best" approach to take with Perl?
Norman
------------------------------
Date: 30 Nov 1998 17:57:31 GMT
From: gward@thrak.cnri.reston.va.us (Greg Ward)
Subject: Re: Checking site status
Message-Id: <73umab$muq$2@news0-alterdial.uu.net>
On Mon, 30 Nov 1998 17:18:41 GMT, Norman Bunn <norman.bunn@mci.com> wrote:
>I need to check whether certain web sites and FTP servers are up on a
>regular basis. Any thoughts on the "best" approach to take with Perl?
Depends what you mean by "up". If you mean "machine is on, running, and
connected to the net" then Net::Ping should do what you want. If you
mean "machine is on, running, connected to the net, and answering
connections on its http/ftp port", then you should look into
libwww-perl. Count on 3-6 hours of learning plus about 20 minutes of
coding. Should be doable inside of 20 lines, unless you want really
detailed reporting on the state of the servers you're poking at.
Now, if "up" means "machine is on, running, connected to the net,
answering connections on appropriate port, and serving the content that
I expect it to be serving"... well, that's an exercise left to the
reader. Would probably take more than 20 lines, but again libwww-perl
is definitely your friend.
(Also, this would be a really cool excuse to try out multithreaded Perl
-- just launch a thread for each attempt to connect. If you expect lots
of long delays -- from lots of down servers -- this should really help
your running time.)
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: Mon, 30 Nov 1998 11:52:08 -0500
From: Dave Stephens <stepherd@gusun.georgetown.edu>
Subject: Date file created check?
Message-Id: <3662CD38.605C7191@gusun.georgetown.edu>
Hi,
Is there any way to do a check on the date a file was created?
For example:
if (-e "whatever.txt")
{
print "YEP";
}
Returns YEP if the file exists. Is there anything that will return the
date whatever.txt was created on?
Thanks,
Dave Stephens
stepherd@gusun.georgetown.edu
------------------------------
Date: 30 Nov 1998 17:52:05 GMT
From: gward@thrak.cnri.reston.va.us (Greg Ward)
Subject: Re: Date file created check?
Message-Id: <73um05$muq$1@news0-alterdial.uu.net>
On Mon, 30 Nov 1998, Dave Stephens <stepherd@gusun.georgetown.edu> wrote:
> Hi,
>
>Is there any way to do a check on the date a file was created?
You forgot to tell which OS you're using. Under Unix, the answer is
no. Unix stores three times about a file: the last modification time,
which is the one you look at 99% of the time, the last access time, and
the time when the inode was last updated. This last one causes a lot of
confusion, because very often the inode was last updated when the file
was created -- thus, people who just mess around and don't actually
bother to read documentation often think that it is the file creation
time. Alas, it isn't; that information is not available through the
standard Unix filesystem interface.
FYI: "inode modification" includes things like changing the group or
user id of the file, or changing its mode. I think that updating the
access or modification time with utime(2) also updates the inode.
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: Mon, 30 Nov 1998 17:45:13 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: debugging forks
Message-Id: <Pine.GSO.4.02A.9811300935480.26619-100000@user2.teleport.com>
On Mon, 30 Nov 1998, TS wrote:
> So, is there a way of debugging the child code under 5.004_04?
If I understand your situation correctly, yes. Here's one way. Do
something like this with your fork code.
my $pid = fork;
die "Can't fork: $!" unless defined $pid;
$DB::single = 1 unless $pid; # Stop child in the debugger
....
When the debugger is active, the parent will keep running, but the child
will drop to the debugger prompt after that last line. Of course, if the
parent is (say) going to time out while waiting for the child, you'll have
other things you'll need to do to be able to debug this. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 30 Nov 1998 12:44:49 +0100
From: Erik van Roode <erik@cthulhu.demon.nl>
Subject: Re: Difficult Pattern Matching
Message-Id: <36628531.B44A784D@cthulhu.demon.nl>
Scott Brumley wrote:
>
> I want to do a pattern match on the common spam flag "$$$" However since
> the $ character is an special anchor character I am having difficulty. I
> thought I could use \$\$\$ but it does not seem to work either.
After solving this problem, I have an interesting followup assignment:
- write a script that does pattern matching to filter out duplicate
messages (with possible different subject)
Erik
------------------------------
Date: Mon, 30 Nov 1998 10:50:55 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Directory?
Message-Id: <fdiu37.kev.ln@flash.net>
Mario Luoni (luoni@gol.com) wrote:
: Has anybody encountered the problem that Perl considers something not to be
: a directory, although it is one? I check with
: if (-d $name) {...}
: but the result of the test is just wrong (not: false). I cannot imagine this
: to be a bug of the Perl implementation,
Me either.
: neither one of the script I wrote.
That seems a rather bold statement...
: I'm pretty much lost. Can anybody help.
We cannot (usually) troubleshoot code we cannot see...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 Nov 1998 17:34:46 +0100
From: "Felix Maurer" <maurerf@post.ch>
Subject: Re: embedded while loop problem
Message-Id: <73uhhk$2m1@gd2inews.swissptt.ch>
After fixing the final typing errors, I were able to make my program running
successfully, and there some real speed increase. Thanks to all who helped:
@x500=sort <X500>;
while (<INFILE>) {
chomp;
($key,$rest) = split/;/,$_,2;
@fields = split/;/,$rest;
$HoL{$key} = [@fields];
}
LINE: foreach $x500(@x500) {
chomp $x500;
$uid=substr($x500,26,12);
$uid=~s/ //g;
$oe=substr($x500,332,40);
$surname=substr($x500,162,40);
$surname=~s/ //g;
$givenname=substr($x500,242,40);
$givenname=~s/ //g;
foreach $key ( keys %HoL) {
if ($uid eq $key) {
print ($key,";",
@{$HoL{$key}},
$surname,";",
$givenname,";",
$oe,"\n");
next LINE;
}
}
}
__END__
------------------------------
Date: Mon, 30 Nov 1998 11:42:32 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: embedded while loop problem
Message-Id: <8elu37.4sv.ln@flash.net>
Felix Maurer (maurerf@post.ch) wrote:
: As suggested in second reply, I'm still wanting to add some more speed by
: using a hash table, but at the moment I'm not able to make the example in
: the book running:
^^^^^^^^
^^^^^^^^ which book?
: while (<INFILE>) {
: chomp;
: ($key,$rest) = split/;/,$_,2;
: @fields = split/;/,$rest;
: $HoL{$key}[@fields];
: }
: foreach $key ( keys %HoL) {
: print "$key: @{$Hol->{$key}[0]}\n";
: }
: The key is printed ok but not the content (the other fields are empty?
: Any hint on this one?
------------------------
#!/usr/bin/perl -w
while (<DATA>) {
chomp;
($key, @fields) = split/;/;
$HoL{$key} = [@fields];
}
foreach $key ( keys %HoL) {
print "$key: @{$HoL{$key}}\n"; # print all array elements
print "$key: $HoL{$key}[0]\n"; # print only first array element
}
__DATA__
key1;val1-1;val1-2;val1-3
key2;val2-1;val2-2
key3;val3-1;val3-2;val3-3;val3-4
------------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 Nov 1998 11:39:45 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: embedded while loop problem
Message-Id: <19lu37.4sv.ln@flash.net>
Eric Bohlman (ebohlman@netcom.com) wrote:
: Felix Maurer <maurerf@post.ch> wrote:
: : As suggested in second reply, I'm still wanting to add some more speed by
: : using a hash table, but at the moment I'm not able to make the example in
: : the book running:
: : while (<INFILE>) {
: : chomp;
: : ($key,$rest) = split/;/,$_,2;
: : @fields = split/;/,$rest;
: The above two lines could more efficiently be written as:
: ($key,$rest,@fields) = split /;/;
^^^^^^
s/\$rest,//; # unless you want to discard the second field ;-)
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 Nov 1998 15:51:06 GMT
From: email@address.com
Subject: Encryption
Message-Id: <3662bb57.41085051@news-server.amherst.edu>
Is there an easy way to encrypt a string and decrypt it back? The man
page didn't seem to help me much.
Thanks.
------------------------------
Date: 30 Nov 1998 17:24:27 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: Folder Recurison
Message-Id: <83yaoti1xg.fsf@vcpc.univie.ac.at>
Re: Folder Recurison, Richard <rippoXXXX@kc3.co.uk> said:
Richard> How can I get a list of all files into a @FILES
Richard> array from a base driectory INCLUDING all
Richard> sub-directories.
perldoc File::Find
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds! | private email:
Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>
------------------------------
Date: Mon, 30 Nov 1998 17:30:39 +0100
From: "Mario Luoni" <luoni@gol.com>
Subject: Re: Folder Recurison
Message-Id: <73uh7s$2bq@gd2inews.swissptt.ch>
call the following subroutine with the top folder's SINGLE-QUOTED name as an
argument. The complete file paths are included.
sub scan {
my $path = @_[0];
if (!opendir(INDIR, "$path")) {
push(@FILES,$path);
return;
}
my @localfiles = readdir(INDIR);
closedir(INDIR);
foreach my $file (@localfiles) {
next if $file=~/^\./;
scan( "$path\\$file" );
}
return 0;
}
-Mario
Richard Wilde wrote in message <3662C06B.74AD@kc3.co.uk>...
>How can I get a list of all files into a @FILES array from a base
>driectory INCLUDING all sub-directories.
>
>I have tried various methods and can only get the files from one
>dirctory down from the sub directory. For example:
>
>|BaseDIR
>|--->dir1 OK
>|--->dir2 OK
>|--->dir3 OK
> |--->dir4 NO
>
>
>Any help will be appreciated
>
>
>Email rippoXXXX@kc3.co.uk
>Remove XXXX from email
------------------------------
Date: Mon, 30 Nov 1998 15:47:25 GMT
From: thycotic@my-dejanews.com
Subject: Re: Globbing don't work
Message-Id: <73uem7$bem$1@nnrp1.dejanews.com>
Try this ...
This may work on Win32 ??
@files = 'dir /B d:/pic/*.pic';
Cos this works on UNIX
@files = 'ls -1 /whatever/*.pic';
Hope this helps!
Jon
In article <73o843$978$1@power42t.hkbu.edu.hk>,
kelvinee@net1.hkbu.edu.hk (CHOU KEI HONG) wrote:
> hi all,
>
> I have tried writing a script to count the no. of files with extension .pic
> with a directory.
> It works fine when invoke locally from a dos prompt (perl test.pl).
> But when I invoke this script as a CGI, it was found that the script can't
> report the no. of files and always is zero.
>
> Does anybody has any idea ? Below is the code I write.
>
> print "Content-Type: text/html\n\n";
>
> @list = <d:/pic/*.pic>;
> $list_len = $#list +1;
> foreach $element (@list) {
> print "$element<br>";
> }
> print #list_len<br>";
>
> Or I guess there may have a better way to do this.
>
> Many thanks.
>
> Kelvin
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 30 Nov 1998 16:09:13 GMT
From: TimesOnLine@my-dejanews.com
Subject: GuestBook on NT with Blat
Message-Id: <73ufur$cfq$1@nnrp1.dejanews.com>
I am in urgent need of a GuestBook that will work on an NT using Blat. We are
moving our site and I will need the new script ASAP!
Our existing GuestBook works on an NT using postmail (I think) but the new
server only has blat and I don't know how to port it.
--
Chris, Web Admin.
The Times OnLine, Minden http://www.mindentimes.on.ca
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 30 Nov 1998 16:09:20 GMT
From: TimesOnLine@my-dejanews.com
Subject: GuestBook on NT with Blat
Message-Id: <73ufv2$cfs$1@nnrp1.dejanews.com>
I am in urgent need of a GuestBook that will work on an NT using Blat. We are
moving our site and I will need the new script ASAP!
Our existing GuestBook works on an NT using postmail (I think) but the new
server only has blat and I don't know how to port it.
--
Chris, Web Admin.
The Times OnLine, Minden http://www.mindentimes.on.ca
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 30 Nov 1998 05:28:32 GMT
From: pete@tier254300.TIER2.CWRU.Edu (Peter J. Kernan)
Subject: Re: Help -- remove white spaces from end of a string
Message-Id: <73tae0$k8$1@pale-rider.INS.CWRU.Edu>
In article <366075FC.FC8BD363@enhanced-performance.com>,
Dale Sutcliffe <dales@enhanced-performance.com> writes:
> What is the perl command for removing white spaces from the
> end of a string?
>
> Thanks
>
here is one way to do it (from command line so it can be tried
at home with minimum dispruption to working programs)
bug: it lacks efficiency
#!/usr/bin/perl -w
#note: this routine is brittle since it presumes knowledge of
# the perl docs
#important that the string to be stripped of *trailing* white
#spaces is named $string for reasons which are clarified later
$string = (shift or die "$0 wants string to strip");
open FAQ4, "perldoc perlfaq4|" or die "faqqed! $!";
$stripcode = do {
local $/="";
my $save;
while (<FAQ4>) {
$save .= $_
if /^\s*Or more nicely written as:\s*$/ .. /\s*[}]\s*$/;
}
$save =~ /(for.*})/s;
$1;
};
close FAQ4;
$stripcode = join "",@{ [split /\n/,$stripcode]}[0,2,3];
eval "$stripcode";
print "$string->end of string\n";
--
Perl Elves Rumble Lightheartedly
open SIG, "<$ENV{HOME}/.sig" or die "sigless! $!";
$sig = do {local $/; <SIG>}; close SIG && print<<"$sig SIG";
Pete Kernan CWRU Physics and Statistics Depts
http://theory2.phys.cwru.edu/~pete
$sig SIG
------------------------------
Date: Mon, 30 Nov 1998 17:49:47 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: How to determine if child process is dead?
Message-Id: <Pine.GSO.4.02A.9811300947380.26619-100000@user2.teleport.com>
On Mon, 30 Nov 1998, SHILUV Alon Zamir 2640 wrote:
> when i use fork,i can't tell in the parent wether the child is still
> running or not. How can i do that?
Sounds as if you want either wait (or waitpid) or kill.
$is_still_alive = kill 0, $pid;
kill with zero isn't as bad as it sounds; it's actually harmless. See the
perlfunc manpage and your system's docs for more information. Hope this
helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 30 Nov 1998 17:57:34 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Open or Create a file
Message-Id: <Pine.GSO.4.02A.9811300955510.26619-100000@user2.teleport.com>
On Mon, 30 Nov 1998, E. Preble wrote:
> What is the "create file" command in Perl.
See the entry for open() in the perlfunc manpage.
> Are there security issues with creating files from a script?
There are always security issues when creating files. Usually, they're
trivial. But if you're worried about security in a CGI environment, the
docs, FAQs, and newsgroups about CGI programming should be helpful. Good
luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 30 Nov 1998 17:22:16 GMT
From: dturley@pobox.com
Subject: perl Tk
Message-Id: <73uk7i$gl8$1@nnrp1.dejanews.com>
I've been trying out the examples from "Advanced Perl Programming",
specifically the perl/Tk stuff. Unfortunately, I'm limited to win32 perl for
this exercize. In the tetris.pl example, line 481:
$w_top = MainWindow->new('Tetris - Perl/Tk');
The script dies at this line, with the error:
Odd number of argsMainWindow->new(Tetris - Perl/Tk) at tetris.pl line 481
If I change the line to:
$w_top = MainWindow->new();
it runs fine (of course, I never could play this game :-)
I don't see anything in the pod about using args in the call to new(). So, I
was wondering, is this valid under Unix perl/tk, and just another limit with
the win32 build?
BTW, this is version 800.012 of the Tk module, from the AS site.
--
David Turley
dturley@pobox.com
http://www.binary.net/dturley/
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 30 Nov 1998 08:47:26 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Please help me solve three CGI problem: Make Dir, Create file and frameset
Message-Id: <u5bu37.mtu.ln@flash.net>
illfigah (alcazar@netcomp.net) wrote:
: Tho your perl code is rather arkane, it is correct. Since you've
: recieved those errors on all three of your scripts... the problem is the
: same. Make sure that when you upload the script (via ftp) that you set your
: upload to ascii format... binary will add unwanted characters.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You have that backwards.
"binary" ftp mode leaves all of the bytes as-is.
"ascii" ftp mode adds/removes characters to accomodate
the different line ending sequences.
If you are transferring between similar systems, then both
modes give identical results.
If transferring between dissimilar systems, then you need
ascii mode if you want the line endings adjusted to whatever
is used by the receiving system.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 Nov 1998 11:58:57 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: PROPOSAL: XML based Make for C++, Perl, Python, Java
Message-Id: <1dmu37.otv.ln@flash.net>
Bart Lateur (bart.lateur@skynet.be) wrote:
: Pluto wrote:
: > <file><path full>/the/first/module/</dir>file</file>
: How can this possibly be vcalid XML. There's a closing of a tag that
: hasn't even been opened: <dir>. <path> isn't closed.
: Something else: on the Mac, which is supposed to be a "valid platform"
: too, "/" is not a valid path separator, as it is a valid file name
: character. So in your code, you should replace the literal "/" with an
: empty tag, e.g. <dirsep/>.
^^^^^^^^^
That is an empty _element_
<> is an empty tag (which is allowed in SGML, but not in XML)
It may seem like a nitpic, but the distinction between tags
and elements is crucial. Tags are merely delimiters for
elements. It is the _element_ that is important.
But in the case of EMPTY elements (as above) there is no
"extent" of the element, and so there is no need to delimit
it. So in that case the tag *is* the element.
In the more general (non-EMPTY) case, the "tags" mark the
extent (beginning and end) of the element.
: Alternatively, URL-encoding would be an option, the same way as file
: paths are encoded for web browsers. Special characters like "/" should
: then be encoded as "%xx", with "xx" the hex value of the Ascii code.
But the ASCII code for slash is the same on Unix and Mac,
so that doesn't solve the "directory separator" problem.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 Nov 1998 10:46:04 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: RegExp and Authentication Help.
Message-Id: <c4iu37.kev.ln@flash.net>
Colin Cyr (ccyr@home.com) wrote:
: $data = "243";
: $data =~ /^\d$/; # How'd I add the additional condition that
: # it is a Real number (Nothing less than 1)?
You seem to be using a non-standard meaning of "real number".
So you will need to define what it means to you.
0.1 is a Real Number
-1 is a Real Number
0 is a Real Number
all are less than 1...
I don't understand your question as stated.
Try restating it unambiguously.
(maybe you meant "positive non-zero integer"?)
Your regex above will match one of only ten strings. Did
you mean to allow more than one digit? /^\d+$/;
See also the Perl FAQ, part 4:
"How do I determine whether a scalar is a number/whole/integer/float?"
: $data = "243.3.2.1.4";
^ ^
Maintenance will be easier if you only ask for
variable interpolation and/or backslash escapes
(using double quotes is asking for those things)
when you _need_ variable interpolation and/or backslash escapes.
$data = '243.3.2.1.4'; # single quotes
: $data =~ /????/; # Nothing I've tried will allow me to verify
: # this. Each section must be a Real, and the
: # string cannot start or end with a period.
To verify that each "section" consists of only digit characters:
print "$data is OK\n" if $data =~ /^\d+(:?\.\d+)*$/;
That says that $data = '123.000.5' is OK.
Is that supposed to be OK?
Is this OK? $data = '123.005.12';
You need to be more rigorous in describing what you want if
you want to get a directly usable answer...
: Okay, now on to finding these things...
: $find = "243.3"; or # Locates a specific key and returns it,
: # simple verification of existance...
$find = '243.3' if exists $data{'243.3'};
[ snip other requirements specifications, since I cannot figure
out what the heck they are specifying ;-)
]
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 Nov 1998 17:43:13 +0000
From: Gareth Ennis <gary.ennis@strath.ac.uk>
Subject: single quote problems
Message-Id: <3662D931.2781@strath.ac.uk>
Im trying to substitute text in a file from the Unix command line using:
perl -pi -e 's/old string/new string/g' filename
It works fine until i try and add a single quote (') in my new string :
perl -pi -e 's/old string/hello 'people' howdy/g' filename
What it prints is : hello people howdy
but what i want is: hello 'people' howdy
Please note i cannot use the double quotes(") since its for a piece of
code which does not accept them.
Please help!
--
Gareth Ennis
ABACUS - Strathclyde University
email: gary.ennis@strath.ac.uk
http://iris.abacus.strath.ac.uk/new/
------------------------------
Date: Mon, 30 Nov 1998 10:01:04 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: string match
Message-Id: <1gfu37.l9v.ln@flash.net>
Ashish (ank@gte.net) wrote:
: I would like to know the following:
: -----
: $string = "This is string. is it";
: @i=($string =~ m/(is)/ig);
: print "@i";
: ------
: How @i is taking "is is is";
Since you are using the m//g operator, you should probably
see what the documentation that came with perl says about
the m//g operator ;-)
Perl's operators are described in the 'perlop' man page,
wherein:
----------------
The C</g> modifier specifies global pattern matching--that is, matching
as many times as possible within the string. How it behaves depends on
the context. In list context, it returns a list of all the
substrings matched by all the parentheses in the regular expression.
If there are no parentheses, it returns a list of all the matched
strings, as if there were parentheses around the whole pattern.
----------------
You have used it in a list context above, so it returns a list of
all the substrings matched by all the parentheses in the
regular expression.
You had your answer on your hard drive the whole time!
Use the docs Luke.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 Nov 1998 17:54:08 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: support for the Kermit protocol?
Message-Id: <Pine.GSO.4.02A.9811300953430.26619-100000@user2.teleport.com>
On Mon, 30 Nov 1998 PETER@yaleads.ycc.yale.edu wrote:
> Hi. I was wondering if Perl (especially MacPerl) has any modules that
> support the Kermit prorocol?
If there's a module which does what you want, it should be listed in
the module list on CPAN. If you don't find one to your liking, you're
welcome and encouraged to submit one! :-) Hope this helps!
http://www.perl.org/CPAN/
http://www.perl.com/CPAN/
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 30 Nov 1998 17:33:14 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: to dbm or not to dbm?
Message-Id: <Pine.GSO.4.02A.9811300927090.26619-100000@user2.teleport.com>
On 30 Nov 1998, Bill Moseley wrote:
> when does it make sense to use dbm file(s) instead of keeping just
> plain text files (and filling related hashes when the script runs from
> the text files)?
When it's "better", in the ways which matter to you. These ways may
include runtime, programmer time, programming ease, robustness, debugging
ease, disk space, memory space, portability, or other criteria. But, in
general, by the time you're asking this question, you probably want a DBM
implementation.
> And if I use dbm, does it make sense, speed wise, to use one or just a
> few files, or use a separate file for each record structure?
If I understand your question correctly, the speed difference is not
significant; using N items of data from one DBM file should be roughly the
same time as using one item from each of N files, in general. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 30 Nov 1998 09:40:35 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: variables in substitutions
Message-Id: <j9eu37.06v.ln@flash.net>
Eric Bohlman (ebohlman@netcom.com) wrote:
: rick.schwein@phillynews.com wrote:
: : For example: my control file contains these search/replace pairs (slashes
: : are interpreted as delimiters): /aaa/qqq/ /(bbbb)(.*)(ee)/\3\2\1/
: That's not how you interpolate backreferences into a substitution in Perl...
^^^^^^^^^^^^
: Go back and take a look at perlre, where you'll find that you want to use
^^^^^^
That would be a strange place to describe what goes on in a
Perl *op*erator.
perlre describes regular expressions (the part between the _first_
pair of // in s///. We're talking about the second pair here...
perlop describes perl's operators, including s///
perlop says:
-------------
s/([^ ]*) *([^ ]*)/$2 $1/; # reverse 1st two fields
Note the use of $ instead of \ in the last example. Unlike
B<sed>, we use the \E<lt>I<digit>E<gt> form in only the left hand side.
Anywhere else it's $E<lt>I<digit>E<gt>.
-------------
Which is what you were probably thinking of.
But in any case \3 works fine (though it is not -w clean)
-------------
#!/usr/bin/perl -w
$_ = 'aaa bbbb ccccc dddddd ee f';
s/(bbbb)(.*)(ee)/\3\2\1/gi;
print "$_\n";
-------------
output:
\3 better written as $3 at ./skel line 5.
\2 better written as $2 at ./skel line 5.
\1 better written as $1 at ./skel line 5.
aaa ee ccccc dddddd bbbb f
Works fine, if a little noisily.
: '$3', etc. rather than '\3' (which says to insert a control-c into the
: replacement text).
If he changes the backslashes to dollar signs, then the output
would be:
qqq $3$2$1 f
... not much of an improvement ;-)
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 Nov 1998 09:52:07 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: variables in substitutions
Message-Id: <7veu37.j7v.ln@flash.net>
rick.schwein@phillynews.com wrote:
: I am using the current version of Perl for Win32. I have a script that reads
: search/replace pairs from a control file, and I am not getting the "replace"
: results I expect.
Adjust your expectations ;-)
: Simple substitutions work just fine, but if I use parentheses to group target
: strings, I'm not able to get them back out properly.
: For example: my control file contains these search/replace pairs (slashes
: are interpreted as delimiters): /aaa/qqq/ /(bbbb)(.*)(ee)/\3\2\1/
: the script loops through the control file and reads in each line and splits
: them into the variables $search and $replace. it then uses those variables in
: this line:
: $_ =~ s/$search/$replace/gi ;
: if the script is run against text containing this line:
: aaa bbbb ccccc dddddd ee f
: my output is "qqq \3\2\1 f" and not "qqq ee ccccc dddddd bbbb f"
You only get one round of variable interpolation in the replacement
part. It is used to expand the $replace variable. There is no
interpolation round to handle expanding the $3$2$1 part.
(you should be using -w on every single Perl program. Really!)
: if the substitution pairs are typed explicitly within the script, they are
: execute as expected.
Because the single round of interpolation can expand the $3$2$1.
: but when expressed as variables, it breaks. is this a
: win32 bug or simply they way the =~ s// operator works?
That is simply the way it works.
You can use s///e to get the number of rounds of evaluation
that you need, but you would need to change your replacement
pattern to be legal code rather than a variable interpolated
string:
--------------------
#!/usr/bin/perl -w
$search = '(bbbb)(.*)(ee)';
$replace = '$3.$2.$1'; # concatenate the parts
$_ = 'aaa bbbb ccccc dddddd ee f';
s/aaa/qqq/gi;
s/$search/$replace/giee; # first e handles $replace, second e
# handles the $digit expansions
print "$_\n";
--------------------
But now you have the problem of determining when to do
s/$search/$replace/gi; # for /aaa/qqq/
and
s/$search/$replace/giee; # for /(bbbb)(.*)(ee)/$3.$2.$1/
...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 Nov 1998 16:53:01 -0000
From: "Clinton Gormley" <cgormley@netcomuk.co.uk>
Subject: When does CLOSE not FLUSH?
Message-Id: <73uihb$htn$1@taliesin.netcom.net.uk>
I'm running perl scripts on Solaris and am having difficulty with locking
and flushing.
The process of the script is :
(1) open (>>FH)
(2) flock (FH,LOCK_EX)
(3) print FH encrypted "foobar"-->takes about 4 seconds.
(4) close (FH);
more than one script can run at the same time.
My understanding was that close would (1) flush the file buffer and
(2)unlock the file.
in practice, I found that if 10 scripts were called, only 1 or 2 lines of
(encrypted "foobar") were being written to the file. The LOCK_EX was
working however.
I then found that if set $| for FH to 1, then this worked perfectly. Why?
Surely the close should sort out the file buffering before the lock is
removed.
I originally tried it with flock (FH,LOCK_UN) as well, without success.
Although, to be honest, I haven't tried to reimplement it since I have
pinpointed the problem.
Any ideas?
Thanks
Clint
------------------------------
Date: Mon, 30 Nov 1998 11:53:13 -0600
From: Dan Brian <dan@clockwork.net>
Subject: Re: Writing to password protected directory
Message-Id: <3662DB89.C521D50C@clockwork.net>
If you're refering to password protection using .htaccess files, these
directories are only password-ed for the web server. You can read/write to
them all you want, given that you have file permissions to do so.
If you're refering to something else ...
Sergey Denisov wrote:
> Hello, all.
> May be someone knows, how can I create and write to files in password
> protected directory on my server. And is it truly, that I can freely read
> from files in this protected directory without any password ?
>
> Thanks, Sergey.
> sdenisov@toolsoft.com
------------------------------
Date: 30 Nov 1998 11:11:22 -0600
From: les@MCS.COM (Leslie Mikesell)
Subject: Re: Y2K and Programmer Denial
Message-Id: <73ujjq$27u$1@Venus.mcs.net>
In article <fl_aggie-2711981806540001@aggie.coaps.fsu.edu>,
I R A Aggie <fl_aggie@thepentagon.com> wrote:
>If you have ever handled the returned value for the year from localtime
>and its friends as a character, you have likely committed a Y2K error.
>
>$year=(localtime)[5];
>$year = $year + 1900 ; #correct
>$year = '19'.$year; # incorrect (results in a string '19100' in 2000)
>
>Anyone who has been doing serious perl for more than 6 weeks should be
>able to write code to seek out and ennumerate a list of perl scripts that
>use localtime, and examine them for trash code.
Has anyone actually done this to look for '19' used in string context
in association with a value obtained from a *time() function with
anywhere near the intensity of 'taint' checking?
Les Mikesell
les@mcs.com
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 4324
**************************************