[19771] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1966 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 20 00:05:33 2001

Date: Fri, 19 Oct 2001 21:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1003550708-v10-i1966@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 19 Oct 2001     Volume: 10 Number: 1966

Today's topics:
    Re: \Z regexp behavior different with $& in program <nospam-abuse@ilyaz.org>
        Easy database questions (HSwan)
    Re: Easy database questions (Clinton A. Pierce)
    Re: Elegant Code - Indexing Letters (Martien Verbruggen)
    Re: File with Blank lins as seperator <c_clarkson@hotmail.com>
    Re: File with Blank lins as seperator <uri@sysarch.com>
    Re: Fork messes up parent file handle? (Joe Smith)
        Help decoding an encoded string from MySql with perl??? <ryan@tuitions.com>
        How to display text file in cgi-bin? <mail@mail.com>
    Re: How to display text file in cgi-bin? <tony_curtis32@yahoo.com>
    Re: lookingglass.pl (Tad McClellan)
    Re: lookingglass.pl (Martien Verbruggen)
        namespaceproblem gives me a headache <pilsl_@goldfisch.at>
    Re: namespaceproblem gives me a headache (Andre Malo)
        need Regular Expression help <brian@jankoNOnet.SPAMcom.INVALID>
    Re: need Regular Expression help <pilsl_@goldfisch.at>
    Re: need Regular Expression help <wyzelli@yahoo.com>
    Re: need Regular Expression help (Tad McClellan)
    Re: need Regular Expression help <flavell@mail.cern.ch>
    Re: need Regular Expression help <brian@jankoNOnet.SPAMcom.INVALID>
    Re: need Regular Expression help <dtweed@acm.org>
    Re: Perl remote communication - Is it tcp port, netbios <goldbb2@earthlink.net>
    Re: precedence question <goldbb2@earthlink.net>
    Re: regexp : "x or nothing" <wyzelli@yahoo.com>
    Re: regexp : "x or nothing" <pilsl_@goldfisch.at>
    Re: regexp : "x or nothing" (Tad McClellan)
    Re: regexp : "x or nothing" <wyzelli@yahoo.com>
    Re: sorting hash of hashes of hashes <goldbb2@earthlink.net>
    Re: Tar failure with Pipe Open... Oops! <whataman@home.com>
    Re: Tar failure with Pipe Open <whataman@home.com>
        Which is better????? <hkdennis2k@yahoo.com.hk>
    Re: Which is better????? <krahnj@acm.org>
    Re: Which is better????? (Clinton A. Pierce)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 20 Oct 2001 00:18:12 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: \Z regexp behavior different with $& in program
Message-Id: <9qqfs4$u2u$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Jason Secosky
<secosky@attglobal.net>], who wrote in article <64a73ed6.0110191122.51c961d7@posting.google.com>:
> Script #2:
> $match = "a\nb\n";
> $match =~ /a\Z/m;
> print ":$-[0]:$match\n";
> 
> Output:
> :0:a
> b
> 
> .  I don't believe the regular expression should find a match, but
> $-[0] being 0 in script #2 indicates that a match was found.

Does it?  I do not think that @- after an unsuccessful match should be
of any particular value.  In my testing the old value of @- preserved
after an unsuccessful match.

perl5.6.0 -wle '$_= "a\nb\n"; /b$/m or print 11; print $-[0]; /a\Z/ and print 12; print $-[0]'
2
2


> The thing I can't figure out is that the test for this in re_tests (line
> 540) is ignored when $& isn't in the code, so it's like this is a
> known issue.  Unfortunately I can't find anything saying why these two
> scripts would behave differently.  What am I missing?

Is the test marked as skipped-as-bug or what?

Ilya


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

Date: 19 Oct 2001 19:02:10 -0700
From: lanhws@expl.ak.ppco.com (HSwan)
Subject: Easy database questions
Message-Id: <3aeb5d59.0110191802.6f72ae55@posting.google.com>

If I do a dbmopen on Perl 5.6.1 without explicitly using any explicit
database package, what flavor of database am I getting?  (SDBM? NDBM?
DB_File?)

I plan to have different users and applications access my database,
but only
one user at a time will be allowed to open it.  I plan to enforce this
policy
through file locking.  Is this a safe approach, or is it prone to
database corruption?

By default, there seem to be two database files created:  a .dir file
and
a .pag file.  Do I need to lock just one of them, or both?

Thank you for reading this and for any replies you care to post.


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

Date: Sat, 20 Oct 2001 03:18:12 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Easy database questions
Message-Id: <U16A7.186523$K6.89343090@news2>

[Posted and mailed]

In article <3aeb5d59.0110191802.6f72ae55@posting.google.com>,
	lanhws@expl.ak.ppco.com (HSwan) writes:
