[6331] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 953 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 14 19:17:14 1997

Date: Fri, 14 Feb 97 16:00:20 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 14 Feb 1997     Volume: 7 Number: 953

Today's topics:
     Re: Case insensitive comparison <merlyn@stonehenge.com>
     Re: Case insensitive comparison (Dave Thomas)
     Re: Counting values within a file (Tad McClellan)
     Re: Counting values within a file (Joel Graber)
     eval in C (Paulino Huerta)
     fflush() in Perl? <henryw@seasick.sps.mot.com>
     Fortran namelist XS Adds junk to end of my C strings (Guy Berliner)
     Re: Help in setting up S/// (Honza Pazdziora)
     Help:# Can't find string terminator "ending_print_tag"  (Keith Warner Colvin)
     Help:# Can't find string terminator "ending_print_tag"  (Keith Warner Colvin)
     Re: Help:# Can't find string terminator "ending_print_t (Nathan V. Patwardhan)
     Re: How to return exit values to UNIX ?!?!? <tchrist@mox.perl.com>
     Re: MacPerl #Can't find string terminator.. (brian d foy)
     Re: OK I know that I am a newbie But I need HELP!! <merlyn@stonehenge.com>
     Perl can't run Dos commands on NT pflynn@intervoice.com
     Re: Perl can't run Dos commands on NT (Nathan V. Patwardhan)
     Re: perl script bug <tchrist@mox.perl.com>
     Re: perl script bug (Brooks Davis)
     Re: PROGRAM: how to check for nice/valid email address (Matthew Ahrens)
     RegEx, Email & Friedl's "Mastering..." Book (24601)
     Re: regexp's in XEmacs vs. Perl <ctdean@cogit.com>
     Re: subtle (to me) RE problem (Verne Beck)
     Re: using "$var" considered harmful?! (was Re: Q: openi <rootbeer@teleport.com>
     Re: why does this regexp eat a newline?? (Honza Pazdziora)
     Why is this an uncaught exception? <cherold@pathfinder.com>
     Re: Why is this an uncaught exception? (Nathan V. Patwardhan)
     Re: Why is this an uncaught exception? (Nathan V. Patwardhan)
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: 14 Feb 1997 15:32:40 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Dave@Thomases.com
Subject: Re: Case insensitive comparison
Message-Id: <8cwwsbow6v.fsf@gadget.cscaper.com>

>>>>> "Dave" == Dave Thomas <dave@fast.thomases.com> writes:

Dave> On Fri, 14 Feb 1997 01:16:55 -0800, Rupesh Kapoor <rupesh@whowhere.com> wrote:
>> Hi,
>> 
>> Its probably an easy question. What is the operator/function to compare
>> two strings in a case insensitive way

Dave> You could use 

Dave>   print "*match*\n" if ($str1 =~ m/^$str2$/i);

No, that would be Really Really Bad for these reasons:

(1) regex is a *lot* slower than simple comparison (even with case-folding),
and

(2) what if $st2 was "(a[bcd]e)"?  That'd match abe or ace or ade. And

(3) You've got a variable interpolation in a regex without /o.  Can
you say "slow as molasses in a heavy loop"?

Please don't fire up the regex machine unless you really need it.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 563 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 14 Feb 1997 23:27:47 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Case insensitive comparison
Message-Id: <slrn5g9t2c.n7c.dave@fast.thomases.com>

On 14 Feb 1997 15:32:40 -0700, Randal Schwartz <merlyn@stonehenge.com> wrote:
> >>>>> "Dave" == Dave Thomas <dave@fast.thomases.com> writes:
> 
> Dave> On Fri, 14 Feb 1997 01:16:55 -0800, Rupesh Kapoor <rupesh@whowhere.com> wrote:
> >> Hi,
> >> 
> >> Its probably an easy question. What is the operator/function to compare
> >> two strings in a case insensitive way
> 
> Dave> You could use 
> 
> Dave>   print "*match*\n" if ($str1 =~ m/^$str2$/i);
> 
> No, that would be Really Really Bad for these reasons:
> 
> (1) regex is a *lot* slower than simple comparison (even with case-folding),
> and

Yup - a factor of three

> (2) what if $st2 was "(a[bcd]e)"?  That'd match abe or ace or ade. And
> 
> (3) You've got a variable interpolation in a regex without /o.  Can
> you say "slow as molasses in a heavy loop"?

(4) IT DOESN'T WORK!!!! He wanted a 'cmp' replacement, I gave him an 'eq'
    one instead.
    
I buy (2) and (4). For normal everyday use, I'm less persuaded by (1) and
(3) - if I was that paranoid about speed I'd be looking at pre-processing my
strings one some other domain specific hack. A factor of 3 or 4 on one
particular comparison is unlikely to be a killer unless this is in the
applications critical loop. If it is, there are better solutions all round.

Dave


-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: Fri, 14 Feb 1997 14:28:33 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Counting values within a file
Message-Id: <hth2e5.jg2.ln@localhost>

Ken Williams (ken@forum.swarthmore.edu) wrote:
: In article <3302DB18.426B@eznet.com>, Darryl Caldwell <darrylc@eznet.com> wrote:
: > I would like to learn how to count multiple occurences of 
: > text within a
: > file.
: > 
: > If a file contains:
: > 
: > camel
: > iguana
: > penguin
: > cat
: > penguin
: > cheetah
: > camel
: > 
: > I would like to append text underneath this that says:
: > 
: > Total
: > =============
: > camel           2
: > iguana          1
: > penguin         2
: > cat             1
: > cheetah         1


: This isn't a Perl solution, but this has always been one of my favorite
: tricks in Unix:

: cat filename | sort | uniq -c

: That will do what you need, I think, and faster than the Perl equivalent.


Pretty slick. Except for the UUOC...

sort filename | uniq -c


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 14 Feb 1997 22:37:05 GMT
From: jgraber@daldd.sc.ti.com (Joel Graber)
Subject: Re: Counting values within a file
Message-Id: <JGRABER.97Feb14163705@sun_7407>


In article <ken-1402971303560001@news.swarthmore.edu>,
 ken@forum.swarthmore.edu (Ken Williams) writes:

> In article <3302DB18.426B@eznet.com>, Darryl Caldwell <darrylc@eznet.com> wrote:
> 
> > I would like to learn how to count multiple occurences of 
> > text within a file.
> > camel
> > iguana
> > penguin
> > cat
> > penguin
> > cheetah
> > camel
> >
> > I would like to append text underneath this that says:
> > 
> > Total
> > =============
> > camel           2
> > iguana          1
> > penguin         2
> > cat             1
> > cheetah         1


> This isn't a Perl solution, but this has always been one of my favorite
> tricks in Unix:
> 
> cat filename | sort | uniq -c
> 
> That will do what you need, I think, and faster than the Perl equivalent.

A (good? well maybe not) use of unix pipe methodology, 
but it does not solve the problem as stated.

Randal would give you a "Useless use of a cat award",
tied with 1e6 other users for second place.
( First place reserved for:  cat filename | tail  )

sort filename | uniq -c   # does the same without the useless cat.

But picking additional nits, it does not solve the stated problem either.
Your solution does not "append text underneath this" 
which would require using another cat and some text "Total ==== etc".

The output of your proposed solution is 
   2 camel
   1 cat
   1 cheetah
   1 iguana
   2 penguin

Which is not the correct column order
(possibly could be fixed with pipes to cut and paste).
or the correct row order, which cannot be fixed. 

If it does not meet the requirements, it doesn't matter if 
it is marginally faster than the working flexible oneliner
perl solution of 

% perl -ne 'chomp; push @o,$_  unless $i{$_}++;
    END { print "\nTotal\n=============\n"; 
          foreach (@o){printf "%-12s %4d\n",$_,$i{$_};}}' filename >>filename

% cat filename # to show correct results appended to file
camel
iguana
penguin
cat
penguin
cheetah
camel

Total
=============
camel           2
iguana          1
penguin         2
cat             1
cheetah         1

# Ten points to gurus who can do it in less characters,
#  without a foreach,grep,or map
#  excluding  if ! vs unless and "="x13
--
jgraber@ti.com


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

Date: 14 Feb 1997 21:52:30 GMT
From: phuerta@ibm.net (Paulino Huerta)
Subject: eval in C
Message-Id: <5e2mqu$2k0e$1@news-s01.ny.us.ibm.net>

Hi:
How to simulate the perl function eval
Any idea?
Thank in advance.
Paulino.



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

Date: Fri, 14 Feb 1997 14:58:25 -0600
From: Henry Wu <henryw@seasick.sps.mot.com>
Subject: fflush() in Perl?
Message-Id: <3304D1F1.3DA1@seasick.sps.mot.com>

I have a simple question.  Is there a function in Perl corresponding to
the C fflush() function?  I used mutiple "print" statements in a Perl
script, but the results didn't show on STDOUT instantly until the end of
the program.  So I want to flush the STDOUT after each "print"
statement.  Can anyone out there give me a clue?  Thanks.

-Henry


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

Date: Fri, 14 Feb 1997 21:29:26 GMT
From: berliner@netcom.com (Guy Berliner)
Subject: Fortran namelist XS Adds junk to end of my C strings
Message-Id: <berlinerE5M3p2.10H@netcom.com>

I created an extension module that may prove useful
to anyone using Fortran and the namelist extension
provided by, for example, the Sun f77 compiler. I
defined a class called "Nmlfile", which lets you
read in namelist files using the Perl syntax:
my $nmlfile = new Nmlfile($filehandle);
$nmlfile->readnml;
$variable = $nmlfile->variable;
$nmlfile->printnml("nmlname" => "mynml");
etc.

I would like to distribute this via CPAN.
The problem is that when I read in character
strings, random junk sometimes gets appended
to them in my extension subroutine. Otherwise,
the module works great. Does anyone have any 
interest in helping me to debug this problem?
Anyone out there have a use for Perl as glue 
for legacy Fortran software?

Guy Berliner
-- 
Finger berliner@netcom18.netcom.com for pgp key.


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

Date: Fri, 14 Feb 1997 20:52:19 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Help in setting up S///
Message-Id: <adelton.855953539@aisa.fi.muni.cz>

Andrew Johnson <ajohnson@gpu.srv.ualberta.ca> writes:

> : 
> : s/(\s+)\*(\s+)/\1 \2/
> : 
> : Keith Arner
> 
> better with:
> s/(\s+)\*(\s+)/$1 $2/;

And wouldn't s/^(\s+?)\*(\s+?)/$1 $2/; be more correct and faster?

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: Fri, 14 Feb 1997 11:26:10 -1000
From: colvin@aloha.net (Keith Warner Colvin)
Subject: Help:# Can't find string terminator "ending_print_tag" anywhere before EOF.
Message-Id: <colvin-1402971126100001@hawaii-5.u.aloha.net>

Aloha from Hawaii,

I am trying to write my first .cgi:

#! /usr/local/bin/perl
print "Content-type: text/html/n/n";

print <<"ending_print_tag";
<html>
<head>
<title>The First CGI</title>
<background="000000"  text="#FF0000" >
</head>
<body>
<h1> My First CGI</h1>
<i> HELLO INTERNET</i>
<hr noshade>
Items of importance go here.....
<body>
</html>
ending_print_tag>>

and I get this response when I run the script:

# Can't find string terminator "ending_print_tag" anywhere before EOF. 

What do I do next?
Mahalo, colvin@aloha.net


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

Date: Fri, 14 Feb 1997 11:43:10 -1000
From: colvin@aloha.net (Keith Warner Colvin)
Subject: Help:# Can't find string terminator "ending_print_tag" anywhere before EOF.
Message-Id: <colvin-1402971143100001@hawaii-5.u.aloha.net>

aloha from Hawaii,

trying to write my first.cgi:

#! /usr/local/bin/perl
print "Content-type: text/html/n/n";

print <<"ending_print_tag";
<html>
<head>
<title>The First CGI</title>
<background="000000"  text="#FF0000" >
</head>
<body>
<h1> My First CGI</h1>
<i> HELLO INTERNET</i>
<hr noshade>
Items of importance go here.....
<body>
</html>
ending_print_tag>>

this is the respone I get when I run the script:

# Can't find string terminator "ending_print_tag" anywhere before EOF.

what is the next step??
colvin@aloha.net


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

Date: 14 Feb 1997 21:55:15 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Help:# Can't find string terminator "ending_print_tag" anywhere before EOF.
Message-Id: <5e2n03$9ic@fridge-nf0.shore.net>

Keith Warner Colvin (colvin@aloha.net) wrote:
: Aloha from Hawaii,

Say hello to Magnum, and TC for me.  ;-)

