[21694] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3898 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 2 06:05:53 2002

Date: Wed, 2 Oct 2002 03:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 2 Oct 2002     Volume: 10 Number: 3898

Today's topics:
        Can't instantiate Net::SMTP on remote host --bad file d <jim.bloggs@eudoramail.com>
    Re: Connecting to Excel (James Willmore)
    Re: Convert Perl script to C program (and Why was this  <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Downloading from a www server: Problem <nobody@nowhere.com>
    Re: Floating point question <Tassilo.Parseval@post.rwth-aachen.de>
    Re: How can I count files in a directory? <nospam@nospam.com>
    Re: How can I count files in a directory? <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: How would you... THANKS ALL! <s.DONTwarhurstSPAM@rl.ac.MEuk>
        I found a cool HACKER COMMUNITY site.  Come hurry and b jaydawg@yahoo.com
        I got it. Use Win32::OLE <Crackhead@mensa.org>
        ignore case in Greek <aragorn@freemail.gr.gr>
    Re: Performance burden in modularization ? <mike_constant@yahoo.com>
    Re: Performance burden in modularization ? <flavell@mail.cern.ch>
    Re: reading Cobol PIC 9(6)V99 formats... <jim.bloggs@eudoramail.com>
    Re: reading Cobol PIC 9(6)V99 formats... (Villy Kruse)
    Re: reading Cobol PIC 9(6)V99 formats... (James Willmore)
    Re: reading Cobol PIC 9(6)V99 formats... <bigj@kamelfreund.de>
        Search Patterns <reid@surfline.ne.jp>
    Re: Search Patterns <bigj@kamelfreund.de>
    Re: Search Patterns <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Search Patterns <Tassilo.Parseval@post.rwth-aachen.de>
        Send email from a Database Management Script (Dave)
    Re: Send email from a Database Management Script <postmaster@localhost.localdomain>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 2 Oct 2002 06:08:38 +0100
From: "doofus" <jim.bloggs@eudoramail.com>
Subject: Can't instantiate Net::SMTP on remote host --bad file descriptor
Message-Id: <andv0n$dc0o8$1@ID-150435.news.dfncis.de>

hi,

I honestly don't know whether I should be asking this here or not. Feel
free to shoo me away if there's a better place. Here's the problem.

On a remote host, I can't instatiate Net::SMTP.
Throught telnet, I *can* access the smtp server on port 25.

The code works fine on localhost using my personal smtp server.

The error i'm getting is "Bad file descriptor".

I suspect port 25 may be blocked. How could I test.

--
I very much hope you can be of some assistance..
Perhaps thankyou is a little premature,
Doofus




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

Date: 2 Oct 2002 01:50:51 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: Connecting to Excel
Message-Id: <e0160815.0210020050.1b0e27da@posting.google.com>

> 1) Can I connect to an exiting Excel Spreadsheet? If so how? Which 
> modules would I need?

WIN32::OLE or Spreadsheet::ParseExcel.  You may want to double check
me on the second (http://search.cpan.org/ - search for Excel).  In the
case of WIN32::OLE, the author puts a rather nice example in the POD
for parsing spreadsheets.

> 2) Can I use SQL statements in PERL to query the spreasheet or is it 
> easier to use some other method?

Ditto.  There's a DBI module to parse Excel spreadsheets.

As far as which would be better - if you have a set location in A
spreadsheet, then using WIN32::OLE on a Windoze box
(Spreadsheet::ParseExcel for other platforms) is just right.  Unless
you're going to use the spreadsheet like a data source, you're better
off sticking with just parsing the spreadsheet.

HTH

Jim


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