> If I do a dbmopen on Perl 5.6.1 without explicitly using any explicit
> database package, what flavor of database am I getting?  (SDBM? NDBM?
> DB_File?)

Uhh.. use perl -d and one-step ("s") through a dbmopen().  It's an 
enlightening experience.  You'll get your answer and learn a whole
lot about dbmopen().   :)
 
> By default, there seem to be two database files created:  a .dir file
> and a .pag file.  Do I need to lock just one of them, or both?

Consider using a semaphore file as a lock:
	http://perl.plover.com/TPC/1998/Hardware-notes.html

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


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

Date: Sat, 20 Oct 2001 10:24:51 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Elegant Code - Indexing Letters
Message-Id: <slrn9t1h2j.5ep.mgjv@martien.heliotrope.home>

On Thu, 18 Oct 2001 23:38:09 GMT,
	Tad McClellan <tadmc@augustmail.com> wrote:
> David Filmer <iNeverReadAnythingSentToMe@hotmail.com> wrote:
> 
>>I
>>have NO IDEA what sort of syntax to use 
> 
> 
> See the "Auto-increment and Auto-decrement" section in perlop.pod.
> 
> ZZ => AAA in the below. Uncomment a line if you want ZZ => AA.
> 
> Sweet huh?  :-)
> 
> -------------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
> 
> $_ = 'AA';
> 
> for my $i ( 1..1000 ) {  # let's see a thousand increments
>    print "$_\n";
>    $_++;
> #   $_ = 'AA' if $_ eq 'ZZ';

I know this is conmented out, but it will not behave as intended when the
comment is removed.

$_ = 'AA' if $_ eq 'AAA';

Martien
-- 
                                | 
Martien Verbruggen              | The gene pool could use a little
                                | chlorine.
                                | 


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

Date: Fri, 19 Oct 2001 22:14:17 -0500
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: File with Blank lins as seperator
Message-Id: <tt1qv5psrfive2@corp.supernews.com>


"Uri Guttman" <uri@sysarch.com> wrote:
: >>>>> "JZ" == Jeff Zucker <jeff@vpservices.com> writes:
: 
:   JZ> Jeff Zucker wrote:
:   >> 
:   >> [snip]
: 
:   JZ> Or even simpler:
: 
:   JZ> my $records;
:   JZ> local $/ = "\n\n";
:   JZ> while (<DATA>) {
:   JZ>   my $row;
:   JZ>   for (split /\n/) {
:   JZ>       my($key,$value)=split /=/;
:   JZ>       $row->{$key} = $value;
:   JZ>   }
:   JZ>   push @$records, $row;
:   JZ> }
:   JZ> use Data::Dumper; print Dumper $records;
: 
: untested:
: 
: {
: local $/ = "\n\n";
: @records = map { { /^(.+)=(.+)$/gm } } <DATA> ;
: }
: 

    Andrew Johnson just wrote a nice article for the
itworld newsletter on Using the do-block:

my @records =
 do {
  local $/ = "\n\n";
  map { { /^(.+)=(.+)$/gm } } <DATA>;
 };


Of course really large files might do better with a
while block.


HTH,
Charles K. Clarkson
Clarkson Energy Homes, Inc.






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

Date: Sat, 20 Oct 2001 03:31:15 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: File with Blank lins as seperator
Message-Id: <x7ofn33s2b.fsf@home.sysarch.com>

>>>>> "CKC" == Charles K Clarkson <c_clarkson@hotmail.com> writes:

  CKC> "Uri Guttman" <uri@sysarch.com> wrote:
  CKC> : 
  CKC> : {
  CKC> : local $/ = "\n\n";
  CKC> : @records = map { { /^(.+)=(.+)$/gm } } <DATA> ;
  CKC> : }
  CKC> : 

  CKC>     Andrew Johnson just wrote a nice article for the
  CKC> itworld newsletter on Using the do-block:

  CKC> my @records =
  CKC>  do {
  CKC>   local $/ = "\n\n";
  CKC>   map { { /^(.+)=(.+)$/gm } } <DATA>;
  CKC>  };

great minds ...


  CKC> Of course really large files might do better with a
  CKC> while block.

no mention was made of the file size. and as i have mentioned here
before i like slurping files when i know i can.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


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

Date: Fri, 19 Oct 2001 22:12:11 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: Fork messes up parent file handle?
Message-Id: <9qq8fr$1jkn$1@nntp1.ba.best.com>

In article <3BD073A8.59553E8@brighton.ac.uk>,
John English  <je@brighton.ac.uk> wrote:
>I have a script which reads lines from a config file and forks off
>a seaparate child process for each line:

	$|++;		# Must flush output buffers whenever doing fork()

>  while (<IN>) {
>    $pid = fork;
>    if ($pid) {
>      &do_parent_stuff;
>    }
>    elsif (defined($pid)) {
>      &do_child_stuff;
>      last;

Those two lines should be
	close IN;		# Child has no business with this file handle
	&do_child_stuff;
	exit;			# Forked child needs to exit when done

>    }
>    else {
>      die "horribly";
>    }
>  }
>  close IN;
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Fri, 19 Oct 2001 17:27:58 -0600
From: "Ryan" <ryan@tuitions.com>
Subject: Help decoding an encoded string from MySql with perl???
Message-Id: <9qqcu3$775$1@news.xmission.com>

I need to know how to decode a string that I have encoded with MySql.

for example:
#encode
  $sql = "INSERT INTO users (Name, Password) VALUES('$username',
(encode('$pass1','rT')))";
  $rc = $DBH->do($sql);