: #! /usr/local/bin/perl
: print "Content-type: text/html/n/n";

problem: print "Content-type: text/html\n\n";

: print <<"ending_print_tag";

: ending_print_tag>>

print <<"ending_print_tag";

your stuff here

ending_print_tag

### *** make sure this is at the zero'th position of your editor's
### buffer ***

HTH!

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 14 Feb 1997 22:41:53 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to return exit values to UNIX ?!?!?
Message-Id: <5e2pnh$9pd$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    "David J. Topper (Pathfinder)" <dtopper@pathfinder.com> writes:
:I am having a hell of a time returning exit codes to the
:UNIX OS.  Here's an example using perl4.
:
:#!/usr/local/bin/perl
:
:print "ERROR TEST SCRIPT";
:&error_sub;  #call the subroutine
:print "Exiting with error $error\n";
:return $error;

You don't return from a program.  You return from 
a function.  From a program you exit.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    "Since when did you hear people talk about writing LISP or BASIC *scripts*?
     JCL and shell make command *scripts*; perl and LISP make *programs*."  --me


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

Date: Thu, 13 Feb 1997 17:20:43 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: MacPerl #Can't find string terminator..
Message-Id: <comdog-1302971720430001@nntp.netcruiser>


[redirected to a more appropriate newsgroup]