Date: Wed, 2 Oct 2002 07:15:50 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Convert Perl script to C program (and Why was this group's name changed?)
Message-Id: <slrnapl76h.1bi.bernard.el-hagin@gdndev25.lido-tech>

In article <rhpm9.980$Ry1.113925375@newssvr14.news.prodigy.com>,
 .Fredo wrote:
> 
> "Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
> news:Pine.LNX.4.40.0210012321240.4865-100000@lxplus074.cern.ch...
>>
>> On Oct 1, .Fredo replied to Tad:
>>
>> [far too much for comfort]
>>
>> > > Do you see any irony there?
>> >
>> > Not really. In your short little reply, you had little to offer, but
> a
>> > misleading reply (to the OP mainly). I seemed like just another one
> of
>> > your rude posts, and you ending here does little persuade otherwise.
>>
>> I could see this coming.  A well-earned killfile entry.  Please
>> don't change your posting address.
> 
> As usual you happen to perfectly avoid the issue, that happens spans way
> passed what you quoted. Actually you've put a new low on "little to
> offer". But then again, you, Tad are saint, rgiht? Sorry I forgot.


Do you not understand the concept of a killfile? Neither Tad nor Alan
can see your replies, so why bother?


Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: Wed, 2 Oct 2002 14:12:21 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: Downloading from a www server: Problem
Message-Id: <Eeum9.44312$g9.126931@newsfeeds.bigpond.com>


develop@gistenson.com wrote in message ...
>Tab and Alan,
>
>I'll try again.
>
>I'm developing a web site, not client-side software. The web site needs to
>transfer files from it to the client.
>
>Alan, you're solution, using an anchor, is fine for downloading one file,
>but I'm interested in a shopping cart application: A user, via his
>browser, selects the items he wants to buy by clicking on a picture of
>each item he intends to buy. This causes the item to be added to his
>shopping cart. When the user has picked all of the items he wants to buy,
>he clicks on a link, call it:
>
><a href="checkout.cgi">checkout</a>
>
>The script checkout.cgi is the script of interest here and needs to do the
>following:
>1. Initiate the credit card processing (No help needed here.)
>2. Download to the user all of the purchased items. (The items are all
>binary files.)
>
>The LWP documentation appears to say that LWP's purpose is at the machine
>at the "receiveing" end of a file transfer. (ie. get, getprint and
>getstore.) Am I wrong? I need something like putstore.
>
>I'm looking for guidance with the second of the above two "checkout"
>steps.
>
>Thanks,
>Dan
>

You need a standard cgi form and a submit button.

gtoomey




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

Date: 2 Oct 2002 06:51:24 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Floating point question
Message-Id: <ane51c$md6$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Eric J. Roode:

> "J" <<A@B>> wrote in news:upjooeq5n8egf0@corp.supernews.com:

>> I like to use perl to test functions that I am going to write in
>> another langauge where integers and string are different data types.
> 
> That's really really silly.

Not necessarily. I am currently doing something in Java involving lots of
bitwise operations (left/right shifts, ORing etc). In order to test
those I let Perl compute the expressions since Java hasn't got
one-liners. It's quite helpful really.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: Tue, 1 Oct 2002 22:45:47 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: How can I count files in a directory?
Message-Id: <3d9a8785$1_1@nopics.sjc>


"Rubber Duck" <rubberducky703@hotmail.com> wrote
> Is their a module or a method in a perl module which will scan a top level
> directory and count the number of files in each of the folders/directories
> below it?
>
> I also need to check for the file index.html in each folder, any
> package/method which allows this would be ideal.
>
> Essentially, all I need is just a list of directory names and a number
> indicating the number of files in that specific folder.
>
And if you hate using CPAN modules for a little/simple task like myself ;-)
, you could roll one for yourself.

[untested code, not much error checking]

sub count_files
{
    my $from    = shift;
    my $dirs     =  0;
    my $inds    = 0;
    my $files    = 0;
    my @list     = ();

    -e $from && -d $from or die "amigo, $from doesn't exist or isn't a
directory\n";
    opendir(DH, $from) or die "amigo, problemo with openning $from: $!\n";
    @list = map { "$from/$_ } grep !/^\./, readdir DH;
    closedir DH;

    while (my $entry = shift @list) {
          if (-d $entry) {
                $dirs++;
                opendir(DH, $entry) or die "amigo, you know the trend....:
$!\n";
                push @list, map { "$entry/$_" } grep !/^\./, readdir DH;
                closedir DH;
                next;
          }
          $entry =~ /index.html$/i ? $inds++ : $files++;
    }

    return ($dirs, $files, $inds);
}

#########
## main

my ($dirs, $files, $indices) = count_files("/pooh/tigger/piglet");

print "Number of directories: $dirs\n";
print "Number of files that arenot index.html: $files\n";
print "Number of index.html files: $inds\n";




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

Date: Wed, 2 Oct 2002 07:07:12 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: How can I count files in a directory?
Message-Id: <slrnapl6mb.1bi.bernard.el-hagin@gdndev25.lido-tech>

In article <3d9a8785$1_1@nopics.sjc>, Tan Nguyen wrote:
> 
> "Rubber Duck" <rubberducky703@hotmail.com> wrote
>> Is their a module or a method in a perl module which will scan a top level
>> directory and count the number of files in each of the folders/directories
>> below it?
>>
>> I also need to check for the file index.html in each folder, any
>> package/method which allows this would be ideal.
>>
>> Essentially, all I need is just a list of directory names and a number
>> indicating the number of files in that specific folder.
>>
> And if you hate using CPAN modules for a little/simple task like myself ;-)
> , you could roll one for yourself.


