[22097] in Perl-Users-Digest
Perl-Users Digest, Issue: 4319 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 29 03:05:49 2002
Date: Sun, 29 Dec 2002 00:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 29 Dec 2002 Volume: 10 Number: 4319
Today's topics:
Adding umlaut character to string <mwoog@gmx.net>
Re: C Backend <goldbb2@earthlink.net>
Re: IE uploads result in zero length files using CGI.pm <goldbb2@earthlink.net>
Re: IE uploads result in zero length files using CGI.pm <usenet@atrixnet.com>
linux: starting apache as su (Cappucino)
Re: linux: starting apache as su <goldbb2@earthlink.net>
Re: Newbie Reg. Exp. questions.. (Anno Siegel)
Re: Newbie Reg. Exp. questions.. (Felix F.)
Re: Newbie Reg. Exp. questions.. <eric.ehlers@btopenworld.com.nospam>
Re: Newbie Reg. Exp. questions.. <bongie@gmx.net>
Re: Newbie Reg. Exp. questions.. (Tad McClellan)
Re: Newbie Reg. Exp. questions.. <wsegrave@mindspring.com>
Re: Newbie Reg. Exp. questions.. (Alan Barclay)
Re: Newbie Reg. Exp. questions.. <goldbb2@earthlink.net>
Not loading unneeded modules with use strict? (Tim Shoppa)
Re: Not loading unneeded modules with use strict? (Anno Siegel)
Re: Not loading unneeded modules with use strict? (Jay Tilton)
Re: Not loading unneeded modules with use strict? <goldbb2@earthlink.net>
Re: regular expression help <Jodyman@hotmail.com>
Re: regular expression help <Jodyman@hotmail.com>
Re: The Superiority of PHP over Perl (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
while and eof <jm@roth.lu>
Re: while and eof <bongie@gmx.net>
win32 - start in background <jlague@NOSPAM.kc.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 29 Dec 2002 01:08:37 +0100
From: "Marc-A. Woog" <mwoog@gmx.net>
Subject: Adding umlaut character to string
Message-Id: <3e0e3d1b$1@news.swissonline.ch>
Hello there,
I have trouble understanding something.
I receive an attribute value from an LDAP directory containing umlauts. Perl
displays these special chars as UTF8 (I assume). I tried Unicode::String for
conversion with no luck yet.
So I did this small experiment: I take this string and feed it into a small
Perl script (the value is in $text):
----
my ($out, $flag);
open(FILE, ">/var/tmp/test.txt") || die;
for ($i = 0; $i < length($text); $i++) {
my $char = substr($text, $i, 1);
if ((ord($char) + 64) < 255) {
if (ord($char) > 127) {
$char = chr(ord($char) + 64);
}
print FILE "C: '$char'\n";
$out = $out.$char;
print FILE "S: $out\n";
}
}
close(FILE);
----
Now the strange thing is that when printed as a single char it is correct.
When appended to the $out string, the same strange chars appear again???
Can anybody please explain this behaviour (and maybe how to get rid of it)?
Thanks a bunch and cheers,
Marc
----
perl -v
This is perl, v5.6.1 built for i386-linux
----
Script Output (I hope it displays correctly):
[cut until it becomes interesting]
C: 'ü'
S: Simple on konnte nicht ausgefü
C: 'h'
S: Simple on konnte nicht ausgefüh
C: 'r'
S: Simple on konnte nicht ausgeführ
C: 't'
S: Simple on konnte nicht ausgeführt
C: ';'
S: Simple on konnte nicht ausgeführt;
C: 'w'
S: Simple on konnte nicht ausgeführt;w
C: 'ä'
S: Simple on konnte nicht ausgeführt;wä
C: 'r'
S: Simple on konnte nicht ausgeführt;wär
C: 'd'
S: Simple on konnte nicht ausgeführt;wärd
C: 'e'
S: Simple on konnte nicht ausgeführt;wärde
C: 'n'
S: Simple on konnte nicht ausgeführt;wärden
C: '2'
S: Simple on konnte nicht ausgeführt;wärden2
C: '}'
S: Simple on konnte nicht ausgeführt;wärden2}
C: '.'
S: Simple on konnte nicht ausgeführt;wärden2}.
C: 'Ö'
S: Simple on konnte nicht ausgeführt;wärden2}.Ã-
C: 'Ü'
S: Simple on konnte nicht ausgeführt;wärden2}.Ã-Ão
C: 'é'
S: Simple on konnte nicht ausgeführt;wärden2}.Ã-Ãoé
------------------------------
Date: Sun, 29 Dec 2002 00:24:34 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: C Backend
Message-Id: <3E0E8712.17CF0384@earthlink.net>
Jeff Mott wrote:
[snip]
> 912: no such instruction ""
> There were 912 assembly errors
> CHECK failed--call queue aborted.
>
> ?!? I realize it's experimental, but does it work at all? Is there
> something vital I'm missing?
The vital thing that you're missing is that it was "experimental" in
perl 5.005_03, and hasn't been updated since then.
If there's even one new opcode which your program uses but which didn't
exist in that version of perl, it's going to cause perlcc to fail.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Sun, 29 Dec 2002 00:31:22 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: IE uploads result in zero length files using CGI.pm
Message-Id: <3E0E88AA.2C89087B@earthlink.net>
Chris Kolosiwsky wrote:
[snip]
> my $uploadedfile = $q->upload('UploadedFile');
At this point, $uploadedfile is a globref which has been blessed into a
class with an overloaded '""' operator.
> $uploadedfile =~ s/.*[\/\\](.*)/$1/;
> # only grab the file after the last / in the pathname
After doing this, $uploadedfile has been forced to be a string and
*only* a string. It is no longer a filehandle.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Sun, 29 Dec 2002 01:09:12 -0600
From: Tommy Butler <usenet@atrixnet.com>
To: phignuton@hotmail.com
Subject: Re: IE uploads result in zero length files using CGI.pm
Message-Id: <3E0E9F98.40702@atrixnet.com>
Chris Kolosiwsky wrote:
> I was wondering if there is a workaround for the following situation:
>=20
> A cgi script accepts a file name for upload. The script untaints the
> file name, munges it to a predetermined name and writes the file to
> disk.
This works:
http://ooopps.sourceforge.net/cgi-bin/archive.pl/pub/code-examples/file-u=
pload.pl.html
--=20
-Tommy Butler
see if I'm online =BBhttp://ooopps.sourceforge.net/online
Tommy Butler <tommy@atrixnet.com>
phone: (817)-468-7716
6711 Forest Park Dr
Arlington, TX
76001-8403
Download my r=E9sum=E9 in PDF, MS Word, HTML, text
http://www.atrixnet.com/
the ooOPps Code Library
http://ooopps.sourceforge.net/pub/
------------------------------
Date: Sun, 29 Dec 2002 06:17:18 +0100
From: "Robert (Cappucino) Welz" <robertLinux@kaffeeschluerfer.com>
Subject: linux: starting apache as su
Message-Id: <BA3443EE.1E30A%robertLinux@kaffeeschluerfer.com>
Hello.
I want to make a little script to help me start SSH or Apache as root.
Unfortunately this doesn't work:
#!/usr/sbin/perl
system 'su';
system '/usr/.../bin/apachectl start';
Is there a way to achieve this behavior?
Greetings,
------------------------------------------------
Robert Welz
Thank you for your attention
------------------------------------------------
------------------------------
Date: Sun, 29 Dec 2002 00:57:49 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: linux: starting apache as su
Message-Id: <3E0E8EDD.DA281D2B@earthlink.net>
Robert (Cappucino) Welz wrote:
>
> Hello.
> I want to make a little script to help me start SSH or Apache as root.
> Unfortunately this doesn't work:
>
> #!/usr/sbin/perl
>
> system 'su';
> system '/usr/.../bin/apachectl start';
>
> Is there a way to achieve this behavior?
This has nothing to do with perl, but:
system qw(su httpd -c /usr/.../bin/apachectl start);
Or, by adding an appropriate line to sudo.conf:
system qw(sudo httpd &startapache);
[untested]
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: 28 Dec 2002 20:17:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Newbie Reg. Exp. questions..
Message-Id: <aul0td$es7$1@mamenchi.zrz.TU-Berlin.DE>
According to -SmC- <invalid-email@melodyland.net>:
> Think this is a simple question by i judy cant solve it...
>
> Can anyone teach me how to validate IP address?
> example checking for the correct format: 220.110.113.111
It is possible to do this in a single regex. See _Mastering Regular
Expressions_ by Jeffrey Friedl and its web page at ora.com for a solution
(two, in fact).
While this may be a good exercise in regular expressions, it is hardly
a good solution in a practical program.
> have 4 group of 3 number and each group not over 255 ?
Just use your verbal description as a guideline to the program (untested):
sub is_well_formed {
my @groups = split /\./, shift; # isolate dot-separated groups
return 0 unless @groups == 4; # must be four fields
for ( @groups ) { # check each group
return 0 unless /^\d+$/; # must be all digits...
return 0 unless $_ < 256; # ...and below 256
}
return 1; # all passed
}
This may be longer and perhaps even less efficient than a single regex,
but it is easy to see what the function checks and how it does it.
It is also easier to modify: Suppose you wanted to check that at least
one group is non-zero (a requirement for a valid IP address you don't
mention). It would be easy to modify the loop above to check this also.
Re-writing a regex to do this check is for masochists.
Anno
------------------------------
Date: 28 Dec 2002 14:34:57 -0800
From: felix@pz4.org (Felix F.)
Subject: Re: Newbie Reg. Exp. questions..
Message-Id: <84216b9c.0212281434.61a80cc9@posting.google.com>
"-SmC-" <invalid-email@melodyland.net> wrote in message news:<aukr4g$qvd$1@nobel.pacific.net.sg>...
> Think this is a simple question by i judy cant solve it...
>
> Can anyone teach me how to validate IP address?
> example checking for the correct format: 220.110.113.111
>
> have 4 group of 3 number and each group not over 255 ?
>
> Thanks alot
Hello,
We can't possibly teach you how to create such script, because it
involves few things. I strongly suggest you pickup a book called
Learning Perl 2nd Edition, by Oreilly. It will help you understand
what the script means than just following blindly.
:)
------------------------------
Date: Sat, 28 Dec 2002 22:42:23 +0000 (UTC)
From: "eric" <eric.ehlers@btopenworld.com.nospam>
Subject: Re: Newbie Reg. Exp. questions..
Message-Id: <aul9ce$qml$1@helle.btinternet.com>
> Can anyone teach me how to validate IP address?
> example checking for the correct format: 220.110.113.111
> have 4 group of 3 number and each group not over 255 ?
try this -
use strict;
use warnings;
my
@test_addresses=("220.110.113.111.111","220.110.256.111","220.110.113.111");
LOOP: for (@test_addresses) {
print "testing address |$_| ... ";
if (my @numbers=$_=~/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
for (@numbers) {
if ($_<100||$_>255) {
print "invalid - digit $_ not between 100 and 255 inclusive\n";
next LOOP;
}
}
print "valid\n";
} else {
print "invalid - not in format 999.999.999.999\n";
}
}
- eric
------------------------------
Date: Sun, 29 Dec 2002 02:46:51 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Newbie Reg. Exp. questions..
Message-Id: <1158395.qdqvXk6crX@nyoga.dubu.de>
eric wrote:
> if (my @numbers=$_=~/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
> for (@numbers) {
> if ($_<100||$_>255) {
^^^
> print "invalid - digit $_ not between 100 and 255
^^^
This 100 looks a bit arbitrary to me for an IP address... ;-)
BTW... How about this:
perl -MSocket -e 'inet_aton("127.0.0.1") or warn "invalid IP";'
Okay, okay, I admit. It's overkill to load Socket.pm just to check an
IP (using a method that will also accept 0.0.0.0 as valid - *eek*).
;-)
Ciao,
Harald
--
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
You know, a lot of girls go out with me just to further their
careers...damn anthropologists. -- Emo Phillips
------------------------------
Date: Sat, 28 Dec 2002 21:28:03 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie Reg. Exp. questions..
Message-Id: <slrnb0squ3.1vs.tadmc@magna.augustmail.com>
Felix F. <felix@pz4.org> wrote:
> I strongly suggest you pickup a book called
> Learning Perl 2nd Edition, by Oreilly.
There is now a 3rd edition.
You should be referring folks to the new edition.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 28 Dec 2002 22:54:31 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Newbie Reg. Exp. questions..
Message-Id: <aulvad$45s$1@slb9.atl.mindspring.net>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnb0squ3.1vs.tadmc@magna.augustmail.com...
> Felix F. <felix@pz4.org> wrote:
>
> > I strongly suggest you pickup a book called
> > Learning Perl 2nd Edition, by Oreilly.
>
The OP might luck up and find a copy. It was remaindered at BAM 01Jun2001.
LP3 is currently among the remainders at BAM, approx. half price.
>
> There is now a 3rd edition.
>
> You should be referring folks to the new edition.
>
If the OP has a Win32 system, he might benefit by getting
LP_on_Win32_Systems.
Happy New Year!
Bill Segraves
------------------------------
Date: 29 Dec 2002 05:02:44 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Newbie Reg. Exp. questions..
Message-Id: <1041138163.581561@elaine.furryape.com>
In article <aukr4g$qvd$1@nobel.pacific.net.sg>,
-SmC- <invalid-email@melodyland.net> wrote:
>Can anyone teach me how to validate IP address?
>example checking for the correct format: 220.110.113.111
Dotted quad is only one possible correctly formatted IP address.
Instead of trying to check if an address is in dotted quad format,
then use the inet_aton function which which handle any validly
formatted ip address:
use Socket;
my $address="1.2.3.4";
if(defined inet_aton($address)){
print "Valid address\n";
} else {
print "Invalid address\n";
}
------------------------------
Date: Sun, 29 Dec 2002 00:39:21 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Newbie Reg. Exp. questions..
Message-Id: <3E0E8A89.EFA5E347@earthlink.net>
Anno Siegel wrote:
[snip]
> > have 4 group of 3 number and each group not over 255 ?
>
> Just use your verbal description as a guideline to the program
> (untested):
>
> sub is_well_formed {
> my @groups = split /\./, shift; # isolate dot-separated groups
> return 0 unless @groups == 4; # must be four fields
> for ( @groups ) { # check each group
> return 0 unless /^\d+$/; # must be all digits...
> return 0 unless $_ < 256; # ...and below 256
> }
> return 1; # all passed
> }
This says that "0.0.0.0........" is valid. I think you want the first
line of the sub to read:
my @groups = split /\./, shift, 5; # isolate dot-separated groups
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: 28 Dec 2002 14:59:30 -0800
From: shoppa@trailing-edge.com (Tim Shoppa)
Subject: Not loading unneeded modules with use strict?
Message-Id: <bec993c8.0212281459.45ea793a@posting.google.com>
OK, I've written a neat little module of my own (Unigraph) which forms an
abstract interface to various graphics-producing CPAN modules. In particular,
Unigraph sits in front of GD and PDF::API2 and lets me create *either* a GD
or a PDF graph with identical calls, the only difference being in a parameter
to the Unigraph->new() constructor that tells it which implementation to use.
It's way cool, and lets me write one program that can produce many different
types of graphs. The problem is, at the top of my Unigraph module I say:
use strict;
use GD;
use PDF::API2;
and the time penalty for loading *both* GD and PDF::API2 (when I only needed
one) is appreciable.
Now I've read chapter 12 of the _Perl Cookbook_ and they tell me how to
replace "use" with "require" and "import", or to wrap the "use" in an "eval",
to avoid loading unneeded modules. But if I do that, I have to turn off
the "use strict", and I really really like keeping "use strict" in my code
even after it leaves development.
Is there some trick, maybe new with Perl 5.6 or 5.8, which gives
me the best of both worlds, the ability to keep "use strict" while
not loading unneeded modules?
Tim.
------------------------------
Date: 28 Dec 2002 23:17:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Not loading unneeded modules with use strict?
Message-Id: <aulbe3$l69$1@mamenchi.zrz.TU-Berlin.DE>
According to Tim Shoppa <shoppa@trailing-edge.com>:
> OK, I've written a neat little module of my own (Unigraph) which forms an
> abstract interface to various graphics-producing CPAN modules. In particular,
> Unigraph sits in front of GD and PDF::API2 and lets me create *either* a GD
> or a PDF graph with identical calls, the only difference being in a parameter
> to the Unigraph->new() constructor that tells it which implementation to use.
>
> It's way cool, and lets me write one program that can produce many different
> types of graphs. The problem is, at the top of my Unigraph module I say:
>
> use strict;
> use GD;
> use PDF::API2;
>
> and the time penalty for loading *both* GD and PDF::API2 (when I only needed
> one) is appreciable.
>
> Now I've read chapter 12 of the _Perl Cookbook_ and they tell me how to
> replace "use" with "require" and "import", or to wrap the "use" in an "eval",
> to avoid loading unneeded modules. But if I do that, I have to turn off
> the "use strict",
Why, exactly? I don't see how these techniques violate strictures.
> and I really really like keeping "use strict" in my code
> even after it leaves development.
Right you are.
> Is there some trick, maybe new with Perl 5.6 or 5.8, which gives
> me the best of both worlds, the ability to keep "use strict" while
> not loading unneeded modules?
If you have to break strictures in your program, you can usually limit
the effect to a small block. Create a bare block if the critical code
isn't already inside one, and then do "no strict 'vars'" (or whatever)
inside the block. Strictures will still be in place for the rest of
the program.
Anno
------------------------------
Date: Sat, 28 Dec 2002 23:38:13 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Not loading unneeded modules with use strict?
Message-Id: <3e0e33f2.79004182@news.erols.com>
shoppa@trailing-edge.com (Tim Shoppa) wrote:
: It's way cool, and lets me write one program that can produce many different
: types of graphs. The problem is, at the top of my Unigraph module I say:
:
: use strict;
: use GD;
: use PDF::API2;
:
: and the time penalty for loading *both* GD and PDF::API2 (when I only needed
: one) is appreciable.
:
: Now I've read chapter 12 of the _Perl Cookbook_ and they tell me how to
: replace "use" with "require" and "import", or to wrap the "use" in an "eval",
: to avoid loading unneeded modules. But if I do that, I have to turn off
: the "use strict",
Says who? What does strict gripe about when you do this?
------------------------------
Date: Sun, 29 Dec 2002 00:50:19 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Not loading unneeded modules with use strict?
Message-Id: <3E0E8D1B.A3C647A1@earthlink.net>
Tim Shoppa wrote:
>
> OK, I've written a neat little module of my own (Unigraph) which forms
> an abstract interface to various graphics-producing CPAN modules. In
> particular, Unigraph sits in front of GD and PDF::API2 and lets me
> create *either* a GD or a PDF graph with identical calls, the only
> difference being in a parameter to the Unigraph->new() constructor
> that tells it which implementation to use.
>
> It's way cool, and lets me write one program that can produce many
> different types of graphs. The problem is, at the top of my Unigraph
> module I say:
>
> use strict;
> use GD;
> use PDF::API2;
>
> and the time penalty for loading *both* GD and PDF::API2 (when I only
> needed one) is appreciable.
>
> Now I've read chapter 12 of the _Perl Cookbook_ and they tell me how
> to replace "use" with "require" and "import", or to wrap the "use" in
> an "eval", to avoid loading unneeded modules.
> But if I do that, I have to turn off the "use strict",
Assuming that 'strict' is complaining about your use of barewords, then
this can be fixed in a few ways -- the first, and simplest, is to add
parens... simply change all calls of the form:
foo;
bar $arg, $arg, $arg;
Into:
foo();
bar( $arg, $arg, $arg );
If the subroutines don't have prototypes, then this is likely to be
best.
The second way is to predeclare all the subs;
sub subname1; sub subname2; sub subname3; # etc.
This has the benefit that you can leave the body of your code unchanged
(other than having to add require/import into your 'new'), and you can
have prototypes.
The third way is the autouse module:
use autouse GD => qw(subname1 subname2 subname3);
use autouse PDF::API2 => qw(subname4 subname5 subname6);
With this, you don't have to make *any* changes to the rest of your code
-- you don't even have to make ->new load up one of the two modules via
require and perform an import, as autouse will do that automatically.
> and I really really like keeping "use strict" in my code
> even after it leaves development.
>
> Is there some trick, maybe new with Perl 5.6 or 5.8, which gives
> me the best of both worlds, the ability to keep "use strict" while
> not loading unneeded modules?
Add parens.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Sun, 29 Dec 2002 05:25:52 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: regular expression help
Message-Id: <AHvP9.1201$9N5.158794@newsread2.prod.itd.earthlink.net>
"Mark" <mark.faine@msfc.nasa.gov> wrote in message
> > > eight characters exactly
> > >
> > > The eight characters will contain at least one character each from at
> > > least three of the following sets of characters:
> > >
> > > At least one uppercase letter
> > > At least one lowercase letters
> > > At least one numbers
> > > At least one special characters
> > >
> > > My feeble attempts have gotten me this far:
> > >
> > > /([A-Z]|[a-z]|[0-9]|(\W)){3,8}/
> > >
> > Do you want to validate passwords or generate passwords with this
criteria?
>
> Actually I can see a case for both.
>
Mark,
This works OK for validation. I'm sure there are better ways out there
but this works.
#!c:\perl\bin\perl -w
use strict;
print "Enter Password: ";
chomp (my $password = <STDIN>);
if (
(length $password == 8) and
($password =~ /[A-Z]+/) and
($password =~ /[a-z]+/) and
($password =~ /[0-9]+/) and
($password =~
/[\~\!\@\#\$\%\^\&\*\(\)\_\+\=\-\`\{\}\:\;\"\'\<\>\,\.\/\?\\\|]+/)
)
{ print "Passed!\n"; } else { print "Failed!\n"; }
if (
(length $password == 8) and
($password =~
/[A-Z]+|[a-z]+|[0-9]+|[\~\!\@\#\$\%\^\&\*\(\)\_\+\=\-\`\{\}\:\;\"\'\<\>\,\.\
/\?\\\|]+/)
)
{ print "Passed!\n"; } else { print "Failed!\n"; }
HTH,
Jody
------------------------------
Date: Sun, 29 Dec 2002 06:15:08 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: regular expression help
Message-Id: <MpwP9.1243$9N5.167256@newsread2.prod.itd.earthlink.net>
"Jodyman" <Jodyman@hotmail.com> wrote in message
news:AHvP9.1201$9N5.158794@newsread2.prod.itd.earthlink.net...
>
> "Mark" <mark.faine@msfc.nasa.gov> wrote in message
> > > > eight characters exactly
> > > >
> > > > The eight characters will contain at least one character each from
at
> > > > least three of the following sets of characters:
> > > >
> > > > At least one uppercase letter
> > > > At least one lowercase letters
> > > > At least one numbers
> > > > At least one special characters
> > > >
> > > > My feeble attempts have gotten me this far:
> > > >
> > > > /([A-Z]|[a-z]|[0-9]|(\W)){3,8}/
> > > >
> > > Do you want to validate passwords or generate passwords with this
> criteria?
> >
> > Actually I can see a case for both.
> >
> Mark,
>
> This works OK for validation. I'm sure there are better ways out
there
> but this works.
>
> #!c:\perl\bin\perl -w
> use strict;
>
> print "Enter Password: ";
> chomp (my $password = <STDIN>);
>
> if (
> (length $password == 8) and
> ($password =~ /[A-Z]+/) and
> ($password =~ /[a-z]+/) and
> ($password =~ /[0-9]+/) and
> ($password =~
> /[\~\!\@\#\$\%\^\&\*\(\)\_\+\=\-\`\{\}\:\;\"\'\<\>\,\.\/\?\\\|]+/)
> )
> { print "Passed!\n"; } else { print "Failed!\n"; }
>
> if (
> (length $password == 8) and
> ($password =~
>
/[A-Z]+|[a-z]+|[0-9]+|[\~\!\@\#\$\%\^\&\*\(\)\_\+\=\-\`\{\}\:\;\"\'\<\>\,\.\
> /\?\\\|]+/)
> )
> { print "Passed!\n"; } else { print "Failed!\n"; }
>
Sorry, the last one does not work. It allows: qqqqqqqq or ZZZZZZZ etc. It
is or'ed not and'ed.
Jody
------------------------------
Date: 29 Dec 2002 00:57:12 +0100
From: mru@users.sourceforge.net (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
Subject: Re: The Superiority of PHP over Perl
Message-Id: <yw1x4r8xzoh3.fsf@gladiusit.e.kth.se>
"Murat Ünalan" <murat.uenalan@gmx.de> writes:
> > It is a method, no matter how you call it. In Perl there is simply no
> > distinction between a class method, an instance method and a function
> > caller-wise. Weren't it a method, you couldn't do the following:
> >
> > $object->printHello;
> >
> > But you can also do:
> >
> > A->printHello;
>
> I regret to reject this. A method is something which relates to its
> class/object.
method == function == procedure == subroutine == lots-of-others
It's the same thing, no matter what you use it for. The name is just
a matter of convention.
--
Måns Rullgård
mru@users.sf.net
------------------------------
Date: Sun, 29 Dec 2002 01:37:44 +0100
From: "J.M.Roth" <jm@roth.lu>
Subject: while and eof
Message-Id: <3e0e43e4$1_1@news.vo.lu>
Hi,
check out this code fragment
I'm trying to put together a script to change size-based logs into
time-based logs.
Now I have a while loop that goes through the logfiles and does some smart
checks to find out where to begin without reading everything.
Now, the problem is if I want to retrieve the data for the month in progress
(in fact the input to the script is "year month") it won't write anything
because it sets $period_over and then writes the output only when it finds
something which doesn't match anymore, which obviously is not the case since
the current month is not yet finished, hence "current" ;-)
The commented line containing the eof would do the trick but would only work
with while(<>) or alike. Needless to say, I'm stuck now.
Any idea?
Thanks!
while($file = readdir(DIR)) {
.......
open(FILEIN, "$qmaillogdir/$file") || die("Can't
open file $qmaillogdir/$file for read: $!");
while(<FILEIN>) {
@line = split(" ", $_);
@line = tai64nlocal(substr($line[0],1));
if ($line[0]==$ARGV[0] &&
$line[1]==$ARGV[1]) {
$already_started=1;
$result[$i] = $_;
$i++;
# $period_over=1 if eof();
} else {
$period_over=1 if $already_started;
}
}
close FILEIN;
if ($period_over) {
... writing results here ....
exit;
}
...
------------------------------
Date: Sun, 29 Dec 2002 03:17:29 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: while and eof
Message-Id: <2187540.gZz446Pi0a@nyoga.dubu.de>
J.M.Roth wrote:
[reduced indentation to fit line length, -hhjb-]
> while($file = readdir(DIR)) {
> .......
> open(FILEIN, "$qmaillogdir/$file") ||
> die("Can't open file $qmaillogdir/$file for read: $!");
> while(<FILEIN>) {
I would insert a
last if $period_over;
here to skip the rest of the file, if the range you're looking for has
been processed. (It is contiguous, isn't it?)
> @line = split(" ", $_);
> @line = tai64nlocal(substr($line[0],1));
> if ($line[0]==$ARGV[0] && $line[1]==$ARGV[1]) {
> $already_started=1;
> $result[$i] = $_;
> $i++;
These two lines could be written more perlish:
push @result, $_;
> # $period_over=1 if eof();
$period_over=1 if eof(FILEIN);
or
$period_over=1 if eof;
See perldoc -f eof.
> } else {
> $period_over=1 if $already_started;
> }
> }
> close FILEIN;
> if ($period_over) {
Or you may skip this eof test totally and check here:
if ($already_started) {
If I'm not wrong, $already_started will only be true if some lines of
interest have been read, either somewhere or at the end of the file.
Don't forget to reset $already_started and $period_over for the next
file. And maybe you want to localize some of your variables to a
smaller scope... :-)
> ... writing results here ....
> exit;
> }
> ...
Ciao,
Harald
--
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Does the Little Mermaid wear an algebra?
------------------------------
Date: Sat, 28 Dec 2002 16:47:06 -0600
From: "John L" <jlague@NOSPAM.kc.rr.com>
Subject: win32 - start in background
Message-Id: <oQpP9.27852$eB.445306@twister.kc.rr.com>
Since I'm usually a Unix/Linux user, I don't know how to do this in win32...
I'd like to start a program when Win2k starts, but want it be a background
process (like a daemon). Anyone know how to do the equivalent to something
like "nohup process_name &" in win2k?
Thanks,
John L
------------------------------
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.
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 4319
***************************************