output from encoding:
¼-|:l±r

What is the code for decoding??
I have tried:
$password1 = ("select decode($password,$passkey) from users where username =
'$username'");

I can decode it using MySql in telnet but I can't get it to work in Perl.
Any help would be great.

Ry




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

Date: Fri, 19 Oct 2001 21:55:46 -0500
From: Jerry McEwen <mail@mail.com>
Subject: How to display text file in cgi-bin?
Message-Id: <ggp1ttsppuvef1ofkpeijqf64q15mfpnnt@4ax.com>

I have a shopping cart several levels deep in my cgi-bin directory and
orders get written to a file in a sub-folder. We have SSL and I want
my client to be able to access orders.txt via https, but Perl (or
maybe the server's config?) prevents the file from being displayed.

My host tells me that I will have to get a script to display it, but I
can't find one. Any thoughts? Thanks!


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

Date: Fri, 19 Oct 2001 21:53:47 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: How to display text file in cgi-bin?
Message-Id: <873d4fyqbo.fsf@limey.hpcc.uh.edu>

>> On Fri, 19 Oct 2001 21:55:46 -0500,
>> Jerry McEwen <mail@mail.com> said:

> I have a shopping cart several levels deep in my cgi-bin
> directory and orders get written to a file in a
> sub-folder. We have SSL and I want my client to be able
> to access orders.txt via https, but Perl (or maybe the
> server's config?) prevents the file from being
> displayed.

> My host tells me that I will have to get a script to
> display it, but I can't find one. Any thoughts? Thanks!

Nowt to do with perl.

Try comp.infosystems.www.servers.misc

[ fup set ]

hth
t
-- 
Oh!  I've said too much.  Smithers, use the amnesia ray.


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

Date: Fri, 19 Oct 2001 22:27:28 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: lookingglass.pl
Message-Id: <slrn9t17in.v1c.tadmc@tadmc26.august.net>

Wilbert van Diemen / Rudy van Doorn <wilbert.van.diemen@hetnet.nl> wrote:

>"Can't use an undefined value as an ARRAY reference at LookingGlass.pl line
>278, <> chunk 1."
>
>On this line 278 is:
>
>my ($maxsub) = scalar(@{@local_files[1]}) -1;
>
>Anybody an idea?


$local_files[1] has the special undef value in it. It isn't supposed to.

I see three indicators of "rookie code" in that one line! 

I wouldn't trust that program much. It is very likely worth
less than you paid for it...


   1) does not enable warnings

   2) uses one-element array slice instead of direct access
      to the scalar (ie. should be $local_files[1], not @local_files[1])

   3) uses scalar(@array)-1 instead of $#array ( $#{$local_files[1]} )


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 20 Oct 2001 09:30:50 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: lookingglass.pl
Message-Id: <slrn9t1dta.5ep.mgjv@martien.heliotrope.home>

On Fri, 19 Oct 2001 23:43:57 +0200,
	Wilbert van Diemen / Rudy van Doorn <wilbert.van.diemen@hetnet.nl> wrote:
> Hi everybody,
> 
> Does anybody know a place on the net with information about lookingglass.pl,
> a perl-program that can automatically upload all the files in a directory
> (and the maps in this directory) on the basis of a conf-file.
> 
> I keep getting an error about:
> 
> "Can't use an undefined value as an ARRAY reference at LookingGlass.pl line
> 278, <> chunk 1."
> 
> On this line 278 is:
> 
> my ($maxsub) = scalar(@{@local_files[1]}) -1;

Don't use a program with code like this. If all of the code is like
this, I'm not surprised that you have an undefined value where you
shouldn't have one.

If your "upload all the files in a directory" uses FTP, then I suggest
that you get yourself the mirror.pl program. 

ftp://sunsite.org.uk/packages/mirror/

Martien
-- 
                                | 
Martien Verbruggen              | Make it idiot proof and someone will
                                | make a better idiot.
                                | 


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