File::Find is a standard module shipped with Perl.


> [untested code, not much error checking]


That's one reason not to "roll one yourself".


> sub count_files
> {
>     my $from    = shift;
>     my $dirs     =  0;
>     my $inds    = 0;
>     my $files    = 0;
>     my @list     = ();
> 
>     -e $from && -d $from or die "amigo, $from doesn't exist or isn't
> a directory\n";
>     opendir(DH, $from) or die "amigo, problemo with openning $from: $!\n";
>     @list = map { "$from/$_ } grep !/^\./, readdir DH;
                                     ^^^^^^

So *anything* beginning with a '.' is ignored? Are you sure that's
correct? That's another reason not to "roll one yourself".


>     closedir DH;
> 
>     while (my $entry = shift @list) {
>           if (-d $entry) {
>                 $dirs++;
>                 opendir(DH, $entry) or die "amigo, you know the
> trend....:$!\n";


The stupid error messages is yet another reason not to "roll one
yourself". Probably the best reason, as far as I'm concerned.


>                 push @list, map { "$entry/$_" } grep !/^\./, readdir DH;
>                 closedir DH;
>                 next;
>           }
>           $entry =~ /index.html$/i ? $inds++ : $files++;
>     }
> 
>     return ($dirs, $files, $inds);
> }



Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: Wed, 2 Oct 2002 10:55:28 +0100
From: "Bigus" <s.DONTwarhurstSPAM@rl.ac.MEuk>
Subject: Re: How would you... THANKS ALL!
Message-Id: <anefqg$13jo@newton.cc.rl.ac.uk>

"David Gethings" <dgething@eu.uu.net> wrote in message
news:3d99966d$0$8506$cc9e4d1f@news.dial.pipex.com...

> > if($string =~ /I like [cats|dogs]/){}
> This too will match the above strings, but will also match:
>
> I like acst
> I like dgos

hehe, I see what you mean. oops!

> > @strings = ("I like cats and my name is Fred","I like dogs and my name
is
> > George");
> >
> > foreach $string(@strings)
> > {
> >   @name = $string =~ /I like (cats|dogs) and my name is (\w+)/;
> >   print "$name[1]\n";
> > }
> use ?: which is used for grouping without making backreferences. So the
> above regex becomes /I like (?:cats|dogs) and my name is (\w+)/. That way
> only the first element of the array @name is set.

That works perfectly. In the Rex Swain's HTMLified Perl Ref Guide that I
sometimes use, it says:

?:    Alternation (if-then-else) operator

Not alot of help that description & certainly wouldn't have led me to the
conclusion that it's used for grouping without making backreferences. I
think there must be a lot of things in Perl, like ?:, that could be really
useful but that I am not aware of. Must do some more reading!

> You seems to have a resonably good jist of regex's so I suggest you read
> perlre (you can use 'perldoc perlre' from the command line to do this). Or
> if you're more inclined to pay for your learning buy Mastering Regular
> Expressions, which covers regexs into great depth and has a section just
for
> Perl's regex implimentation.

Good idea. thanks :)

Bigus




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

Date: Wednesday, 02 Oct 2002 03:07:40 -0600
From: jaydawg@yahoo.com
Subject: I found a cool HACKER COMMUNITY site.  Come hurry and be the first members to join.  
Message-Id: <02100203.0740@yahoo.com>

Yeah i was looking on the net today and found this cool site that needs to be populated.  Its a message forum community for hackers and stuff.  They got forums for all kind of security and even some for free xxx password cracks and stuff.  Anways come check it out.  The address is www.teencyberlink.com


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

Date: Wed, 02 Oct 2002 06:11:50 GMT
From: Crackpot <Crackhead@mensa.org>
Subject: I got it. Use Win32::OLE
Message-Id: <Xns929AEBF539E04Crackheadmensaorg@204.127.68.17>

I figured it out

use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;                                # die on errors...
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')|| 
Win32::OLE->new('Excel.Application', 'Quit');  # get already active Excel
                                                      # application or 
open new
my $Book = $Excel->Workbooks->Open("C:\test.xls");    # open Excel file
my $Sheet = $Book->Worksheets(1);           # select worksheet number 1


Thanks guys for the help, let me know if there is something I missed.

cp <cpryce@pryce.nospam.net> wrote in
news:011020022233576203%cpryce@pryce.nospam.net: 

> In article <3D99EAC9.4020801@attbi.com>, Kenny Low <jlow1@attbi.com>
> wrote:
> 
>> I'm trying to connect to an existing Excel spreadsheet. In the 
>> spreadhseet there are 3 columns of interest to me. I'd like to have 4
>> variables (3 for columns A,B,C and one for the current row) that I
>> would use in a loop to extract data. Everything I've seen so far
>> creates a new spreadsheet so here are my questions.
>> 
>> 1) Can I connect to an exiting Excel Spreadsheet? If so how? Which 
>> modules would I need?
>> 
>> 2) Can I use SQL statements in PERL to query the spreasheet or is it 
>> easier to use some other method?
> 
> Often when the question is "how do I do X" or "what module do I use to
> do X" the answer can be found on the CPAN archive (at www.cpan.org or
> search.cpan.org). 
> 
> If you want to use SQL on the Spreadsheet you might have a look at
> DBD::Excel. 
> 
> Spreadsheet::WriteExcel also has an extension called
> Spreadsheet::WriteExcel::FromDB, but you can't query existing values
> from WriteExcel. 
> 
> Search the perl.dbi.users mailing list at
> http://groups.google.com/groups?group=perl.dbi.users for other
> solutions.
> 



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