In article <5e2lgp$4bm@Holly.aa.net>, colvin@aloha.net (Keith Warner
Colvin) wrote:
 
> #! /usr/local/bin/perl
> print "Content-type: text/html/n/n";
> 
> print <<"ending_print_tag";

> ending_print_tag>>
                  ^^ get rid of that >>

the string terminator has to appear on the line by itself.
 
> When I run the script, this is what I get back.
> # Can't find string terminator "ending_print_tag" anywhere before EOF.

-- 
brian d foy                              <URL:http://computerdog.com>                       
unsolicited commercial email is not appreciated


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

Date: 14 Feb 1997 15:29:49 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: OK I know that I am a newbie But I need HELP!!
Message-Id: <8czpx7owbm.fsf@gadget.cscaper.com>

>>>>> "Nathan" == Nathan V Patwardhan <nvp@shore.net> writes:

Nathan> Mike Stok (mike@stok.co.uk) wrote:
Nathan> : Are you a cunning AI program let loose by someone at MIT?

Nathan> SYNTAX ERROR ON LINE 10.  :-)

I presume you meant 10 binary.  Not 10 decimal. :-)

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 563 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Fri, 14 Feb 1997 14:51:24 -0600
From: pflynn@intervoice.com
Subject: Perl can't run Dos commands on NT
Message-Id: <855950705.9135@dejanews.com>