Date: Sat, 20 Oct 2001 00:09:58 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: namespaceproblem gives me a headache
Message-Id: <3bd0a4b7$1@e-post.inode.at>


I have two modules and each of them require each other. So I end up with 
big problem that I dont understand .. (I expected it, but I dont understand 
it)
The following modules and testscript reproduces my problem. Of course m2 
isnt really needed in m1 in that test-modules but it shows the effect ...

---------------------
package test::m1;

require 5.005_62;
use strict;
use warnings;
use test::m2 qw(m2);

require Exporter;

our @ISA = qw(Exporter);
our @EXPORT_OK = qw(m1);
our @EXPORT = qw(m1);
our $VERSION = '0.01';

sub m1{return 'm1';};

1;
__END__
--------------------------
package test::m2;

require 5.005_62;
use strict;
use warnings;
use test::m1 qw(m1);

require Exporter;

our @ISA = qw(Exporter);
our @EXPORT_OK = qw(m2);
our @EXPORT = qw(m2);
our $VERSION = '0.01';

sub m2{
#  my $a=test::m1::m1();       # WORKS 
    my $a=m1();                   # DONT WORK
    return $a.'m2';
};

1;
__END__
--------------------------
#!/usr/local/bin/perl -w

use strict;
use test::m1 qw(m1);
use test::m2 qw(m2);

print m1(),"\n";
print m2(),"\n";
-------------------------

now I run the last testscript:
$./test.pl
m1
Undefined subroutine &test::m2::m1 called at /usr/lib/perl5/site_perl

I dont understand cause I imported m1 ...
All packages have their own namespace so there should be no collision even 
if the modules imports each other. I just import m1 from module m1 ...

my head is calming and maybe I dont see the obvious ...

thnx,
peter

-- 
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at



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

Date: 20 Oct 2001 01:09:04 GMT
From: ndparker@gmx.net (Andre Malo)
Subject: Re: namespaceproblem gives me a headache
Message-Id: <Xns9140212982F90ndparker@news.o3media.de>

* peter pilsl wrote in news:3bd0a4b7$1@e-post.inode.at:

> The following modules and testscript reproduces my problem. Of course
> m2 isnt really needed in m1 in that test-modules but it shows the
> effect ... 
[...]

first the solution. I restructured you sample packages:
=== cut ===
package test::m1;

use strict;
use warnings;

our (@EXPORT_OK, @EXPORT, $VERSION, @ISA);
BEGIN {
  require Exporter;
  @ISA = 'Exporter';
  @EXPORT_OK = qw(m1);
  @EXPORT = qw(m1);
  $VERSION = '0.01';
}

use test::m2 qw(m2);

sub m1{return 'm1';};

1;
__END__

test::m2 is done the same way.

What went wrong in your code?

in test.pl you 'use test::m1', that means:
BEGIN {
  require test::m1;
  test::m1->import(list);
}

test/m1.pm will be loaded and the first relevant statement is:
use test::m2 (which means BEGIN{...})

Perl stops interpreting of test/m1.pm at this point and handles your
'use'-statement. It loads test/m2.pm. The first interesting statement is:
use test::m1. 

And here is more or less the problem. m1.pm will not be loaded once more.
The code of m1.pm, which is known by perl at this time is:
=== cut ===
package test::m1;

require 5.005_62;
use strict;
use warnings;
use test::m2 qw(m2);
=== cut ===

there's *no* import method defined, and so perl doesn't import anything
by test::m1 at this time. By the way: 'm2' was not exported by test::m2,
too. 

However, I think, you should think over your design. If the modules
*require* each other, you should create *one* interface to both packages.
(i.e. test::m1 imports from test::m2 and exports test::m1-symbols *and*
test::m2-symbols; the main script imports only from test::m1) 

HTH,

nd
-- 
s;.*;aaaaaoaaaoaaaaooooaaoaaaomaaaa:a:alataa:aaoat:a:a:a
maoaa:a:laoata:a:oia:a:o:a:m:a:o:alaoooat:aaool:aaoaa
matooololaaatoto:aaa:o:a:o:m;;s:\s:\::g;y;mailto:;
\40\51/\134\137|"n.d.p."<nd@o3media.de>;;print;


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

Date: Fri, 19 Oct 2001 23:22:52 GMT
From: "Brian Janko" <brian@jankoNOnet.SPAMcom.INVALID>
Subject: need Regular Expression help
Message-Id: <gB2A7.813704$NK1.73333750@bin3.nnrp.aus1.giganews.com>

I'm using the following line of code to test for a invalid email address.

if ($_ !~ /^\w+@\w+(\.\w+){1,2}$/)