Date: Wed, 2 Oct 2002 12:16:32 +0300
From: "aragorn" <aragorn@freemail.gr.gr>
Subject: ignore case in Greek
Message-Id: <anedhf$af6$1@nic.grnet.gr>

I am trying to create a search form and i have problems with the "i"
switch in the regular expression statement. The problem is that it
doesn't work with Greek, propably will not work with any other
language.
I use the following command

if ($op1 =~ /$searchstr/i)
{
# code goes here
}

as i said it works fine with English but not with Greek. I try to find
a perl way to do the job and not do it myself with a convert sub.

Anybody help please replay here




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

Date: Tue, 1 Oct 2002 22:04:13 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: Performance burden in modularization ?
Message-Id: <3d9a7dc7$1_5@nopics.sjc>

"Tad McClellan" <tadmc@augustmail.com> wrote

> If they are Real Modules, then they will be read at _compile_ time
> via "use", yes?

What are "Real Modules"?  You can always have options to dynamically load
modules accordingly to your needs. "eval" would be helpful in these
situations.

> > Is there much of an overhead in reading these modules from
> > disk
>
> The difference is reading a thousand lines from one file vs.
> reading a thousand lines spread over several files?
>
> Is that what you're asking about?
>
> If so, then the difference is not worth worrying about.

Not mentioning the fact that most of modern OSes implement some sort of file
caching mechanism which makes IO stuff less expensive.

But the question is if you already know mod_perl, why bother with CGI? With
mod_perl, once you load a module into memory, you don't have to re-load it
from disk next time you try to "use" it.




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

Date: Wed, 2 Oct 2002 11:35:43 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Performance burden in modularization ?
Message-Id: <Pine.LNX.4.40.0210021123500.11776-100000@lxplus076.cern.ch>

On Oct 1, Newbie inscribed on the eternal scroll:

> But the question is if you already know mod_perl, why bother with CGI?

CGI is almost universally supported: a CGI-based solution can be very
portable. (Well, modulo the fact that MS seems incapable of supporting
any open-specified software interface properly - sometimes they even
document their brokenness and claim it as a benefit, and this is one
such case - but if you're condemned to use one of their servers, I
doubt that mod_perl is going to help you.  OK, I digress.)