Hi, folks:

Didn't see this one around, so I'll ask it...

I'm running Netscape Enterprise Server on my NT 4.0 machine.  I got CGI
scripts running, installed Perl 5.001, and everything's hunky-dory.

Problem is this:  from my Perl script, I call a Dos system command, say,
Dir (similar things happen when I use actual .exe or .cmd files):

[header stuff]
$dir = `dir e:\cgi-bin\*.*`;
print "<h2>Dir Test</h2>";
print "<hr>Dir = $dir <hr> ";
print "<h2>system call</h2>";
$result = system ("dir e:\\cgi-bin\\*.*");
print "<hr width=50% size=1>Result = $result <hr>";

( I realize there are those who are morally opposed <g> to using system
calls, but for sake of argument, let me continue...)

I drop to a dos prompt on the NT server and run the script.  It runs
fine. When I call it through a browser, I get some HTML (the <hr>'s and
text), but "dir" comes up absolutely blank, and "result" is "-256" (ie.,
the command didn't happen).

I wrote an equivalent batch file:

[header stuff]
dir *.*
echo.
echo That's all!


Run this from a dos prompt, it works fine; run it through the browser, and
it works fine again (!).

So, CGI scripts *are* running (for both .cgi and .bat (dangerous, I
know)).  Most perl programs run fine.  The scripts run fine from the
command line, but the 'dir' called from Perl doesn't get executed when run
by the http server.

Permissions?  The perl interpreter, the directories, etc., are all set
at RWX by the SYSTEM, which is what the http server runs as.

Ideas?  Something simple I missed, I'm sure.

Thanks for your time!

Paul

pflynn@intevoice.com

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 14 Feb 1997 23:14:02 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Perl can't run Dos commands on NT
Message-Id: <5e2rjq$ej6@fridge-nf0.shore.net>

pflynn@intervoice.com wrote:

Are you using the absolute path for cgi-bin?  The code segment below
returns errors, soooo if you use it (and you build the field), they 
will come.

Comment: I'm going to start an award for 'useless MSDOS backticks usage for
directory calls.'  :-)  But seriously, since Perl has some nice functions
to work with directories, why are you going this far out of your way?

Here's my version:

$dir = "E\:\\CGI-BIN\\";
### I've also heard you can use:
$dir = "E:/CGI-BIN";

sub error {
   my($error) = @_;
   print("Error: $error\n");
}

opendir(CGIBIN, "$dir") || error("NO: $!\n");
@entries = sort(readdir(CGIBIN)); ### sort the entries like a good kid
closedir(CGIBIN);

print <<HTML;
Content-type: text/html

<HTML>
  <HEAD>
    <TITLE>Reading: $dir</TITLE>
  </HEAD>

  <BODY>
  <H2>Dir Test</H2>

HTML

foreach $entry (@entries) {
   print("Entry: $entry<BR>\n");
}

print <<HTML;

   </BODY>
</HTML>

HTML

: ( I realize there are those who are morally opposed <g> to using system
: calls, but for sake of argument, let me continue...)

It's a sin in this case, and mortally wounds your program.  :-) Why use
something system-specific if you don't have to?

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 14 Feb 1997 22:38:17 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl script bug
Message-Id: <5e2pgp$9pd$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    rking@thepoint.net (RKing) writes:
:I'm running a perl script on unix under perl 4.036 

No, you aren't.  That's a 5.0 error message.

:and I can't figure this out.
:This is the message I keep getting when I run ./ in unix:
:
:Literal @thepoint now requires backslash at ./wilma line 217, within
:string Execution of ./wilma aborted due to compilation errors.
:
:Can anyone tell me why I'm getting this error msg?

Just what particular part of 

    Literal @thepoint now requires backslash 

don't you understand?  JUST PUT IN THE BACKSLASH ***AS IT 
CLEARLY TELLS YOU*** AND ALL WILL BE WELL.


--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com


Emacs is a fine editor, but I still prefer vi. -me


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

Date: 14 Feb 1997 17:11:56 GMT
From: brdavis@orion.ac.hmc.edu (Brooks Davis)
Subject: Re: perl script bug
Message-Id: <5e26cs$k6v$1@cinenews.claremont.edu>

RKing (rking@thepoint.net) wrote:
: Hello,
: 
: I'm running a perl script on unix under perl 4.036 and I can't figure
: this out.

I doubt you are running 4.036 since that error is a perl 5 message.  Typing
"perl -v" on the command line will tell you what version you are actually
running.

: This is the message I keep getting when I run ./ in unix:
: 
: Literal @thepoint now requires backslash at ./wilma line 217, within
: string Execution of ./wilma aborted due to compilation errors.
: 
: # heres the code, it's my e-mail addy:
:  
: <ADDRESS>
: <A HREF=mailto:"rking@thepoint.net">rking@thepoint.net</A>
: </ADDRESS>

I assume there is a print statement or a variable assingment somewhere
that this is attached to.  In that case the problem is simple.  The message
is telling you everything you ever wanted to know about this error.  You
need to change the <A HREF... line to:

<A HREF=mailto:"rking\@thepoint.net">rking\@thepoint.net</A>

The fact that you are getting that error and you have "s in your string
makes me worry a little since that could cause problems, but you didn't
include any perl so I don't know what you are doing there.  If you simply
enclose the whole mess in 's instead or "s your don't need to escape the @s
in your address.

-- Brooks

--
Brooks Davis            +------------------------------------------------+
brdavis@hmc.edu         | "_Slackware_ [Linux] is the MacOS of UNIXes."  |
Harvey Mudd College     |                    -- Richard Garnish          |
340 E. Foothill Blvd.   |                       on alt.sysadmin.recovery |
Claremont, CA 91711     +------------------------------------------------+


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

Date: Fri, 14 Feb 1997 23:36:23 GMT
From: matt@callnet.com (Matthew Ahrens)
Subject: Re: PROGRAM: how to check for nice/valid email address
Message-Id: <3305f29e.29421175@news.alt.net>

thanks for posting this useful program! as I was trying it out, I noticed
that it will bitch about compuserve addresses because they do not have any
[a-z] characters in the username. here is a diff which will except
compuserve-type usernames from this check.

97c97,99
<     bad("ugly") unless $hispass =~ /[a-z]/;
---
>     if ($hispass !~ /\d{3,}\.\d{3,}/) {
>       bad("ugly") unless $hispass =~ /[a-z]/;
>     }

On 14 Feb 1997 18:27:36 GMT, Tom Christiansen <tchrist@mox.perl.com> wrote:

>Here's a program checks to make sure that you've been given a reasonably
>decent email address.  It stops most goofs and spoofs, and annoys a *lot*
>of people.  I use it in, well, various places.  It's one of those things
>that is just going to get me talked about. :-)
>


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