It seems to work pretty well, except that if there are any spaces in the
middle of the email address, it doesn't catch the address as a bad one.  I
don't mind if there are leading or trailing spaces, but I would like it to
recognize that, in addition to what I have, if there is a space in the
middle of the address, then the address is invalid.

Any ideas?

Thanks,
Brian Janko
brian@jankonet.com









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

Date: Sat, 20 Oct 2001 01:51:01 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: need Regular Expression help
Message-Id: <3bd0bc66$1@e-post.inode.at>

Brian Janko wrote:

> I'm using the following line of code to test for a invalid email address.
> 
> if ($_ !~ /^\w+@\w+(\.\w+){1,2}$/)
> 
> It seems to work pretty well, except that if there are any spaces in the
> middle of the email address, it doesn't catch the address as a bad one.  I
> don't mind if there are leading or trailing spaces, but I would like it to
> recognize that, in addition to what I have, if there is a space in the
> middle of the address, then the address is invalid.
> 

The above pattern does not match adresses with spaces ... \w does not match 
spaces. Your problem must be somewhere different.

perl -e '$a="ha ns\@h.at"; print "good\n" if $a=~/^\w+@\w+(\.\w+){1,2}$/';
perl -e '$a="hans\@h. at"; print "good\n" if $a=~/^\w+@\w+(\.\w+){1,2}$/';
 ...
none of this expression will trigger a output

please post more code and your perl-version.

anyway : your match will also mark "me@subsubsub.subsub.sub.top" as false 
and there are such adresses .... I would use {1,5} or something ...

hope this helps,
peter


-- 
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at



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

Date: Sat, 20 Oct 2001 09:49:12 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: need Regular Expression help
Message-Id: <T%2A7.4$qg2.228@wa.nnrp.telstra.net>

"Brian Janko" <brian@jankoNOnet.SPAMcom.INVALID> wrote in message
news:gB2A7.813704$NK1.73333750@bin3.nnrp.aus1.giganews.com...
> I'm using the following line of code to test for a invalid email address.
>
> if ($_ !~ /^\w+@\w+(\.\w+){1,2}$/)
>
> It seems to work pretty well, except that if there are any spaces in the
> middle of the email address, it doesn't catch the address as a bad one.  I
> don't mind if there are leading or trailing spaces, but I would like it to
> recognize that, in addition to what I have, if there is a space in the
> middle of the address, then the address is invalid.
>
> Any ideas?

I would disagree with that reported fault.  Maybe something else is causing
your problem.

Since the above regex matches alphanumerics plus _ from the beginning of the
string to an @ (shouldn't that be excaped in a regex?  maybe that's your
problem?) followed by two or three sets of alphanumerics (plus _ ) separated
by a period and then the end of string, there is no way a space can slip
through.

Can you perhaps show an example of an email address with a space in it which
fails the above test?

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: Sat, 20 Oct 2001 00:15:17 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: need Regular Expression help
Message-Id: <slrn9t1dkc.v5s.tadmc@tadmc26.august.net>

Brian Janko <brian@jankoNOnet.SPAMcom.INVALID> wrote:
>I'm using the following line of code to test for a invalid email address.
>
>if ($_ !~ /^\w+@\w+(\.\w+){1,2}$/)


So "tad.mcclellan@somewhere.com" is supposed to be invalid?

You are going to disallow lots of real and usuable addresses...


>It seems to work pretty well, 


It will accept invalid addresses.

It will reject valid addresses.

I wouldn't characterize that as "works pretty well", but
maybe that's just me.


>except that if there are any spaces in the
>middle of the email address, it doesn't catch the address as a bad one.  


Addresses with spaces in the middle are NOT "bad ones".

Spaces are legal in email addresses.

And the code you have shown cannot be doing what you say it
is doing. There is something else going on that you haven't
shared with us...


>Any ideas?


How about checking the Perl Frequently Asked Questions?

   perldoc -q mail

      "How do I check a valid mail address?"


Naw. That would be too easy.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 20 Oct 2001 02:21:03 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: need Regular Expression help
Message-Id: <Pine.LNX.4.30.0110200214420.32173-100000@lxplus023.cern.ch>

On Oct 19, Brian Janko inscribed on the eternal scroll:

> I'm using the following line of code to test for a invalid email address.
>
> if ($_ !~ /^\w+@\w+(\.\w+){1,2}$/)

Why are you doing that?  Don't you know that there's an FAQ?

What do you consider to be a "valid" email address?  There is, after
all, a formal specification.  Most so-called email address validators
are known (check the faqs) to reject some valid email addresses.  All
so-called email address validators pass some addresses that won't, in
fact, reach anyone (they could be syntactically valid, but
deliberately directed into a bit-bucket, for the recipient's own good
reasons).

What, actually, do you count as a 'valid' email address?  If you could
answer that question, you probably wouldn't need our advice.



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

