[29739] in Perl-Users-Digest
Perl-Users Digest, Issue: 983 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 27 16:10:10 2007
Date: Sat, 27 Oct 2007 13:09:07 -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 Sat, 27 Oct 2007 Volume: 11 Number: 983
Today's topics:
Re: configurable variables in own file? <tzz@lifelogs.com>
Re: Data::Dumper and UTF-8 <hjp-usenet2@hjp.at>
Re: FAQ 5.11 How can I write() into a string? <hjp-usenet2@hjp.at>
Re: FAQ 5.11 How can I write() into a string? <brian.d.foy@gmail.com>
Re: FAQ 5.11 How can I write() into a string? <brian.d.foy@gmail.com>
Re: FAQ 5.11 How can I write() into a string? <jurgenex@hotmail.com>
Re: How to fetch output of some other script in the cur <5502109103600001@t-online.de>
how to redirect error to variable <stoupa@practisoft.cz>
Re: how to redirect error to variable <bik.mido@tiscalinet.it>
Re: how to redirect error to variable <paduille.4061.mumia.w+nospam@earthlink.net>
need help with hash - been too long working in Perl <gjwpp88@gmail.com>
Re: packing a C structure <5502109103600001@t-online.de>
Re: perl time function <hjp-usenet2@hjp.at>
Re: PID of exec <Juha.Laiho@iki.fi>
Re: Regular expression to match only strings NOT contai <jesse.houwing@newsgroup.nospam>
Re: TeX pestilence <bik.mido@tiscalinet.it>
Re: TeX pestilence <paduille.4061.mumia.w+nospam@earthlink.net>
Re: TeX pestilence (Victor Eijkhout)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 27 Oct 2007 10:28:14 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: configurable variables in own file?
Message-Id: <m2ir4spofl.fsf@lifelogs.com>
On 26 Oct 2007 18:27:03 GMT xhoster@gmail.com wrote:
x> I already know what a hash looks like in Perl. Why spend the
x> effort to learn what a hash looks like in some other language, too,
x> without some compelling reason?
You're joking, I hope. We write software for the users, not for
ourselves (I'm obviously not discussing one-off applications here). Why
should they have to learn Perl to configure things? To make sure it's
harder to port the application to another language, or to test their
intelligence in a needless chore?
AppConfig's syntax in particular is dictated by the fact that every
configuration option is available both from a file AND from the command
line, so you can say "-option1 key1=val1 -option1 key2=val2" for a hash
"option1" easily. Users seem to like that, in my experience.
x> Ted Zlatanov <tzz@lifelogs.com> wrote:
>> YAML and XML can do this as well. YAML will handle multi-level hashes
>> and lists, while XML may be better depending on your environment. Any
>> one of them is easily parseable by other languages as well--don't limit
>> your data to just Perl interpretation.
x> That is a good idea if you have some inkling that your configuration file
x> will need to be read by some other language. But how frequent is that?
Again, you're joking I hope. I recommend 'The Art of Unix Programming'
for starters at http://catb.org/~esr/writings/taoup/ as I really don't
have the time to explain it all, and ESR has done a better job anyhow.
If you want to find points to argue, go for
http://catb.org/~esr/writings/taoup/html/textualitychapter.html
(Textuality) but I hope you'll read the whole book first.
x> If the configuration is for my Perl program, why would anything other
x> than Perl and the person doing the configuration need to be able to read
x> it?
(I'll use "configuration editor user" to mean the person who is supposed
to edit the configuration and has access to write it)
You're assuming a lot of things in that one sentence:
1) the configuration and the program will be forever joined
2) only your Perl application and the configuration editor user need to read it
3) only the configuration editor user is interested in its contents
4) your application will remain a Perl program forever
When they are all true, go for an all-Perl configuration. I can't see
the future so I prefer to program without those assumptions.
x> The security risk seems to be largely a red herring to me. If the
x> potentially malicious user is going to be running the perl program as
x> himself, then he can already make the program do anything he wants just by
x> changing the main code itself, with no need to trick it by changing the
x> configuration file.
You're assuming that the user running the program is the configuration
editor user. There's a risk a malicious configuration editor user will
compromise other users by editing the configuration. Even if you think
the risk is small, why take it?
Also, don't discount inadvertent security compromises where the
configuration editor user accidentally enters malicious code, and covert
compromises where the configuration editor user is tricked into entering
malicious code that looks OK at a glance.
x> If the potentially malicious user is going to be running the code as
x> me, well, 99% of the time I'm no more going to make the configuration
x> file writable by him than I am going to make the main code itself
x> writable by him, regardless of what mechanism is used to hold the
x> configuration.
I hope you see that this is a consequence of writing your configuration
as code. If the configuration can't be used to compromise the program
because it's just data, the risk is much lower and malicious users could
change options only in ways allowed by the configuration syntax.
There's still a risk from "evil" data, sure, but it's a well understood
one and Perl even has a taint mechanism to deal with it. How do you
untaint Perl code?
Let's put it another way. Do you give your programs a -e switch
analogous to Perl's, which will just run whatever is passed?
x> There are good reasons for using text-only configuration, but those reasons
x> are not universally applicable, and in my experience in Perl they are not
x> even very common.
There's too much ambiguity in your statement, sorry.
Ted
------------------------------
Date: Sat, 27 Oct 2007 15:42:19 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Data::Dumper and UTF-8
Message-Id: <slrnfi6g1r.77r.hjp-usenet2@zeno.hjp.at>
On 2007-10-21 21:27, August Karlstrom <fusionfive@comhem.se> wrote:
> Hi,
>
> I'm trying to make Dumper display an UTF-8 string but I can't get it to
> work:
>
> $ cat test.pl
> #!/usr/bin/perl -w
>
> use strict;
> use Data::Dumper;
> use utf8;
>
> binmode(STDOUT, ":utf8");
>
> my $s = "\x{263a}";
>
> print "$s\n";
> print Dumper($s);
> print Dumper("☺");
>
> $ ./test.pl
> ☺
> $VAR1 = "\x{263a}";
> $VAR1 = "\x{263a}";
Looks ok to me. What output did you expect?
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Sat, 27 Oct 2007 17:15:58 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 5.11 How can I write() into a string?
Message-Id: <slrnfi6lhe.77r.hjp-usenet2@zeno.hjp.at>
On 2007-10-27 11:52, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>> On 2007-10-11 07:03, PerlFAQ Server <brian@stonehenge.com> wrote:
>> > 5.11: How can I write() into a string?
>> >
>> > See "Accessing Formatting Internals" in perlform for an swrite()
>> > function.
>>
>> I think a more useful companion question would be
>>
>> How can I open a file handle to a string?
>>
>> Use open(my $fh, '>', \$string); or open(my $fh, '<', \$string);
>
> With reference to IO::String for pre-5.8 perls?
Yup. Something like this:
------------------------------------------------------------------------
How can I open a file handle to a string?
Since Perl 5.8.0, you can pass a reference to a scalar instead of
the filename to create a file handle which can be used to read of
write the string:
open(my $fh, '>', \$string) or die ...
print $fh "foo\n";
print $fh "bar\n"; # $string now contains "foo\nbar\n"
open(my $fh, '<', \$string) or die ...
my $x = <$fh>; # $x now contains "foo\n"
With older perls the IO::String module provides similar
functionality.
------------------------------------------------------------------------
hp
--
_ | Peter J. Holzer | It took a genius to create [TeX],
|_|_) | Sysadmin WSR | and it takes a genius to maintain it.
| | | hjp@hjp.at | That's not engineering, that's art.
__/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex
------------------------------
Date: Sat, 27 Oct 2007 14:17:42 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 5.11 How can I write() into a string?
Message-Id: <271020071417420054%brian.d.foy@gmail.com>
In article <slrnfi6683.77r.hjp-usenet2@zeno.hjp.at>, Peter J. Holzer
<hjp-usenet2@hjp.at> wrote:
> On 2007-10-11 07:03, PerlFAQ Server <brian@stonehenge.com> wrote:
> > 5.11: How can I write() into a string?
> >
> >
> > See "Accessing Formatting Internals" in perlform for an swrite()
> > function.
> >
>
> I think a more useful companion question would be
>
> How can I open a file handle to a string?
That would be a good question, although you might want to phrase is
"How do I print to a string instead of a file?".
If someone writes out the full answer, I'll add it to the FAQ. Please
send the answer to perlfaq-workers as noted in perlfaq.pod.
Thanks, :)
------------------------------
Date: Sat, 27 Oct 2007 14:26:40 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 5.11 How can I write() into a string?
Message-Id: <271020071426402375%brian.d.foy@gmail.com>
In article <271020071417420054%brian.d.foy@gmail.com>, brian d foy
<brian.d.foy@gmail.com> wrote:
> In article <slrnfi6683.77r.hjp-usenet2@zeno.hjp.at>, Peter J. Holzer
> <hjp-usenet2@hjp.at> wrote:
> > How can I open a file handle to a string?
> If someone writes out the full answer, I'll add it to the FAQ. Please
> send the answer to perlfaq-workers as noted in perlfaq.pod.
Oh, never mind. Peter already posted an answer. I've added that to the
FAQ.
Thanks, :)
------------------------------
Date: Sat, 27 Oct 2007 19:48:39 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: FAQ 5.11 How can I write() into a string?
Message-Id: <rCMUi.1515$p%.1482@trndny03>
brian d foy wrote:
> In article <slrnfi6683.77r.hjp-usenet2@zeno.hjp.at>, Peter J. Holzer
> <hjp-usenet2@hjp.at> wrote:
>
>> On 2007-10-11 07:03, PerlFAQ Server <brian@stonehenge.com> wrote:
>>> 5.11: How can I write() into a string?
>>>
>>>
>>> See "Accessing Formatting Internals" in perlform for an swrite()
>>> function.
>>>
>>
>> I think a more useful companion question would be
>>
>> How can I open a file handle to a string?
>
> That would be a good question, although you might want to phrase is
> "How do I print to a string instead of a file?".
Well, isn't the answer to that question a simple:
Use the sprintf() function?
jue
------------------------------
Date: Sat, 27 Oct 2007 17:52:40 +0200
From: Josef Moellers <5502109103600001@t-online.de>
Subject: Re: How to fetch output of some other script in the current running perl script?
Message-Id: <ffvmse$hqn$02$1@news.t-online.com>
ritugoyal12@gmail.com wrote:
> Hi,
> I want to execute some script (May or May not be perl script) from a
> perl script and print the output of that executed script.
> My Operating system are Windows and Mac OS(Unix).
> I was trying the following code without success:
>
>
> Code
> $Response = system("start test.wbt");
> print $Response;
>
> By the above code I am able to execute test.wbt but program doesnt
> wait for test.wbt to get executed.
Maybe "start" runs "test.wbt" in the background?
--
Mails please to josef dot moellers
and I'm on gmx dot de.
------------------------------
Date: Sat, 27 Oct 2007 15:30:59 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: how to redirect error to variable
Message-Id: <ffveiq$17n5$1@ns.felk.cvut.cz>
I'm running script on server where sometime some service fail (mysql server,
user log is closed and reopened etc). I have not these processes under
control, this is virtual server hosting.
I need to redirect error messages to variable, send these messages vie
sendmail to user and exit from my script after I do needed actions. For
these reasons I wrote mu own sub for some SIG, say for SIG-PIPE.
This is my code
use Carp qw(cluck);
.....
$SIG{'PIPE'}=sub {
local *STDERR;
my $errfile=$backups . '/err.txt';
open STDERR,"> $errfile";
cluck("SIG-PIPE ");
close STDERR;
open ERR,"< $errfile";
my $err='';
while (<ERR>)
{
$err .= $_;
}
close STDERR;
print $err;
exit;
};
This work as expected. I tried to use IO::Scalar but without success. What
is wrong in this code?
use IO::Scalar;
$SIG{'PIPE'}=sub {
my $err='';
$SH=new IO::Scalar \$err;
open STDERR,,">&SH";
cluck("SIG-PIPE ");
print $err;
exit;
};
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Sat, 27 Oct 2007 17:02:30 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: how to redirect error to variable
Message-Id: <2nk6i3hm2319nvrhl1gn03h3r33m17nvcn@4ax.com>
On Sat, 27 Oct 2007 15:30:59 +0200, "Petr Vileta"
<stoupa@practisoft.cz> wrote:
>I need to redirect error messages to variable, send these messages vie
>sendmail to user and exit from my script after I do needed actions. For
IIUC, then you can hook into $SIG{__DIE__}.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 27 Oct 2007 11:21:00 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: how to redirect error to variable
Message-Id: <13i6ptf21h47e9b@corp.supernews.com>
On 10/27/2007 08:30 AM, Petr Vileta wrote:
> [...]
> This work as expected. I tried to use IO::Scalar but without success.
> What is wrong in this code?
>
> use IO::Scalar;
> $SIG{'PIPE'}=sub {
> my $err='';
> $SH=new IO::Scalar \$err;
> open STDERR,,">&SH";
> cluck("SIG-PIPE ");
> print $err;
> exit;
> };
>
I don't think it'll work with IO::Scalar. Why not do it the right way?
my $err = '';
$SIG{PIPE} = sub {
$err .= Carp::shortmess('SIG-PIPE ');
print $err;
exit 1;
};
I doubt you want $err to be lexically scoped within the sub, and I think
you need to read "man Carp" again.
------------------------------
Date: Sat, 27 Oct 2007 19:57:14 -0000
From: JerryP <gjwpp88@gmail.com>
Subject: need help with hash - been too long working in Perl
Message-Id: <1193515034.814092.129460@o3g2000hsb.googlegroups.com>
Hi!
This is simple? But it has been a while that I have programmed in
Perl. What I am wanting to do is build a hash from a text file:
text:
79706-0000 2229.17
79706-0000 2523.25
79701-0000 53904.48
79701-0000 78957.81
79701-0000 378043.04
79701-0000 1255172.34
79702-0000 7367.23
79702-0000 20742.95
79702-0000 67331.82
79702-0000 137629.57
79703-0000 1444.18
79701-0000 57565.48
79703-0000 2415.00
79703-0000 2787.97
79703-0000 4780.55
79703-0000 5061.21
79703-5011 1125.80
79704-0000 2382.31
79705-0000 4612.65
79706-0000 1416.50
79703-0000 64014.50
With script:
use strict;
local( *FI, *FO );
my @text = ();
my @zip = ();
my %ref;
open ( FI, "msj_sare.lst" ) or die "Couldn't open c:\\vf\
\sj_sare.lst";
my @text_ = <FI>;
close FI;
s/\n// for( @text = @text_ );
foreach ( @text ) {
/(\d+)\-(\d+)(\s+)(-?(?:\d+(?:\.\d*)?|\.\d+))/;
push( @zip, $1 );
push( @{ $ref{ $1 }{ $2 }},$_ );
}
# then sort with
open ( FO, "+>msj_sare.jwp" ) or die "Couldn't open c:\\vf\
\sj_sare.jwp";
foreach my $family ( sort keys %ref ) {
# for my $role ( sort { $ref{$b} <=> $ref{$a} } keys %
{ $ref{$family} } ) {
print " $family*$ref{ $family }*\n";
for my $role ( sort keys %{ $ref{$family} } ) {
print(join(', ',sort keys ${ $ref{$family} }),"\n");
# print "$ref{$family}{$role}[0]\n";
print FO "$ref{$family}{$role}[0]\n";
}
print FO "\n";
}
I am wanting to print out the data in the following format:
79701-0000 1255172.34
79701-0000 378043.04
79701-0000 78957.81
79701-0000 57565.48
79701-0000 53904.48
79702-0000 137629.57
79702-0000 67331.82
79702-0000 20742.95
79702-0000 7367.23
79703-0000 64014.50
79703-0000 5061.21
79703-0000 2787.97
79703-0000 2415.00
79703-0000 4780.55
79703-0000 1444.18
79703-5011 1125.80
79704-0000 2382.31
79705-0000 4612.65
79706-0000 2523.25
79706-0000 2229.17
79706-0000 1416.50
Thanks,
Jerry
------------------------------
Date: Sat, 27 Oct 2007 17:56:41 +0200
From: Josef Moellers <5502109103600001@t-online.de>
Subject: Re: packing a C structure
Message-Id: <ffvn3v$hqn$02$2@news.t-online.com>
jl_post@hotmail.com wrote:
> On Oct 25, 10:57 pm, haai...@gmail.com wrote:
>> hi ,,,
>>
>> iam trying to pack a C structure to send via socket..i would like to
>> know how to frame the template for the C structure..
>>
>> this is my structure
>>
>> typedef struct buffer_t {
>> uint32_t a;
>> char b[16];
>> uint32_t c;
>> uint32_t d;
>> char e[6];
>> char f[8];
>>
>> } buffer_t;
>>
>> kindly suggest me the format for the pack function call..this will
>> help me to solve my issue...
>
>
> Hi,
>
> I have the impression that what you want is to pack values in Perl
> into a binary string of data that matches how a C program would do it.
>
> If I'm right, this might work:
>
> my $stringToSend = pack('I c16 I I c6 c8',
> <YOUR PERL VARIABLES GO HERE>);
>
> However, it's quite likely that the C program packs the data in a
> way so that they are properly byte-aligned. If that's the case, the
> above pack string may not work, and you'd probably have better luck
> with the following pack string that inserts padding in the proper
> places:
>
> my $stringToSend = pack('I c16 x![I] I I c6 c8 x![I]',
> <YOUR PERL VARIABLES GO HERE>);
>
> Out of curiosity, when you declare b as a char array of 16 elements
> is that because you're sending over 16 separate char values, or are
> you sending one null-terminated string that can be a maximum of 15
> characters long?
>
> If your intention is to use b[16] as a single string (holding a
> maximum of 15 characters), you probably want to replace "c16" in the
> above pack strings to "Z16" (you may also want to replace "c6" and
> "c8" with "Z6" and "Z8"). That way, instead of sending over 33
> separate variables (that is, three ints plus 30 characters), you'd be
> sending over six separate variables (that is, three ints plus three
> strings).
>
> So if it's the case that you want to send over three ints and three
> strings, you might use code like this:
>
> my $a = 1;
> my $b = "Title of book";
> my $c = 3;
> my $d = 4;
> my $e = "March";
> my $f = "Sunday";
> my $stringToSend = pack('I Z16 x![I] I I Z6 Z8 x![I]',
> $a, $b, $c, $d, $e, $f);
I "is _at_least_ 32 bits wide", so, if the OP is on a 64 bit machine
which has 64 bit "int"s, you're toast!
Better use 'L', which more closely matches "uint32_t".
--
Mails please to josef dot moellers
and I'm on gmx dot de.
------------------------------
Date: Sat, 27 Oct 2007 17:00:42 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: perl time function
Message-Id: <slrnfi6kkr.77r.hjp-usenet2@zeno.hjp.at>
On 2007-10-27 11:48, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>> On 2007-10-17 15:53, Ben Morrow <ben@morrow.me.uk> wrote:
>> > Hours (or, at any rate, 'calendar hours') are not necessarily 3600
>> > seconds long, because of leap seconds. When doing calendar calculations,
>> > it's best to use a module that does it right.
>>
>> When doing calendar calculations which may possibly include future dates
>> you cannot use leap seconds. Leap seconds are determined by observation
>> every six months, so at this point of time it is impossible to know how
>> many seconds the year 2008 will have.
>>
>> This is why POSIX timestamps don't use leap seconds. The POSIX timestamp
>> 1199145600 always refers to 2008-01-01 00:00:00 UTC and the POSIX
>> timestamp 1230768000 always refers to 2009-01-01 00:00:00 UTC,
>> regardless of the number of actual seconds between these dates.
>
> OK, now I'm fascinated... what happens when a leap second occurs?
> time(3) returns the same value for two seconds in a row? That sounds...
> confusing, although I suppose it's similar to what adjtime(2) does...
>
> [Spurious Perl connection: this is similar to the hobbit's system of
> treating leap days as not part of the year... :)]
What does the hobbit's system have to do with Perl?
Anyway, to answer the question, there are a number of ways of dealing
with leap seconds and it depends on the system which one is used:
1) Just ignore the problem. At some time after the leap second, the
system's time synchronisation system (probably NTP) will notice that
the clock is now one second fast (or slow) and adjust accordingly.
Different systems in your network will probably notice this at
different times and the PLL may overshoot, so for a few hours the
clocks of the systems may differ by a second or more until they have
all converged again. However, you have similar problems after a
reboot and reboots probably occur more often than leap seconds.
2) Step the clock backwards or forwards by 1 second. Stepping the clock
backwards may cause problems for some programs which assume
monotonically increasing time. But again, time steps often occur
after a reboot, so that may be acceptable.
3) Halt the clock instead of stepping backwards: For one second, all
calls to gettimeofday either return the same value, or just increment
the microsecond counter.
I am not sure, but I think Linux uses the third method. Don't know about
other systems.
hp
--
_ | Peter J. Holzer | It took a genius to create [TeX],
|_|_) | Sysadmin WSR | and it takes a genius to maintain it.
| | | hjp@hjp.at | That's not engineering, that's art.
__/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex
------------------------------
Date: Sat, 27 Oct 2007 17:07:04 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: PID of exec
Message-Id: <ffvr0g$4ou$1@ichaos2.ichaos-int>
hendedav@gmail.com said:
>I read another post that said after running the exec statment, it is
>a highly recommended to use an "exit();" statement. Does this sound
>correct?
It's a good safety belt -- it's for the case where the exec() call fails.
If that happens, the child will continue running whatever code there is
beyond the child branch of the fork - which definitely is something that
was never intended to happen. In addition to exit(), you might want to
log an error somewhere, and it might be good idea to exit() with
a nonzero status, so your parent process could also catch and log the
failure situation.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: Sat, 27 Oct 2007 19:45:49 +0000 (UTC)
From: Jesse Houwing <jesse.houwing@newsgroup.nospam>
Subject: Re: Regular expression to match only strings NOT containing particular words
Message-Id: <21effc90271d78c9e6f9dfeb1b3a@news.microsoft.com>
Hello Dylan,
> On Oct 20, 2:40 am, "J?rgen Exner" <jurge...@hotmail.com> wrote:
>
>> J?rgen Exner wrote:
>>
>>> Dylan Nicholson wrote:
>>>
>>>> I can write a regular expression that will only match strings that
>>>> are NOT the word apple:
>>>>
>>>> ^([^a].*|a[^p].*|ap[^p].*|app[^l].*|apple.+)$
>>>>
>>>> But is there a neater way, and how would I do it to match strings
>>>> that are NOT the word apple OR banana? Then what would be needed to
>>>> match only strings that do not CONTAIN the word "apple" or "banana"
>>>> or "cherry"?
>>>>
>>> !(/apple/ or /banana/ or /cherry/)
>>>
>> Actually, coming to think of it: there is no good reason to use a RE
>> in the first place because you are looking for a literal substring
>> only without any of the meta-functionality of REs. The proper tool
>> for that much simpler task is index().
>>
>> jue
>>
> Sure, except the regular expression mechanism is already in place as a
> feature of the application. I was just curious if it could be used to
> solve a particular problem.
>
> Unfortunately "!(/apple/ or /banana/ or /cherry/)" doesn't work with
> Microsoft's .NET regex library.
It isn't ideal, but this will do the trick:
^((?!\b(cherry|banana|apple)\b).)*$
Make sure you set the option SingleLine and unset the option Multiline when
appropriate. If the application is under your control, it would probably
be easier to add a checkbox which will invert the match result from Success
to fail.
Though as Jue pointed out, it's probably faster and easier to maintain when
you implement a "bad words" list and use indexOf to see if the string is
in there somewhere. You might even use \bword\b in a regex for that.
--
Jesse Houwing
jesse.houwing at sogeti.nl
------------------------------
Date: Sat, 27 Oct 2007 15:58:32 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: TeX pestilence
Message-Id: <dvg6i3h16ftb5ees1sjth1olvn0avg200r@4ax.com>
On Fri, 26 Oct 2007 23:13:41 +0200, David Kastrup <dak@gnu.org> wrote:
>used without breaking ligatures or kerns. So one of the most basic
>programming tasks to be imagined is a "Dirty Trick" and the author of
>the language does not have a solution close to satisfactory.
Futhermore: the author of a language, who incidentally happens to be a
genius!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 27 Oct 2007 11:24:39 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: TeX pestilence
Message-Id: <13i6ptg4sikad9d@corp.supernews.com>
On 10/27/2007 06:09 AM, Michele Dondi wrote:
> On Fri, 26 Oct 2007 20:51:32 +0900, Gernot Hassenpflug
> <gernot@nict.go.jp> wrote:
>
>>> Is there a particular reason you elided all the detailed explanation I
>>> give? First: I am one of the most renowned TeX hackers in the field,
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> LOL
>
> Well, he is!
>
>
> Michele
Maybe, but this thread still does not belong in comp.lang.perl.misc.
------------------------------
Date: Sat, 27 Oct 2007 12:51:09 -0500
From: see@sig.for.address (Victor Eijkhout)
Subject: Re: TeX pestilence
Message-Id: <1i6mtpm.gdgbzbp21hdaN%see@sig.for.address>
David Kastrup <dak@gnu.org> wrote:
> And
> that's not least because it is a team from a blind and a lame
> programming system: only TeX's stomach can _affect_ a variable, but
> only TeX's mouth can _look_ at a variable and make decisions based on
> its values, decisions for which a resulting action again can only be
> done by the blind stomach. Both systems kick in at different points
> of time and different circumstances. And you must not employ the
> stomach in the middle of typesetting a word, or kernings and ligatures
> will break.
Et cetera.
When explaining the mouth and stomach (*cough* eijkhout.net/tbt *cough)
I've been told any number of times "why don't you call this the parser
and the code generator" which I've always objected to, pointing for
instance to the fact that the code generator can change the syntax that
the parser accepts. Still, it is a bit like that, not? There are two
stages, and sometimes they have a cart and horse ordering.
I wonder if Knuth had any deep thoughts about this. It kinda makes
sense: first you have the expansion part that does the simple
replacement tasks, and then the actual code generation that does the
typesetting and changing values of variables. This would make sense if
those variables only controlled the typesetting, but as I said above,
some of them control the parsing layer.
But while making sense, it is also a bit nonsensical in other
circumstnaces as you point out.
> that manner. Programming TeX really sucks, and its creator Donald
> Knuth has expressed his amazement at what tasks people actually have
> bothered implementing in TeX
Judging by what I've seen of his own macros, that doesn't surprise me.
> says that it probably had been a mistake from him to let himself be
> prodded into adding the basics for making programming, however awful,
> basically possible in TeX.
Really? Where did he say that? Personally I'd say that a programmable
text processor is a great idea, it just needs a better language.
Victor.
--
Victor Eijkhout -- eijkhout at tacc utexas edu
------------------------------
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 V11 Issue 983
**************************************