[24376] in Perl-Users-Digest
Perl-Users Digest, Issue: 6565 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 14 21:06:26 2004
Date: Fri, 14 May 2004 18: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)
Perl-Users Digest Fri, 14 May 2004 Volume: 10 Number: 6565
Today's topics:
Re: eMailing with an extracted eMail address (Zaphod)
Re: Favorite Editor for Perl programming <blah@blah.com>
Re: Favorite Editor for Perl programming <tadmc@augustmail.com>
Re: Favorite Editor for Perl programming <tadmc@augustmail.com>
Re: Favorite Editor for Perl programming <spamtrap@dot-app.org>
Re: Favorite Editor for Perl programming <knowsitall@NoSpamPLZ.net>
Re: Favorite Editor for Perl programming <postmaster@castleamber.com>
Re: Favorite Editor for Perl programming <knowsitall@NoSpamPLZ.net>
Re: file uploads <someone@somewhere.com>
Re: file uploads <sbryce@scottbryce.com>
Re: file uploads <usenet@morrow.me.uk>
how to make "dir /s" in perl? <tihana@kata.com>
Re: how to make "dir /s" in perl? <postmaster@castleamber.com>
Re: IO::socket question <1usa@llenroc.ude>
Operator precedence <net.weathersongATnemo>
Re: Operator precedence (Malcolm Dew-Jones)
Re: Operator precedence <ittyspam@yahoo.com>
Re: Operator precedence ctcgag@hotmail.com
Re: Password scheme/Persistent session... <blah@blah.com>
Re: Random Integer <pinyaj@rpi.edu>
Re: RegEx to delete // comments NOT in quotes: ( ' ) OR <NewsGroups@US-Webmasters.com>
Request: Statistical analysis - Event detection <christian3110@noos.fr>
Re: Request: Statistical analysis - Event detection <ebohlman@earthlink.net>
Re: Using hashes to sort number sequences (Martin Foster)
Re: Using hashes to sort number sequences <usenet@morrow.me.uk>
what's wrong with my CPAN module (yjin6666@hotmail.com)
Re: what's wrong with my CPAN module <usenet@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 May 2004 17:49:45 -0700
From: zaphod@earthling.net (Zaphod)
Subject: Re: eMailing with an extracted eMail address
Message-Id: <fabcf423.0405141649.496e6910@posting.google.com>
Paul Lalli <ittyspam@yahoo.com> wrote in message news:<20040514115253.K15402@dishwasher.cs.rpi.edu>...
> On Fri, 14 May 2004, Zaphod wrote:
>
> > I am trying to make the script eMail the sender when these
> > errors happen also. However I can't seem to get the script
> > to send the eMail with the address I extract from the CSV
> > file into a variable. If I explicitly assign an address to the
> > same variable the eMail will send fine.
> >
> > Here is my very simplified testing file as an example, and a
> > bit more explanation;
> >
> > #!/usr/bin/perl
>
> <snip>
> > # escape the @
> > $emailaddress=~s/@/\\@/g;
>
> Don't do this. This is (most likely) the source of your problem. You are
> not supposed to escape @ contained in existing strings.
Thank you.
I actually figured this out before reading your post. But thank you
for your informative post none the less!
Z
------------------------------
Date: Fri, 14 May 2004 14:11:31 -0400
From: Sherif Zaroubi <blah@blah.com>
Subject: Re: Favorite Editor for Perl programming
Message-Id: <opr7z4th2ncx74rp@news.videotron.ca>
On Fri, 14 May 2004 12:19:53 -0500, John Bokma
<postmaster@castleamber.com> wrote:
> Edward Wijaya wrote:
>
>>
>> In unix/linux environment.
>>
>> Is X(Emacs) better than vi(M)?
>
> Editor war?
>
>> How does one fare to another?
>> Or there is other better choice?
>
> I used NEdit a lot (IRIX and Linux).
> http://www.nedit.org/
>
> besides vi(m). I think you should at least learn either Emacs or vi(m),
> without X :-D.
>
I love to code on bare metal with a magnet ...
Pfff Editor ... They are for sissies.
------------------------------
Date: Fri, 14 May 2004 16:00:56 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Favorite Editor for Perl programming
Message-Id: <slrncaacs8.dal.tadmc@magna.augustmail.com>
Edward Wijaya <ewijaya@singnet.com.sg> wrote:
> Is X(Emacs) better than vi(M)?
No.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 14 May 2004 16:01:07 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Favorite Editor for Perl programming
Message-Id: <slrncaacsj.dal.tadmc@magna.augustmail.com>
Edward Wijaya <ewijaya@singnet.com.sg> wrote:
> Is X(Emacs) better than vi(M)?
Yes.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 14 May 2004 18:07:49 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Favorite Editor for Perl programming
Message-Id: <KIudnSq3iIqr3jjdRVn-uw@adelphia.com>
Tad McClellan wrote:
> Edward Wijaya <ewijaya@singnet.com.sg> wrote:
>
>> Is X(Emacs) better than vi(M)?
>
> Yes.
>> Is X(Emacs) better than vi(M)?
>
>
> No.
The truth is finally revealed - Tad's an elf. ;-)
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Fri, 14 May 2004 22:45:55 GMT
From: knowsitall <knowsitall@NoSpamPLZ.net>
Subject: Re: Favorite Editor for Perl programming
Message-Id: <D_bpc.55774$493.812374@weber.videotron.net>
On Sat, 15 May 2004 00:48:14 -0000, Edward Wijaya wrote:
>
> In unix/linux environment.
>
> Is X(Emacs) better than vi(M)?
No. It is worse. Do not beleive people who tell you otherwise!
> How does one fare to another?
It is simple - vim is 505% better than emacs.
> Or there is other better choice?
>
No. But vi will be close second after vim. Then come (in this order):
emacs
xemacs
editor
notepad
ms word.
------------------------------
Date: Fri, 14 May 2004 17:59:03 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Favorite Editor for Perl programming
Message-Id: <40a54f38$0$208$58c7af7e@news.kabelfoon.nl>
knowsitall wrote:
> No. But vi will be close second after vim. Then come (in this order):
> emacs
> xemacs
> editor
copy con: script
> notepad
> ms word.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
------------------------------
Date: Fri, 14 May 2004 23:17:03 GMT
From: knowsitall <knowsitall@NoSpamPLZ.net>
Subject: Re: Favorite Editor for Perl programming
Message-Id: <Prcpc.56446$493.832343@weber.videotron.net>
On Fri, 14 May 2004 17:59:03 -0500, John Bokma wrote:
>> editor
>
> copy con: script
>
forgot the echo command:
echo '#!/usr/local/bin/perl' > file.pl
echo 'use warnings;' >> file.pl
echo 'use strict;' >> file.pl
etc
------------------------------
Date: Fri, 14 May 2004 21:37:39 GMT
From: "Bigus" <someone@somewhere.com>
Subject: Re: file uploads
Message-Id: <03977f759dce13cd6297db907e2f7cc6@news.teranews.com>
"Sokar" <jmccloughlin@hotmail.com> wrote in message
news:34628238.0405140328.7163a7f4@posting.google.com...
> I have a perl cgi form that when activated prints out an online for
> for people to fil in. I want to give the user the option to upload
> two jpegs. I have the input type "file" I just dont know how to
> upload the picture onto my server. The cgi calls a .pl script. When
> I do a $pic1 = $FORM{'pic1'} all i get is the path name that the user
> submitted when they selected the pic they want to upload.
>
> I was told that I would prob have to use cgi.pm to get this done.
> Would anyone have a bit of code that will upload the jpeg file that
> the user selects and save it onto my server?
This should work:
use CGI;
$query = new CGI;
$filename = $query->param("file");
$filename =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = $query->upload("file");
open UPLOADFILE, ">$uploadir/$filename";
binmode UPLOADFILE;
while ( <$upload_filehandle> ) { print UPLOADFILE; }
close UPLOADFILE;
Notes:
1) You should change $uploadir to the directory on your server where you are
storing the file
2) "file" in the 3rd & 5th lines should be changed to whatever the name of
the file field is in your HTML code.
3) I believe you can omit the binmode line if your server isn't Windows
4) You will probably want to include other lines in that code to check
things like whether the file already exists (since it will be overwritten
with the above code if it does) and check that the file actually uploaded
properly afterwards
Bigus
.
------------------------------
Date: Fri, 14 May 2004 16:33:47 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: file uploads
Message-Id: <10aai9n8eh8880b@corp.supernews.com>
Bigus wrote:
> 4) You will probably want to include other lines in that code to check
> things like whether the file already exists (since it will be overwritten
> with the above code if it does) and check that the file actually uploaded
> properly afterwards
and whether the file is actually a JPG.
------------------------------
Date: Fri, 14 May 2004 23:08:14 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: file uploads
Message-Id: <c83jgu$5p1$1@wisteria.csv.warwick.ac.uk>
Quoth "Bigus" <someone@somewhere.com>:
> 3) I believe you can omit the binmode line if your server isn't Windows
As of 5.8 it is needed regardless; anyway, it is good practice to put it in.
Ben
--
"If a book is worth reading when you are six, * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis
------------------------------
Date: Sat, 15 May 2004 00:50:20 +0200
From: <tihana@kata.com>
Subject: how to make "dir /s" in perl?
Message-Id: <c83ieo$qr1$1@ls219.htnet.hr>
How to make "dir /s" in perl, to make list off all files in directory, and
subdirectory?
------------------------------
Date: Fri, 14 May 2004 18:09:02 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: how to make "dir /s" in perl?
Message-Id: <40a5518f$0$197$58c7af7e@news.kabelfoon.nl>
tihana@kata.com wrote:
> How to make "dir /s" in perl, to make list off all files in directory, and
> subdirectory?
Have a look at File::Find
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
------------------------------
Date: 14 May 2004 18:12:54 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: IO::socket question
Message-Id: <Xns94E99099C76F4asu1cornelledu@132.236.56.8>
"B. W." <mysympatico001@sympatico.ca> wrote in news:Jm7pc.79721$FH5.1821934
@news20.bellglobal.com:
> Is it possible to open a socket for loopback on win32 system?
What happened when you tried?
--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)
------------------------------
Date: Fri, 14 May 2004 19:04:37 GMT
From: David Frauzel <net.weathersongATnemo>
Subject: Operator precedence
Message-Id: <60e129ab1d335e41772290bbaff96812@news.teranews.com>
I'm building a small lexical analyzer and parser and using perlop /
perlsyn / perldata as a reference. (I'm not building the lexer in Perl,
though.)
I've managed to get myself thoroughly confused with how operator
precedence works in Perl. At some point I got the (mis)conception that a
statement was evaluated from "inside out" based on the precedence of each
operator, but all of my tests seem to indicate that precedence means
little, in fact, in contrast to the typical left-to-right reading style
of human languages. Which makes sense. And doesn't.
Some of my tests:
$foo = 1; $foo or $foo++; print $foo;
The "or" operator has very low precedence, and ++ has very high. Yet the
second statement is plainly evaluated left to right - since $foo is true,
"or" is short-circuited, and $foo++ never happens.
1 or (print "foo");
Something similar happens here. Although parantheses and TERMs (the list
operator print, in this case) are documented as having the highest
precedence, the above statement proves once again that plain old left to
right is what's really happening.
Well, obviously precedence is still an issue in mathematical equations.
So that 2-3*4 is -10 (though some languages like SmallTalk defy
convention in this regard). But the same appears not to hold true with
logical operators:
0 and 1 && ++$foo; # $foo is not incremented
I had to work hard just to craft of an example of when operator
precedence *does* actually take effect:
print 0 < 0 || 1; # true
print 0 < 0 or 1; # false
But then how did Perl know to evaluate || before < in this statement,
when it (apparently?) did not know to evaluate the ++ in the previous
example? Yes, it's tempting to say "use parantheses" - but that goes
against the whole idea of native operator precedence in the first place.
When I have to say,
0 and (1 && ++$foo);
then I've defeated the established precedence difference between "and"
and &&. Anyhow, the use of parantheses still promotes the same result.
$foo is not incremented. Only if I put things left to right:
1 && ++$foo and 0;
do I get my expected result.
So what I'm left with wondering is: how *does* operator precedence
actually work? I've pored over perlop and something obvious is just not
penetrating.
Thanks for any insight.
------------------------------
Date: 14 May 2004 13:38:34 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Operator precedence
Message-Id: <40a52e4a@news.victoria.tc.ca>
David Frauzel (net.weathersongATnemo) wrote:
: I'm building a small lexical analyzer and parser and using perlop /
: perlsyn / perldata as a reference. (I'm not building the lexer in Perl,
: though.)
: I've managed to get myself thoroughly confused with how operator
: precedence works
Precedence doesn't have anything do with evaluation order, except by
accident.
Precedence describes how the tokens are bound together when one is trying
to understand the meaning of something.
In particular, in a progrmaming language, the precedence is used to build
the parse tree.
A couple of possible parse trees of "$foo or $foo++" come to mind...
or
/ \
/ \
$foo ++
/
/
$foo
++
/
/
or
/ \
/ \
$foo $foo
Which parse tree is perl supposed to use? It's the operator precedence
that tells perl that the first one is the correct one to use.
When perl _uses_ the parse tree then the things at the bottom of the parse
tree typically need to be calculated before it can calculate things higher
up. By a happy accident, that often means that things attached to higher
precedence operators have to be calculated first, but that's all it really
is - a happy accident, and in fact if you have more than one branch of the
tree then you still have to ask which side of the tree is to be calcuated
first, and precedence has nothing to do with that.
for example a * b + c * d, creates the following (because * is higher
than +)
+
/ \
/ \
/ \
* *
/ \ / \
a b c d
Which multiplication should be calcuated first? a*b or c*d?
Precedence only tells us that they both need to be calculated
before we can perform the final addition, but precedence does
not tell us which multiplication to do first. In fact from a
precedence point of view, either multiplication could be done
first.
In the original example, "$foo or $foo++", the "or" operator only requires
input from one of the two branches if either branch is true. So in this
case, perl starts by calculating the first branch. The value is true, so
therefore perl does not have to calculate the second branch, i.e. the code
$foo++ never gets run.
------------------------------
Date: Fri, 14 May 2004 18:33:15 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Operator precedence
Message-Id: <20040514182601.M15402@dishwasher.cs.rpi.edu>
On Fri, 14 May 2004, it was written:
> Date: Fri, 14 May 2004 19:04:37 GMT
> From: David Frauzel <net.weathersongATnemo>
> Newsgroups: comp.lang.perl.misc
> Subject: Operator precedence
>
> I'm building a small lexical analyzer and parser and using perlop /
> perlsyn / perldata as a reference. (I'm not building the lexer in Perl,
> though.)
>
> I've managed to get myself thoroughly confused with how operator
> precedence works in Perl. At some point I got the (mis)conception that a
> statement was evaluated from "inside out" based on the precedence of each
> operator, but all of my tests seem to indicate that precedence means
> little, in fact, in contrast to the typical left-to-right reading style
> of human languages. Which makes sense. And doesn't.
>
Er, if you're using perlop, then surely you saw the table at the very
beginning which shows you the different associativities of the operators?
Two operators of the same precedence level that are left associative (such
as 'or') will operate left-to-right. Two operators of the same precedence
level that are right associative (such as **) will operate right-to-left.
Therefore,
$foo = 1;
$foo or $foo++; # $foo evaluated first.
$bar = 4**3**2 # 3**2 evaluated first, returns (4 to the power of 9), not
(64 squared).
> 0 and 1 && ++$foo; # $foo is not incremented
This has nothing to do with precedence. When perl sees this line, it is
equivalent to:
0 and (1 && (++$foo))
The reason $foo isn't incremented is because of short-circuit evaluation.
This means that as soon as perl sees the 0 in an 'and' statement, it knows
the entire thing will be false, so there is no reason to even try to
evaluate the right and side (which in this case is (1 && (++$foo)) ).
Again, this isn't precedence, it's a function of the short-circuited
nature of the logical operators.
Paul Lalli
------------------------------
Date: 15 May 2004 00:03:40 GMT
From: ctcgag@hotmail.com
Subject: Re: Operator precedence
Message-Id: <20040514200340.424$Fz@newsreader.com>
David Frauzel <net.weathersongATnemo> wrote:
> I'm building a small lexical analyzer and parser and using perlop /
> perlsyn / perldata as a reference. (I'm not building the lexer in Perl,
> though.)
>
> I've managed to get myself thoroughly confused with how operator
> precedence works in Perl. At some point I got the (mis)conception that a
> statement was evaluated from "inside out" based on the precedence of each
> operator, but all of my tests seem to indicate that precedence means
> little, in fact, in contrast to the typical left-to-right reading style
> of human languages. Which makes sense. And doesn't.
Precedence determines what the operands *are*, it does not directly
determine when they are evaluated.
>
> Some of my tests:
>
> $foo = 1; $foo or $foo++; print $foo;
>
> The "or" operator has very low precedence, and ++ has very high. Yet the
> second statement is plainly evaluated left to right - since $foo is true,
> "or" is short-circuited, and $foo++ never happens.
short-circuiting wouldn't make sense otherwise, would it?
>
> 1 or (print "foo");
>
> Something similar happens here. Although parantheses and TERMs (the list
> operator print, in this case) are documented as having the highest
> precedence, the above statement proves once again that plain old left to
> right is what's really happening.
Precedence is entirely irrelevant. There is no ambiguity there to be
resolved.
> Well, obviously precedence is still an issue in mathematical equations.
> So that 2-3*4 is -10 (though some languages like SmallTalk defy
> convention in this regard). But the same appears not to hold true with
> logical operators:
>
> 0 and 1 && ++$foo; # $foo is not incremented
Those different expressions are not testing the same thing at all.
>
> I had to work hard just to craft of an example of when operator
> precedence *does* actually take effect:
>
> print 0 < 0 || 1; # true
True, But perhaps not for the reason you think. The two expressions
"(0<0)||1" and "0<(0||1)" just happen to both be true in Perl.
> print 0 < 0 or 1; # false
No, that's true. (It does print false, but that's neither here nor there.
the return value of an expression is not necessarily the same as what the
expression causes to be printed.)
>
> But then how did Perl know to evaluate || before < in this statement,
It didn't. It evaluated < before ||.
> when it (apparently?) did not know to evaluate the ++ in the previous
> example?
It didn't "not know to evaluate ++", it knew better than to evaluate ++.
You may think it's one step behind you, but it is really one step ahead.
> Yes, it's tempting to say "use parantheses" - but that goes
> against the whole idea of native operator precedence in the first place.
> When I have to say,
>
> 0 and (1 && ++$foo);
>
> then I've defeated the established precedence difference between "and"
> and &&. Anyhow, the use of parantheses still promotes the same result.
> $foo is not incremented. Only if I put things left to right:
>
> 1 && ++$foo and 0;
>
> do I get my expected result.
Again, how could it possibly be short-circuiting if it did what you expect?
> So what I'm left with wondering is: how *does* operator precedence
> actually work? I've pored over perlop and something obvious is just not
> penetrating.
>
> Thanks for any insight.
You are confusing precedence with order of operation. Precedence only
disambiguates the ambiguity as to which expression is the operand of which
operator. This only indirectly affects order of operation, and does it in
a operator-dependent fashion.
Xho
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Fri, 14 May 2004 14:36:07 -0400
From: Sherif Zaroubi <blah@blah.com>
Subject: Re: Password scheme/Persistent session...
Message-Id: <opr7z5yhkqcx74rp@news.videotron.ca>
On 14 May 2004 06:24:35 -0700, krakle <krakle@visto.com> wrote:
> Thank you. However, the whole point to my post was to see if I could
> do a session with out cookies...
If you are running apache.
Check .htaccess files and .htpasswd files.
You don't need a session. All you need is a password file.
------------------------------
Date: Fri, 14 May 2004 17:56:41 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Random Integer
Message-Id: <Pine.SGI.3.96.1040514175515.1338660A-100000@vcmr-64.server.rpi.edu>
On 14 May 2004, Walter Roberson wrote:
>In article <qz7pc.67201$P35.13308@newssvr25.news.prodigy.com>,
>Ala Qumsieh <notvalid@email.com> wrote:
>:Iain Chalmers wrote:
>
>:> $num=sprintf "%u",rand($n+1);
>
>:Hmmm .. what's wrong with int()?
>
>int() truncates. sprintf rounds. See the perl documentation for int,
>which suggests "usually" sprintf over int.
Um, I've seen %.0f used to round, but never %u. That just truncates. And
%.0f is imperfect:
printf "%.0f %.0f", 1.5, 2.5; # 2 2
--
Jeff Pinyan RPI Acacia Brother #734 RPI Acacia Corp Secretary
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Fri, 14 May 2004 15:47:46 -0500
From: "W. D." <NewsGroups@US-Webmasters.com>
To: Bill <wherrera@lynxview.com>
Subject: Re: RegEx to delete // comments NOT in quotes: ( ' ) OR (")???
Message-Id: <40A53072.520C@US-Webmasters.com>
Hi Bill, et. al.,
Am I interpreting this correctly?
s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
RegExPattern = '
# # Opening delimiter
/ # A forward slash
\* # An escaped *
[^*] # Any character (except: *)
* # Zero or more of the previous character
\* # An escaped *
+ # One or more of the previous
( # Begin a logical grouping
[^/*] # Any character (except: / * )
[^*] # Any character (except: * )
* # Zero or more of the previous
\* # An escaped *
+ # One or more of the previous
) # End logical grouping
* # Zero or more of the previous
/ # A slash
| # OR
// # 2 forward slashes
[^\n] # Can't be a newline
* # Zero or more of the previous
| # OR
( # Begin logical grouping
" # A double quote mark
( # Begin a nested logical grouping
\\ # An escaped backslash
. # Any character (except newline \n)
| # OR
[^"\\] # Any character (except " or \ )
) # End logical grouping
* # Zero or more of the previous
" # A quote mark
| # OR
' # A single quote mark
( # Begin logical grouping
\\ # An escaped backslash
. # Any character (except newline \n)
| # OR
[^'\\] # Any character except ' or \
) # End logical grouping
* # Zero or more of the previous
' # A single quote mark
| # OR
. # Any character (except newline \n)
[^/"'\\] # Any character (except these: / " ' \ )
* # Zero or more of the previous
) # End logical grouping
# # Closing delimiter
$2 # ?
#gsx # Modifiers? Global? String?
';
Bill wrote:
>
> W. D. wrote:
> > ===================== Code Start ==========================
> > // Some comments that should be trashed
> >
> > Code goes here;
> >
> > $SomeVar = '// These comments should be left alone!';
> >
> > /* Some more comments that will remain */
> >
> > " // These comments should also be left alone "
> >
> > # Hash/Pound sign comments should remain for now
> >
> > More Code goes here
> >
> > { This code should stay // This comment should go
> > }
> > =========================== Code End ===========================
> >
> > Does anyone know how to create a RegEx to do this????!
> >
>
> Derived from perlfaq on regex:
>
> #!/usr/bin/perl
>
> my $lines = <<ENDTEXT;
> // Some comments that should be trashed
> Code goes here;
> \$SomeVar = '// These comments should be left alone!';
> /* Some more comments that will remain */
> \" // These comments should also be left alone \"
> # Hash/Pound sign comments should remain for now
> More Code goes here
> { This code should stay // This comment should go
> }
> ENDTEXT
>
> print $lines, "\n\n\n";
>
> # this needs whitespace reformatting, but you're using PHP :{
> $lines =~
> s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
> print $lines, "\n";
--
Start Here to Find It Fast!™ ->
http://www.US-Webmasters.com/best-start-page/
$8.77 Domain Names -> http://domains.us-webmasters.com/
------------------------------
Date: Fri, 14 May 2004 22:12:32 +0200
From: Christian <christian3110@noos.fr>
Subject: Request: Statistical analysis - Event detection
Message-Id: <40a52830$0$31695$79c14f64@nan-newsreader-05.noos.net>
Hello,
I'm currently thinking about developing an "event detection" module and
I guess I might use Perl for this. Basically what I want to do is to
monitor a large number of phone calls going through an operator's
network. I have a number of curves ("indicators") in an SQL database
that can have a "normal" behavior (like staying constant, or displaying
a weekly periodical pattern) and an "abnormal" behavior (for instance a
quality indicator dropping sharply, or a number of calls peaking one
day, etc).
So I'm thinking about developing something that could help automatically
identify "events", using statistical analysis. The user would specify
for instance "this curve should stay horizontal", or "this indicator
should be periodical", or "this value should increase at such or such
rate", and the module would detect and signal when a curve strays from
its supposed, ideal behavior.
So my question is: does anyone know about anything even remotely
similar? I guess this kind of algorithms must be very classical (lots
of systems need such monitoring, like airplanes, powerplants,
whatever). I'd like to avoid reinventing the wheel if possible :-)
Any idea?
Thanks to all!
Christian <christian.roche@caramail.com>
------------------------------
Date: 14 May 2004 22:09:49 GMT
From: Eric Bohlman <ebohlman@earthlink.net>
Subject: Re: Request: Statistical analysis - Event detection
Message-Id: <Xns94E9AF415245Bebohlmanomsdevcom@130.133.1.4>
Christian <christian3110@noos.fr> wrote in
news:40a52830$0$31695$79c14f64@nan-newsreader-05.noos.net:
> I'm currently thinking about developing an "event detection" module and
> I guess I might use Perl for this. Basically what I want to do is to
> monitor a large number of phone calls going through an operator's
> network. I have a number of curves ("indicators") in an SQL database
> that can have a "normal" behavior (like staying constant, or displaying
> a weekly periodical pattern) and an "abnormal" behavior (for instance a
> quality indicator dropping sharply, or a number of calls peaking one
> day, etc).
>
> So I'm thinking about developing something that could help automatically
> identify "events", using statistical analysis. The user would specify
> for instance "this curve should stay horizontal", or "this indicator
> should be periodical", or "this value should increase at such or such
> rate", and the module would detect and signal when a curve strays from
> its supposed, ideal behavior.
>
> So my question is: does anyone know about anything even remotely
> similar? I guess this kind of algorithms must be very classical (lots
> of systems need such monitoring, like airplanes, powerplants,
> whatever). I'd like to avoid reinventing the wheel if possible :-)
This sounds like it falls under "statistical process control" (SPC), for
which there's a well-developed literature. Note that SPC isn't only about
identifying process shifts, but also about characterizing the normal
behavior of processes in order to determine how well they're meeting
requirements.
------------------------------
Date: 14 May 2004 12:21:39 -0700
From: mdfoster44@netscape.net (Martin Foster)
Subject: Re: Using hashes to sort number sequences
Message-Id: <6a20f90a.0405141121.1e924515@posting.google.com>
Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c80m8b$2he$1@wisteria.csv.warwick.ac.uk>...
> Quoth anno4000@lublin.zrz.tu-berlin.de (Anno Siegel):
> > Ben Morrow <usenet@morrow.me.uk> wrote in comp.lang.perl.misc
> > >
> > > my $line = <$FH>;
> > > defined $line or die "read error: $!";
> > > $line or return;
> >
> > This test won't work unless $line is chomp'ed. I'd append "...or return"
> > to the "split" line that comes next.
>
> Arrgh, no, there's a more important bug... I was assuming <> returned
> undef only on error, and false-but-defined on EOF. So, what I meant was:
>
> undef $!;
> my $line = <$FH>;
> $! and die "read error: $!";
> $line or return;
>
> Ben
Ben,
Thanks for taking the time to write a program. I've tried your code.
From the additional comments, I wrote the program as follows:
#!/usr/bin/perl -l
# Ben Morrow's Perl code from a comp.lang.perl.misc post
use strict;
use warnings;
use Symbol;
# the (*) means that the sub takes one parameter, which will be interpreted
# as a filehandle
sub read_crystal (*) {
# this will find the correct FH in case this sub is called
# from a different package (string and bareword FH names are
# relative to the current package, with exceptions for STDIN etc.)
my $FH = Symbol::qualify_to_ref $_[0], caller;
my (@atoms, $crystal);
for (1..6) {
#my $line = <$FH>;
#chomp $line;
#defined $line or die "read error: $!";
#$line or return;
# Above incorrect, use this instead
undef $!;
my $line = <$FH>;
$! and die "read error: $!";
$line or return;
my ($tmp, undef, $atom) = split ' ', $line, 3 or return;
$crystal ||= $tmp;
$crystal eq $tmp or die "bad file format: $tmp ne $crystal";
push @atoms, $atom;
}
# this creates a canonical representation of a given crystal
# (i.e. it will be the same regardless of the order the atoms
# were given in the file)
my $canon = join '|', sort @atoms;
return ($crystal, $canon);
}
my %crystals;
{
# lexical FHs like this are closed automatically when they
# go out of scope
open my $B, '<', 'b.txt' or die "can't open b.txt: $!";
while (my ($crystal, $canon) = read_crystal $B) {
$crystals{$canon} = $crystal;
}
}
{
open my $A, '<', 'a.txt' or die "can't open a.txt: $!";
while (my ($crystal, $canon) = read_crystal $A) {
if ($crystals{$canon}) {
print "$crystal is the same as $crystals{$canon}";
}
}
}
__END__
I get the following error:
read error: Bad file descriptor at new_tool.plx line 28, <$B> line 1.
So I commented out the line:
$! and die "read error: $!";
I don't understand what the above line is supposed to do.
But the script now runs beautifully and very fast, what is left of me to do
is to thank you and to try to understand the code!
I get the main part, I just can't read the last section.
You first read sequences as a "canon" (long string of ordered numbers)
into the hash %crystals for file b.
Then while you do the same for file a:
while (my ($crystal, $canon) = read_crystal $A) {
if ($crystals{$canon}) {
print "$crystal is the same as $crystals{$canon}";
}
}
I don't understand :
if ($crystals{$canon})
Does this test if the key in the hash for crystal is the same as the one being
read in from A then print - these are the same - ?
Very compact!
This code is all part of a bigger puzzle and I will make sure to
give you credit. Many thanks again!
cheers,
Martin.
------------------------------
Date: Fri, 14 May 2004 21:15:58 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Using hashes to sort number sequences
Message-Id: <c83cue$1te$1@wisteria.csv.warwick.ac.uk>
[comments below have been re-arranged somewhat to make more sense]
Quoth mdfoster44@netscape.net (Martin Foster):
> Ben,
>
> Thanks for taking the time to write a program. I've tried your code.
> From the additional comments, I wrote the program as follows:
>
> #!/usr/bin/perl -l
>
> # Ben Morrow's Perl code from a comp.lang.perl.misc post
>
> use strict;
> use warnings;
> use Symbol;
>
> # the (*) means that the sub takes one parameter, which will be interpreted
> # as a filehandle
> sub read_crystal (*) {
> # this will find the correct FH in case this sub is called
> # from a different package (string and bareword FH names are
> # relative to the current package, with exceptions for STDIN etc.)
> my $FH = Symbol::qualify_to_ref $_[0], caller;
>
> my (@atoms, $crystal);
> for (1..6) {
> #my $line = <$FH>;
> #chomp $line;
> #defined $line or die "read error: $!";
> #$line or return;
>
> # Above incorrect, use this instead
> undef $!;
> my $line = <$FH>;
> $! and die "read error: $!";
> $line or return;
>
> I get the following error:
> read error: Bad file descriptor at new_tool.plx line 28, <$B> line 1.
>
> So I commented out the line:
>
> $! and die "read error: $!";
>
> I don't understand what the above line is supposed to do.
OK, my bad for not testing it <sigh>. Sorry. What this is supposed to do
is catch both EOF and read errors on $FH. I've got this wrong twice now;
this time should be right :). What *should* be there is
undef $!;
my $line = <$FH>;
unless ($line) {
$! and die "read error: $!";
return;
}
The reason for this is that <> returns undef both on error and on EOF.
In the latter case $! will not be set, so if we clear it beforehand we
can distinguish the two. For some reason $! gets set to EBADF if the
read was successful: goodness knows why.
> my ($tmp, undef, $atom) = split ' ', $line, 3 or return;
<snip remainder>
>
>
> But the script now runs beautifully and very fast, what is left of me to do
> is to thank you and to try to understand the code!
>
> I get the main part, I just can't read the last section.
>
> You first read sequences as a "canon" (long string of ordered numbers)
> into the hash %crystals for file b.
This not exactly correct. The split leaves the strings of numbers and
spaces as they are, and the sort then sorts these. So if we had a
(simplified) input file of
aaa T1 1 2 3
aaa T2 3 4 5
then at the end of the for loop we would have
@atoms = ('1 2 3', '3 4 5');
. These strings are then sorted (in this case it does nothing) and
joined to give a 'canonical representation' of this crystal of
$canon = '1 2 3|3 4 5';
. The point of the sort is that if the crystal had been specified as
aaa T1 3 4 5
aaa T2 1 2 3
(which by your rules is the same crystal) we would still end up with the
*same* canonical representation. (This, btw, is what 'canonical' was
intended to convey: something which is canonical is in some sense
'correct' or 'usual' or 'standard'. $canon simply stands for 'canonical
representation of a crystal structure').
We then build a hash which maps the coordination structure of a crystal
(in an unambiguous form) to its name in file b: i.e., given any
crystal's structure, we can look up what it was called in file b (if it
was there).
I've just thought of two more things: firstly, this code assumes that
your data will never contain '|', and secondly it is probably worth
adding
$atom =~ s!\s+! !g;
after the split line, in case an input file has more than one space
between numbers.
> Then while you do the same for file a:
>
> while (my ($crystal, $canon) = read_crystal $A) {
> if ($crystals{$canon}) {
> print "$crystal is the same as $crystals{$canon}";
> }
> }
>
> I don't understand :
> if ($crystals{$canon})
>
> Does this test if the key in the hash for crystal is the same as the one being
> read in from A then print - these are the same - ?
Yes: we now have an unambiguous rep'n of the crystal we have just read
from a, and this checks to see if we found a name for that crystal in
file b; if we did, it says so.
It should be clear now how to modify the program to check three files
against each other (if it is then you've understood what's going on)?
> Very compact!
That's Perl for you :)
> This code is all part of a bigger puzzle and I will make sure to
> give you credit.
Don't worry about that: this is just a coding of the usual Perl
algorithm for finding duplicates (in this case, coordination structures
which are duplicated across the files): make the potential duplicates
into hash keys.
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* ben@morrow.me.uk *
------------------------------
Date: 14 May 2004 15:00:41 -0700
From: yjin6666@hotmail.com (yjin6666@hotmail.com)
Subject: what's wrong with my CPAN module
Message-Id: <edd5194d.0405141400.7c4c44ce@posting.google.com>
Hi,
I use to able to install perl modules by CPAN (perl -MCPAN -e shell).
Yesterday when I was installing some perl modules, I also updated CPAN
as the system made the suggestion. Now I have a problem as the
following:
[root@versaw03 jin]# perl -MCPAN -e shell
Undefined value assigned to typeglob at (eval 14) line 15, <RC> line
11.
Warning [/etc/inputrc line 11]:
Invalid variable `mark-symlinked-directories'
CPAN.pm panic: Lockfile /root/.cpan/.lock
reports other host localhost.localdomain and other process 5008.
Cannot proceed.
Could someone tell me how to solove this problem.
Many thanks,
Kim
------------------------------
Date: Fri, 14 May 2004 23:10:03 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: what's wrong with my CPAN module
Message-Id: <c83jkb$5p1$2@wisteria.csv.warwick.ac.uk>
Quoth yjin6666@hotmail.com (yjin6666@hotmail.com):
> Hi,
>
> I use to able to install perl modules by CPAN (perl -MCPAN -e shell).
> Yesterday when I was installing some perl modules, I also updated CPAN
> as the system made the suggestion. Now I have a problem as the
> following:
>
> [root@versaw03 jin]# perl -MCPAN -e shell
> Undefined value assigned to typeglob at (eval 14) line 15, <RC> line
> 11.
> Warning [/etc/inputrc line 11]:
> Invalid variable `mark-symlinked-directories'
> CPAN.pm panic: Lockfile /root/.cpan/.lock
> reports other host localhost.localdomain and other process 5008.
> Cannot proceed.
>
> Could someone tell me how to solove this problem.
Make sure you don't have any CPAN processes running and delete
/root/.cpan/.lock.
Ben
--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~ Jorge Luis Borges, 'The Babylon Lottery'
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6565
***************************************