Date: Sat, 20 Oct 2001 01:56:16 GMT
From: "Brian Janko" <brian@jankoNOnet.SPAMcom.INVALID>
Subject: Re: need Regular Expression help
Message-Id: <4R4A7.75047$%B.5905591@bin1.nnrp.aus1.giganews.com>

I just found the spot in my code where I am allowing the spaces through, so
the problem has becoem a moot point.

However,  you bring up a good point.  I did not know there was an "official"
standard for valid email addresses.  Where would I find that spec?  I would
be very interested.

Thanks everyone for your help.

-- Brian





"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
news:Pine.LNX.4.30.0110200214420.32173-100000@lxplus023.cern.ch...
> On Oct 19, Brian Janko inscribed on the eternal scroll:
>
> > I'm using the following line of code to test for a invalid email
address.
> >
> > if ($_ !~ /^\w+@\w+(\.\w+){1,2}$/)
>
> Why are you doing that?  Don't you know that there's an FAQ?
>
> What do you consider to be a "valid" email address?  There is, after
> all, a formal specification.  Most so-called email address validators
> are known (check the faqs) to reject some valid email addresses.  All
> so-called email address validators pass some addresses that won't, in
> fact, reach anyone (they could be syntactically valid, but
> deliberately directed into a bit-bucket, for the recipient's own good
> reasons).
>
> What, actually, do you count as a 'valid' email address?  If you could
> answer that question, you probably wouldn't need our advice.
>
>




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

Date: Sat, 20 Oct 2001 03:59:19 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: need Regular Expression help
Message-Id: <3BD0F532.6C8805EC@acm.org>

Brian Janko wrote:
> However,  you bring up a good point.  I did not know there was an "official"
> standard for valid email addresses.  Where would I find that spec?  I would
> be very interested.

It's called RFC822. Any search engine should be able to dig up a copy for you.

-- Dave Tweed


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

Date: Fri, 19 Oct 2001 23:53:21 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl remote communication - Is it tcp port, netbios or what?
Message-Id: <3BD0F531.1AE088DD@earthlink.net>

Alessandro Augusto wrote:
[snip stuff about controlling the tcp connection Win32::TieRegistry uses
when making a connection to a remote machine]
> My goal is, how can i specify always the same port on the computer
> where I execute the script? That way, i know that traffic from port
> xxx to port 445 is always the perl traffic of my script.
> 
> where do i specify that? I looked at the code of tieregistry.pm, but
> didn't find anything yet. Any ideia?

It's entirely possible that *perl* doesn't do it at all.  It may simply
use some Win32 library function to 'connect' to a remote machine.

If that's the case, haul yourself over to a Win32 newsgroup, and ask
"How does the XXX library function connect to the registry of a remote
machine, and how can I control the port number of the tcp connection of
that connection?"

Then, armed with that information, you accost the author of the module
to add the functionality you desire.

> > You might have better luck if you phrase your question,
> > "How does Win32::TieRegistry connect to remote systems?".
> > Perl can use many different mechanisms to talk to remote
> > systems, and it's only how Win32::TieRegistry works that
> > interests you.

-- 
"What does stupid old man mean pidgin talk?
Shampoo does not talk like a bird."


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

Date: Fri, 19 Oct 2001 23:44:36 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: precedence question
Message-Id: <3BD0F324.D5E662C1@earthlink.net>

Joe Schaefer wrote:
[snip order of evauation]
> 
> FWIW, the only thread I could find with Larry Wall's opinion on
> the order of evaluation in an otherwise undocumented case is here
> (unwrapped url):
> 
> http://www.xray.mpe.mpg.de/cgi-bin/w3glimpse2html/perl5-porters/1997-12/msg00107.html?61#mfs

Except that that thread is about the fact that one of pre/post inc
returns a copy of the thing incremented, and the other returns an alias
to it... NOT about what should happen in what order.

-- 
"What does stupid old man mean pidgin talk?
Shampoo does not talk like a bird."


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

Date: Sat, 20 Oct 2001 09:55:48 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: regexp : "x or nothing"
Message-Id: <363A7.5$qg2.436@wa.nnrp.telstra.net>

"peter pilsl" <pilsl_@goldfisch.at> wrote in message
news:3bd0ba36$1@e-post.inode.at...
>
> To parse a weird string I need the following statement
>
> $permstring=~/(^|,)A:\((\d*-|)$_(-|\))/;
>
> This should check if a string of the form  A:(x1-x2-x3) contains $_, where
> x1,x2... are integers (with 1 to 5 digits) and there can be zero to
> infinite values.
> My construct above works well, but it just hit me that my contruct
> "(\d-|)" could be somehow inviting troubles. Or do I just underestimate
> perl ...  I didnt find any mention of this 'or nothing' in man perlre.
>
> thnx,
> peter
>
> ps: today is not the day to raise my selfestimee as perl-programmer. This
> is the second question if have to post here ....