Date: Fri, 14 Feb 1997 21:22:26 GMT
From: cggatt@worldnet.att.net (24601)
Subject: RegEx, Email & Friedl's "Mastering..." Book
Message-Id: <330cd5e1.14914399@netnews.worldnet.att.net>

Any help would be appreciated - 

In Friedl's book there is an example of parsing email headers that are
all single line entries. I am trying to match to headers that have
multiple line selections like the following -

Received: Blah BLah
	    Blah BLah
Date: BLah Blah

 I am reading the email header as one continuos string instead of
saving to file and reading from STDIN. Right now, I match on the colon
and the word metacharacters. Problem - I use (.*) to match everything
after the colon and this breaks on the \n. How would I tell the
expression to match the multiple line, as above, but go back to
matching normally on the 'Date:' line. Again, any help is appreciated.

24601


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

Date: 14 Feb 1997 13:57:06 -0800
From: Chris Dean <ctdean@cogit.com>
Subject: Re: regexp's in XEmacs vs. Perl
Message-Id: <x4ohdnnj9p.fsf@carnifex.cogit.com>


Hrvoje Niksic <hniksic@srce.hr> writes:
> Chris Dean <ctdean@cogit.com> writes:
> > While presumably one could do simple things like translate '\s' to
> > '[ \t\n\r]', it would be require significant work to get some of
> > the more useful Perl regexps.  Even to implement the \s translation
> > perfectly one would need a regular expression parser so that
> > [\sxyz] changes to [ \t\n\rxyz].
> 
> Whatever are you talking about??  Haven't you ever looked at Emacs
> syntax tables?  Perl \s is the same as Emacs \s-.  Emacs also has \s_,
> \sw, \S<something>, etc.  Look up the regexp section of the manual.