> With
> mod_perl, once you load a module into memory, you don't have to re-load it
> from disk next time you try to "use" it.

If your priority is raw efficiency, you wouldn't choose CGI -
fairynuff.  But portability has considerable value in a fast-moving
world, whereas, for the most part, if you run out of steam on CPU
cycles you can just throw more CPU at it.

Remember, rules 1 and 2 of optimisation are "don't optimise yet".

-- 




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

Date: Wed, 2 Oct 2002 06:02:26 +0100
From: "doofus" <jim.bloggs@eudoramail.com>
Subject: Re: reading Cobol PIC 9(6)V99 formats...
Message-Id: <andul4$dja20$1@ID-150435.news.dfncis.de>

Jim Agnew wrote:
> People, subject says it all,
>
> on a VMS system, try to read a Cobol PIC 9(6)V99 formats...
>
> I'm a newbie trying to redo an accounting system from Cobol to
> something a little bit less unwieldy...  ;-)
>
> so the question is how can Perl read that stuff? I think I'm wading
> thru most else ok,
> just time and beating my head on the books...
>
It depends whether it's comp-3 or not. If it is, it's packed decimal,
two digits to a byte. If it isn't, it's just straight digits, all eight
of them, right justified, most likely zero-filled.

Examples.

00003400  maps to 34
00000034  maps to 0.34
10000000 maps to 100,000

How about reading the digits as a string and then dividing by 100. Ah,
if only cobol were that simple.

Good luck!

PS. If it's straight comp, it's binary, machine dependent, you're on
your own. Hope that helps.

doofus




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

Date: 02 Oct 2002 08:01:31 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: reading Cobol PIC 9(6)V99 formats...
Message-Id: <slrnapl9ur.dqi.vek@pharmnl.ohout.pharmapartners.nl>

On Tue, 01 Oct 2002 16:06:21 -0400,
    Jim Agnew <jpagnew@vcu.edu> wrote:


>People, subject says it all,
>
>on a VMS system, try to read a Cobol PIC 9(6)V99 formats...
>
>I'm a newbie trying to redo an accounting system from Cobol to something
>a little bit less unwieldy...  ;-)
>

Just be aware that COBOL is about the only widely used language which
supports fixed point decimal numbers.  In most other languages you must
do all calculations in cents using integer numbers and only inserver
the decimal point when amounts is printed.  Doing these calculations
in floating point dollar values will give different rounding results,
which will chock some accountants.





Villy


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

Date: 2 Oct 2002 01:42:28 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: reading Cobol PIC 9(6)V99 formats...
Message-Id: <e0160815.0210020042.5934f6e2@posting.google.com>

> on a VMS system, try to read a Cobol PIC 9(6)V99 formats...

Perl and COBOL are two VERY different languages.  In this statement,
if you have a number greater than 8 digits, your data is truncated -
period.  You could use a regular expression to accomplish something
similar, but not identical to the COBOL statement.  Perl does not
automatically truncate as COBOL does.  Nor does it automatically
observe the decimal place as COBOL does. You have to code for such
things in Perl.

> I'm a newbie trying to redo an accounting system from Cobol to something
> a little bit less unwieldy...  ;-)

In this situation, I'd have to fall back on the old saying - "if it
ain't broke, don't fix it".  That's why COBOL programmers are paid the
salaries they are paid - because the code written 20+ years ago work
and it ain't broke.

HOWEVER, if you see there's a need to get rid of the VMS systems in
your shop,  or want non-COBOL programmers to understand the accounting
system and have the time to do it, converting from COBOL to Perl may
be worth while.  You'll just have to lose the mindset of COBOL and
enter the mindset of Perl.

IMHO, the thinking involved in writting COBOL is radically different
from writting Perl.  For example, you don't have to declare variables
up front in Perl the same why you do in COBOL (ie Working Storage
Section).  You also don't have the PIC statements in Perl, which means
your data can be more dynamic (ie instead of only being able to make
one million dollars in COBOL, you can code in Perl for a trillion or
more dollars - if that makes any sense).  You can also use regular
expressions and "fuzzy" logic in Perl, while there's no easy way to do
it in COBOL.  You can also have fun with subroutines in Perl, versus
paragraphs in COBOL - without the EXIT's and switches.