Heh, I have those all the time, usually followed by some degree of
enlightenment.

Isn't 'this or nothing' logically equivalent to 'zero or 1' therefore simply
making that an optional match?

$permstring=~/(^|,)A:\((\d*-)?*$_(-|\))/;

unless I am missing something...

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: Sat, 20 Oct 2001 02:13:37 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: regexp : "x or nothing"
Message-Id: <3bd0c1b3$1@e-post.inode.at>

Wyzelli wrote:

> 
> Isn't 'this or nothing' logically equivalent to 'zero or 1' therefore
> simply making that an optional match?
> 
> $permstring=~/(^|,)A:\((\d*-)?*$_(-|\))/;
> 
> unless I am missing something...
> 

dammned .. awkward .. I knew there was something wrong with this 'or 
nothing'-construction but I didnt think in logical terms, only in perl-terms
(never want to say that perl isnt logical ;)
Think its time to go to bed ..

thnx for the enlightment ...
best,
peter

-- 
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at



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

Date: Sat, 20 Oct 2001 00:28:23 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regexp : "x or nothing"
Message-Id: <slrn9t1ejv.v7k.tadmc@tadmc26.august.net>

peter pilsl <pilsl_@goldfisch.at> wrote:
>Wyzelli wrote:
>
>> 
>> Isn't 'this or nothing' logically equivalent to 'zero or 1' therefore
>> simply making that an optional match?
>> 
>> $permstring=~/(^|,)A:\((\d*-)?*$_(-|\))/;
                                    ^^^^^^

and that looks like it should be a character class:

   ([-)])

I hate backslashes.

Something isn't right with that (\d*-)?* part. Is that an extra asterisk?


I think    (\d+-)?   or (\d{1,5}-)?  would be better.


>Think its time to go to bed ..

Nighty night. 

sleep(28800);   :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 20 Oct 2001 10:37:06 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: regexp : "x or nothing"
Message-Id: <NI3A7.6$qg2.498@wa.nnrp.telstra.net>

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9t1ejv.v7k.tadmc@tadmc26.august.net...
> peter pilsl <pilsl_@goldfisch.at> wrote:
> >Wyzelli wrote:
> >
> >>
> >> Isn't 'this or nothing' logically equivalent to 'zero or 1' therefore
> >> simply making that an optional match?
> >>
> >> $permstring=~/(^|,)A:\((\d*-)?*$_(-|\))/;
>                                     ^^^^^^
>
> and that looks like it should be a character class:
>
>    ([-)])
>
> I hate backslashes.
>
> Something isn't right with that (\d*-)?* part. Is that an extra asterisk?

How did that sneak in - ( I know - I played with * for zero or more before I
remembered that ? meant 0 or 1, and mustv'e missed that in the re-edit
before my cut and paste.  My oops.

> I think    (\d+-)?   or (\d{1,5}-)?  would be better.
>
>
> >Think its time to go to bed ..

I just got up from bed... :)

> Nighty night.
>
> sleep(28800);   :-)

Time for some carbs I think!

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: Fri, 19 Oct 2001 23:36:43 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: sorting hash of hashes of hashes
Message-Id: <3BD0F14B.DADF7441@earthlink.net>

g wrote:
> 
> Hi,
> 
> I'm trying to sort a hash of hashes...of hashes by the last (3rd key)
> and also sort by value.
> 
> For example,
> $test{'a'}{'hey'}{'1'} = 20;
> $test{'a'}{'ouch'}{'4'} = 23;
> $test{'a'}{'zippy'}{'7'} = 21;
> $test{'b'}{'zippy'}{'3'} = 21;
> $test{'b'}{'zippy'}{'6'} = 26;

I would suggest you flatten your structure just a bit:

my @flattened;
while( my ($one_k, $one_v) = each %test ) {
    while( my ($two_k, $two_v = each %$one_v ) {
        while( my ($three_k, $three_v) = each %$two_v ) {
            push @flattened => [$one_k, $two_k, $three_k, $three_v];
        }
    }
}

print "By third key:\n";
print "[@$_]\n" for sort { $a->[2] <=> $a->[2] };
print "By value:\n";
print "[@$_]\n" for sort { $a->[3] <=> $a->[3] };

-- 
"What does stupid old man mean pidgin talk?
Shampoo does not talk like a bird."


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

Date: Sat, 20 Oct 2001 01:55:00 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Tar failure with Pipe Open... Oops!
Message-Id: <3BD0D98A.8D3891CA@home.com>

[correction]

> That's Tad favorite saying.:) Anyway, I was afraid someone would ask
> that. I tried something like   if (-z <TEST>) { print "FAILURE" }  and it
> always failed. I probably have the syntax wrong.

> Best regards,
> --Dennis


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

Date: Sat, 20 Oct 2001 01:52:18 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Tar failure with Pipe Open
Message-Id: <3BD0D8E7.5FDA8374@home.com>

Benjamin Goldberg wrote:
>  
> BUCK NAKED1 wrote:
> >
> > I had forgot that Ben recommended using a pipe for testing tar.
> 
> I mentioned it was possible, I didn't *recommend* it.

Sorry, bad choice of words. I should've said "suggested" it.
> 
> > He also recommended using a filetest operator, but I couldn't get that
> > to work.
> 
> What do you mean when you say that it didn't work?

That's Tad favorite saying.:) Anyway, I was afraid someone would ask
that. I tried something like   if (-z TEST>) { print "FAILURE" }  and it
always failed. I probably have the syntax wrong.
  
> > I decided to just test success based on retrieving a list of
> > files (-t) and later exec tar based on that. Is the coding below OK?
> > It seems to work.
> >
> > open( TEST, "tar -ztf $tmpfile |" );
> >   if ( <TEST> eq "" )  {
> >      print "Tar TEST Failed!\n";
> >      close TEST; exit;
> > };
> 
> Sure, I guess it may work, but it doesn't give you the ability to
> seperately learn the success or failure of the gunzip and tar
> operations.

I understand. I had a feeling, that I would need to separate the
procedures and do the gunzip separately. I guess that's the difference
between my elementary code and your collegiate example. :)

> The way *I* would do it, would be:
> 
> use IPC::Open2;
> 
> open( TMPFILE, "<$tmpfile" )
>     or die "Couldn't open $tmpfile for reading: $!";
> 
> my $g_pid = open2(FROM_GUNZIP, "<&TMPFILE", "gunzip", "-c", "-d");
> my $t_pid = open2(FROM_TAR, "<&FROM_GUNZIP", "tar", "tf", "-");
> 
> if( my @tar_output = <FROM_TAR> ) {
>    print "Success!  The tar file contains the following:\n";
>    print @tar_output;
> } else {
>    print "Failure!\n";
>    print "Either the tar file empty, or something screwed up.\n";
> }
> 
> if( waitpid $g_pid, 0 ) {
>     my ($sig, $ret) = ($? & 255, $? >> 8);
>     die "gunzip died from signal $sig" if $sig;
>     die "gunzip exited with code $ret" if $ret;
> } else {
>     die "Somebody musta reaped my gunzip process: $!";
> }
> 
> if( waitpid $t_pid, 0 ) {
>     my ($sig, $ret) = ($? & 255, $? >> 8);
>     die "tar died from signal $sig" if $sig;
>     die "tar exited with code $ret" if $ret;
> } else {
>     die "Somebody musta reaped my tar process: $!";
> }
> 
> END: {
>     kill SIGKILL => $g_pid, $t_pid;
> }
> __END__
> 
Looks great. Why am I getting "gunzip exited with code 1 at
/home/public_html/untarpost.cgi line 49, <FROM_TAR> chunk 10?"
 ... and do I really need that END block?

Best regards,
--Dennis


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

Date: Sat, 20 Oct 2001 10:22:31 +0800
From: "Dennis" <hkdennis2k@yahoo.com.hk>
Subject: Which is better?????
Message-Id: <9qqmp1$gon2@rain.i-cable.com>

while($data=substr($string,0,1,'')){
    ## something.........
}

while($string=~s/(.)//){
 $data=$1;
  ## something......
}


-- 
Dennis
======
Homepage(chinese)
    http://hkdennis2k.virtualave.net



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

Date: Sat, 20 Oct 2001 03:09:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Which is better?????
Message-Id: <3BD0EB6D.D1AD2D7A@acm.org>

Dennis wrote:
> 

Define "better".

> while($data=substr($string,0,1,'')){
>     ## something.........
> }
> 
> while($string=~s/(.)//){
>  $data=$1;
>   ## something......
> }

for my $data ( split //, $string ) {
    ## something.......
    }


John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 20 Oct 2001 03:15:25 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Which is better?????
Message-Id: <h%5A7.186520$K6.89339043@news2>

[Posted and mailed]

In article <9qqmp1$gon2@rain.i-cable.com>,
	"Dennis" <hkdennis2k@yahoo.com.hk> writes:
> while($data=substr($string,0,1,'')){
>     ## something.........
> }
> 
> while($string=~s/(.)//){
>  $data=$1;
>   ## something......
> }

Define "better".

Faster?  Readable?  Fewer side-effects?  Golf score?  Smaller
failure rates?

PS: They DON'T do the same thing.  Consider what /./ matches.  :)

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


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

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 1966
***************************************


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