While Perl '\s' is (nearly) the same as XEmacs '\s-', Perl '[\s]'
is not the same as XEmacs '[\s-]'.

The original question and response was [attributions removed for brevity]:
| > > Does anyone know if XEmacs provides an alternate way to enter in regular
| > > expressions the way Perl accepts them?
| > I don't think there's any, but it's easy to write a macro to do this.

It seems to me that the question is "how does one enter a RE using
the syntax that Perl uses?".  replace-regexp-using-perl-syntax
would sure be nice to have.

The response to write a macro implies that there is an easy way to
perform a translation from Perl RE -> XEmacs RE.

For some things there is a simple correlation between the XEmacs
syntax and the Perl syntax:

        Perl            XEmacs
        ====            ======
        *               *
        .               .
        |               \|
        (               \(
        \w              \w
        \s              \s-
        \d              [0-9]
        [\da-f]         [0-9a-f]

etc.

For most of these REs with simple correlations the translation
step is easy and one could write a simple wrapper that does a
quick substitution.  But some things don't work simply.  

For one example, in Perl \s is the same as [\s].  To get [\s] to
translate to the XEmacs syntax would require that one have a
mini-parser to keep track of whether or not the \s is inside a []
or not.  There are other things that aren't simple.

Regards,
Chris Dean


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

Date: Fri, 14 Feb 1997 23:31:25 GMT
From: Verne_Beck@mindlink.bc.ca (Verne Beck)
Subject: Re: subtle (to me) RE problem
Message-Id: <3304ea31.19560797@news.mindlink.net>

 Eli the Bearded wrote:

> In a script which is scoring spam, I want to be able to
> detect N or more occurances of any one of these characters:
> 
> 	()!%*_+=|\/,<>:~-
> 
> For N=7, I have
> 
> /([\(\)!%*_+=|\\\/,<>:~-]).*${1}.*${1}.*${1}.*${1}.*${1}.*${1}/
> 

  m#[()!%*_+=|/\,<>:~-]{7,}#

OK, this is only a guess. :-)

What I am trying to do is to set up a class of characters (everything
inside the square braces, followed with a set of curly braces to set
up the mininum number of matches as seven.

Will this work? (I am already home for the weekend, so I can't test
the code).

PS Since the special characters are enclosed entirely inside the
square braces, I am assuming that I wouldn't need to 'escape' them.
(hope, hope).


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

Date: Fri, 14 Feb 1997 12:55:43 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: Re: using "$var" considered harmful?! (was Re: Q: opening a file RW without deleting it.)
Message-Id: <Pine.GSO.3.95q.970214121843.19770C-100000@julie.teleport.com>

On Thu, 13 Feb 1997, Russell Schulz wrote:

> over and over in the group I see people write code like
> 
>   $var1="$var2";
> 
> and always people respond
> 
>   why are the quotes there???
> 
> like they're HARMFUL or something.  

Well, they do force stringification. That's a big problem in a few rare
cases, and an extra cost if it's not already a string or needing to be
converted in any case. Other than that, you have a point. 

> I find it all much like warning people about escaping obscure
> punctuation on the right hands of regexes when they don't need to, or
> putting extra {} in C where they don't need to, or using () around
> conditionals in Pascal where you don't need to -- they just make
> maintenance that much easier, and lead to fewer surprises. 

There's a certain balance here. Perl lets you do things in more than one
way, so there's nothing strictly wrong with doing those things if it makes
your life easier. If you know that adding to "$var2" is going to be
necessary, or if it's just likely, you're welcome to put on the quotes,
just as 'use vars qw($foo)' has fancier quoting than necessary, for
convenience.

On the other hand, I teach students to leave off unneeded quotes. It's
better for them to learn to leave them off in most cases. Later, when
they've seen a few times when including them might help, they'll figure
that out on their own. And it may help them to avoid some mistakes like
these, not all of which are necessarily incorrect Perl (although some are
exaggerated a bit to make a point).

    "$var1" = "$var2";
    if ("$var1" == "$var2") { ... }
    $var1 = "&myfunc(1,2,3)";
    $var1 = '$var2';
    $var1 = sin("$var2");
    @list = `foo`; print "@list";
    if ($foo =~ /^\-/) { $foo =~ s/^\-//; }
        else { $foo =~ s/^(.)/ "-" . "$1" /e }

In most cases (but with some notable exceptions) Perl's easiest way is
also the best way. 

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Fri, 14 Feb 1997 21:02:10 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: why does this regexp eat a newline??
Message-Id: <adelton.855954130@aisa.fi.muni.cz>

F.Postma@inter.NL.net (Frans Postma) writes:

> Problems arise when the subject is empty or only filled with spaces.
> Example as short as I could:
> 
> #!perl
> $x='Subject:
> To: bla@abla
> Date: Sat 01-02-1997';
> $x=~s/Subject:\s*([^\n]*?)\s*\n/Subject: $1\n/im;
> print $x;
> __END__
> 
> Output of this is:
> Subject: To bla@abla
> Date: Sat 01-02-1997
> 
> Question: why does the regexp on $x eat the line on the Subject line?
> $1 should be empty in the s//m in this case but for some reason it
> grabs the next line too, which it shouldn't 'cos I specificly exclude
> newlines (\n)....

Well, the problem is not that the \n would get into $1. It is eaten by
the previous \s*, because \s is defined as [ \t\n\r\f]. You might try
s/Subject: *([^\n]*?)\s*\n/Subject: $1\n/im;
instead.

Hope this helps.

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: Fri, 14 Feb 1997 15:52:37 -0500
From: Charles Herold <cherold@pathfinder.com>
Subject: Why is this an uncaught exception?
Message-Id: <3304D096.54D3@pathfinder.com>

I want to abort if there are less than three arguments on the command
line.  The code below does that, but gives me the message:


Uncaught exception from user code:
        Usage: change <search_string> <replace_string> <filename>



Here's the code in question.  What's wrong with it?

#!/usr/local/bin/perl5 -w
use diagnostics;

die "Usage: change <search_string> <replace_string> <filename>\n" unless
@ARGV >= 3;


-- 
Best regards,

       Charles Herold
           cherold@pathfinder.com
               (212) 522-5190


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

Date: 14 Feb 1997 21:52:24 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Why is this an uncaught exception?
Message-Id: <5e2mqo$9ic@fridge-nf0.shore.net>

Charles Herold (cherold@pathfinder.com) wrote:

: Uncaught exception from user code:
:         Usage: change <search_string> <replace_string> <filename>

OOPS!  Sorry -> finger too quick on the trigger.

$args = $#ARGV+1;
&usage if $args <3;

sub usage {

    print("Usage: change <search_string> <replace_string> <filename>\n");
    exit;

}

HTH!

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 14 Feb 1997 21:50:12 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Why is this an uncaught exception?
Message-Id: <5e2mmk$9ic@fridge-nf0.shore.net>

Charles Herold (cherold@pathfinder.com) wrote:

: Here's the code in question.  What's wrong with it?

: #!/usr/local/bin/perl5 -w
: use diagnostics;

: die "Usage: change <search_string> <replace_string> <filename>\n" unless
: @ARGV >= 3;

#!/usr/local/bin/perl -w

$my_argc = $#ARGV+1;
&usage() unless $my_argc ==3;

sub usage {
   print("Usage: change <search_string> <replace_string> <filename>\n");
   exit;
}


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

Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Jan 97)
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.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

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 V7 Issue 953
*************************************

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