> so the question is how can Perl read that stuff? I think I'm wading thru
> most else ok, 
> just time and beating my head on the books...

You may want to start out with the FAQ's that come with the Perl
distro (perldoc perlfaq).  You may find the answer to you question
there.  Again, I must stress that COBOL and Perl are very different
languages.  You need to align yourself to Perlish ways to do things.

HTH

Jim


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

Date: Wed, 02 Oct 2002 10:25:47 +0200
From: Janek Schleicher <bigj@kamelfreund.de>
Subject: Re: reading Cobol PIC 9(6)V99 formats...
Message-Id: <3d9abb11$0$11477$afc38c87@auth.de.news.easynet.net>

Villy Kruse wrote at Wed, 02 Oct 2002 10:01:31 +0200:

> Just be aware that COBOL is about the only widely used language which
> supports fixed point decimal numbers.  

As we are in Perl newsgroup we should mention the CPAN module
Math::FixedPrecision

> In most other languages you must
> do all calculations in cents using integer numbers and only inserver
> the decimal point when amounts is printed.  Doing these calculations
> in floating point dollar values will give different rounding results,
> which will chock some accountants.

which avoids such rounding errors for a little speed penalty.


Greetings,
Janek


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

Date: Wed, 2 Oct 2002 17:49:28 +0900
From: "Alex Reid" <reid@surfline.ne.jp>
Subject: Search Patterns
Message-Id: <anebvh$arl$1@pecan.surfline.ne.jp>

I am learning perl now. I have checked the perldoc, my books, etc. but am
unable to get the correct result. I am trying to do a search pattern
producing an error for instances of more than one @ mark, lowercase letters
and not numeric characters. The code I have written is as follows:

print "Please enter your e-mail address\n";
$email = <STDIN>;
chomp $email;
while ($email) {
         if ($email !~ /@/ && $email =~ /[^A-Z]|[^0-9]/) {
          print "ERROR\n";
          $email = <STDIN>;
         }
while ($count = ($email =~ tr/@//)) {
         if ($count > 1) {
          print "ERROR\n";
          $email = <STDIN>;
        }
      else {
      print "okay\n";
      exit;
      }
}
}

This code won't pick up the lowercase and non-numeric search pattern and I
can't understand why.




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

Date: Wed, 02 Oct 2002 10:24:00 +0200
From: Janek Schleicher <bigj@kamelfreund.de>
Subject: Re: Search Patterns
Message-Id: <3d9abaa5$0$11477$afc38c87@auth.de.news.easynet.net>

Alex Reid wrote at Wed, 02 Oct 2002 10:49:28 +0200:

> I am learning perl now. I have checked the perldoc, my books, etc. but am
> unable to get the correct result. I am trying to do a search pattern
> producing an error for instances of more than one @ mark, lowercase letters
> and not numeric characters. The code I have written is as follows:

Well, it's better to use existing modules to check email addresses 
for its validness, as it isn't a simple job.
Look to the CPAN and you'll find a nice module 
Email::Valid

> 
> print "Please enter your e-mail address\n";
> $email = <STDIN>;
> chomp $email;
> while ($email) {
>          if ($email !~ /@/ && $email =~ /[^A-Z]|[^0-9]/) {

The alternation is wrong.
E.g. an 'A' is matched, as it isn't an 0-9.
Also a '9' is matched as it isn't an A-Z.

>           print "ERROR\n";
>           $email = <STDIN>;

Look to the next comment, it's quite the same.

>          }
> while ($count = ($email =~ tr/@//)) {
>          if ($count > 1) {
>           print "ERROR\n";
>           $email = <STDIN>;
>         }

The second while loop doesn't seem to be at the right place.
After an error, there will be only a check for the number of @'s,
but not for the lowercase and digits.

>       else {
>       print "okay\n";
>       exit;
>       }
> }
> }


It seems you mix a bit the logic.
First of all,
you read a lot of emails from STDIN,
as long as there are some one.

So a 
while (my $email = <STDIN>) {
   chomp $email;
   ...
}
is a good start.

Then there are 3 things you want to check:
Number of @'s <= 1
No lowercase character
No numeric characters

The last two things could be combined,
so that only two things need to be checked

    if (scalar ($email =~ tr/@//) > 1 or
        $email =~ /[[:lower:]\d]/) {   # also a [a-z\d] on non-POSIX-OS
       print "ERROR\n";
    } else {
       print "ok\n";
       last;
    }

A shorthand [untested] version could be:

while (<STDIN>) {
   chomp;
   tr/@/ > 1 or /[[:lower:]\d]/
      ? print "ERROR\n"
      : print "ok\n",last;
}
    

Best Wishes,
Janek



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

Date: 2 Oct 2002 09:24:38 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Search Patterns
Message-Id: <anee0m$1mj$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Alex Reid:

> I am learning perl now. I have checked the perldoc, my books, etc. but am
> unable to get the correct result. I am trying to do a search pattern
> producing an error for instances of more than one @ mark, lowercase letters
> and not numeric characters. The code I have written is as follows:
> 
> print "Please enter your e-mail address\n";
> $email = <STDIN>;
> chomp $email;
> while ($email) {
>          if ($email !~ /@/ && $email =~ /[^A-Z]|[^0-9]/) {
>           print "ERROR\n";
>           $email = <STDIN>;
>          }
> while ($count = ($email =~ tr/@//)) {
>          if ($count > 1) {
>           print "ERROR\n";
>           $email = <STDIN>;
>         }
>       else {
>       print "okay\n";
>       exit;
>       }
> }
> }
> 
> This code won't pick up the lowercase and non-numeric search pattern and I
> can't understand why.

Your code has some serious problems in control-flow. I am not sure what
this second nested while-loop is to achieve. Once you clean up the logic
of this code-snippet, things should get easier:

    print "Please enter your e-mail address\n";
    chomp (my $email = <STDIN>);
    
    while () { # inifite loop is more suitable here
        
        if ($email =~ tr/@// != 1 or
            $email =~ tr/A-Z0-9//) {
            print "Not ok. Try again:\n";
            chomp ($email = <STDIN>);
        } else {
            break;
        }
    }

So, you basically need only one condition: the number of occurances of @
is not equals 1 or the string contains uppercase characters or digits.
In this case, we let the user enter a new string. Otherwise it's ok and
we leave the loop.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: 2 Oct 2002 09:26:53 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Search Patterns
Message-Id: <anee4t$1r3$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Tassilo v. Parseval:

> Your code has some serious problems in control-flow. I am not sure what
> this second nested while-loop is to achieve. Once you clean up the logic
> of this code-snippet, things should get easier:
> 
>     print "Please enter your e-mail address\n";
>     chomp (my $email = <STDIN>);
>     
>     while () { # inifite loop is more suitable here
>         
>         if ($email =~ tr/@// != 1 or
>             $email =~ tr/A-Z0-9//) {
>             print "Not ok. Try again:\n";
>             chomp ($email = <STDIN>);
>         } else {
>             break;
              ^^^^^^

Errr!! Should be 'last' of course!

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: 2 Oct 2002 02:46:54 -0700
From: prometheus_au@excite.com.au (Dave)
Subject: Send email from a Database Management Script
Message-Id: <526e114e.0210020146.311a90bc@posting.google.com>

G'day all...

I have a flat-file pipe delimted contact database, which is used by
several scripts on my site. I'm wondering if anyone knows of a
database management script which will allow the 'admin' (via an HTML
interface) to choose a contact and send an email (preformatted or
otherwise) to only the contact chosen?

I've been searching and found nothing yet. Any help would be
appreciated.

Cheers
Dave. 

to reply directly change "excite" to "optusnet" - gotta keep them
spambots confused!


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

Date: Wed, 2 Oct 2002 10:58:44 +0100
From: "bengee" <postmaster@localhost.localdomain>
Subject: Re: Send email from a Database Management Script
Message-Id: <anefvm$6bu$1@news0.ifb.net>

"Dave" <prometheus_au@excite.com.au> wrote in message
news:526e114e.0210020146.311a90bc@posting.google.com...
> G'day all...
>
> I have a flat-file pipe delimted contact database, which is used by
> several scripts on my site. I'm wondering if anyone knows of a
> database management script which will allow the 'admin' (via an HTML
> interface) to choose a contact and send an email (preformatted or
> otherwise) to only the contact chosen?

Why don't you try writing your own? It's not that hard.

bengee




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

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


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