[22494] in Perl-Users-Digest
Perl-Users Digest, Issue: 4715 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 16 00:06:40 2003
Date: Sat, 15 Mar 2003 21:05:07 -0800 (PST)
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, 15 Mar 2003 Volume: 10 Number: 4715
Today's topics:
Re: [Probably] a stupid question about REGEX (Mark Healey)
Re: [Probably] a stupid question about REGEX <noreply@gunnar.cc>
Re: [Probably] a stupid question about REGEX <jurgenex@hotmail.com>
Re: [Probably] a stupid question about REGEX <uri@stemsystems.com>
Re: file parse into hash and writing output with certai (Anno Siegel)
Re: file parse into hash and writing output with certai (david)
Re: FILEHANDLE and search and replace question <goldbb2@earthlink.net>
Re: frames without files ? <spam@thecouch.homeip.net>
Re: how to create NULL character in perl <kalinabears@hdc.com.au>
Re: how to create NULL character in perl <uri@stemsystems.com>
Re: How to find a word which is palindromica using REGE <abigail@abigail.nl>
Re: How to find a word which is palindromica using REGE <peakpeek@purethought.com>
Re: How to find a word which is palindromica using REGE (Anno Siegel)
Re: it's true but can I say so ? <abigail@abigail.nl>
Re: it's true but can I say so ? <kevin@vaildc.net>
Re: it's true but can I say so ? <goldbb2@earthlink.net>
Re: it's true but can I say so ? <jurgenex@hotmail.com>
Re: it's true but can I say so ? <goldbb2@earthlink.net>
Perl - How to parse a data file to display occurances o (shree)
Re: Perl - How to parse a data file to display occuranc <noreply@gunnar.cc>
Re: Printing a 2d array <mail@annuna.com>
Re: Question: What's the proper way to retrieve last mo (Tad McClellan)
socket question <smackdab1@hotmail.com>
Re: Sorting using DB_File/btree <peakpeek@purethought.com>
Re: Stupid Perl Questions <wsegrave@mindspring.com>
Re: War against spam (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Mar 2003 18:03:07 -0600
From: die@spammer.die (Mark Healey)
Subject: Re: [Probably] a stupid question about REGEX
Message-Id: <VP2SpNyJrzMZ-pn2-KPjZi0d8ddwP@adsl-63-207-135-60.dsl.sndg02.pacbell.net>
On Sat, 15 Mar 2003 21:29:51 UTC, Uri Guttman <uri@stemsystems.com>
wrote:
> >>>>> "MH" == Mark Healey <die@spammer.die> writes:
>
> MH> All I want to do is determine if $_ is a substring of $last, ignoring
> MH> case.
>
> MH> For example I submitted "mission hills" to the website and got these
> MH> three responses. It is an ORed keyword search which gives me the
> MH> false positive third line because it contains "hills". I'd like to
> MH> filter the false positives.
>
>
> MH> MISSION HILLS Sat 8-12. Multi-fam. Fun items, good prices. 3760 Hawk
> MH> St. off University btween Sutter & Bush
>
> MH> MISSION HILLS Moving sale Sat-Sun 9-5. Furniture, clothing, pictures &
> MH> more. 4126 ARDEN WAY
>
> MH> MOUNT HELIX, Sat 7-1. Multi-Family. Rolling Hills/ Sunrise Hills.
> MH> Furn, appls, toys, antiques, clothes, misc
>
> so make it an ANDed search. what is the problem? just loop over the keys
> and bail out if any fail. if you fall through then all the keys matched
> and you have a matched line.
The problem is that I always get a false. I think it has something to
do with the way I'm formating the regexp.
When I have $_ in there I think it is being interperated as an end of
line followed by an underscore.
> you seem to be running in a strange circle to get a simple search done.
It makes some sense if you know the larger context.
------------------------------
Date: Sun, 16 Mar 2003 02:08:15 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [Probably] a stupid question about REGEX
Message-Id: <b50j5o$248t72$1@ID-184292.news.dfncis.de>
Mark Healey wrote:
> All I want to do is determine if $_ is a substring of $last, ignoring
> case.
Like Uri said, it should be:
if ($last =~ /$_/i)
> For example I submitted "mission hills" to the website and got these
> three responses. It is an ORed keyword search which gives me the
> false positive third line because it contains "hills". I'd like to
> filter the false positives.
Okay, I made a couple of adjustments to your initial code fragment based
on the additional info:
my $last;
foreach(@lines)
{
if (/\A">/)
{
my $flag = 0;
foreach(@searchTerms)
{
if ($last =~ /$_/i)
{
$flag = 1;
next;
}
else
{
$flag = 0;
last;
}
}#end foreach searchTerms
push(@descriptions, $last) if $flag;
}
$last = $_;
}# end foreach lines
As you can see, I added $flag to determine whether to add $last to
@descriptions or not. It appears to me that the unwanted result you
received was caused by a faulty semantic rather than being a regexp problem.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 16 Mar 2003 02:04:05 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: [Probably] a stupid question about REGEX
Message-Id: <pYQca.8012$IM3.3170@nwrddc03.gnilink.net>
Mark Healey wrote:
> All I want to do is determine if $_ is a substring of $last, ignoring
> case.
If you want to find out if $x is a substring of $y then REs are the wrong
tool.
It's like killing a fly with a shotgun.
Instead just use 'index'. And if you want to ignore case then use a normal
form for your arguments, e.g. all upper case:
if (index (uc($x), uc($y)) {
print "$x contains $y\n";
}
------------------------------
Date: Sun, 16 Mar 2003 04:11:41 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: [Probably] a stupid question about REGEX
Message-Id: <x74r6454sj.fsf@mail.sysarch.com>
>>>>> "MH" == Mark Healey <die@spammer.die> writes:
MH> On Sat, 15 Mar 2003 21:29:51 UTC, Uri Guttman <uri@stemsystems.com>
MH> wrote:
MH> The problem is that I always get a false. I think it has something to
MH> do with the way I'm formating the regexp.
MH> When I have $_ in there I think it is being interperated as an end of
MH> line followed by an underscore.
i still haven't seen any real data with real results and real code that
is just the regexes. if you are getting false where you don't think you
should be that is a regex issue. the outer code is meaningless then.
>> you seem to be running in a strange circle to get a simple search done.
MH> It makes some sense if you know the larger context.
not if what you just said is true. checking for strings is simple. you
are clouding the waters with all kinds of big picture i don't care
about. ANDing vs ORing is only important if the booleans going in are
correct. you just claimed they aren't. focus on one bug at a time.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: 15 Mar 2003 23:41:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: file parse into hash and writing output with certain format to new file
Message-Id: <b50dn8$dbj$1@mamenchi.zrz.TU-Berlin.DE>
david <dwlepage@yahoo.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<b4vp2u$s2o$1@mamenchi.zrz.TU-Berlin.DE>...
> > david <dwlepage@yahoo.com> wrote in comp.lang.perl.misc:
[...]
> Thank you for the feedback. I have changed my code using your
> suggestions, and here is where I am.
>
> #!/usr/bin/perl -w
> use strict;
>
> my %records;
> my (@ser, @seperate, @fields);
> my $ser;
You still declare variables you never use. Only %records and @separate
seem to have a meaning outside the loop. Declaring $ser here makes it
hard to find an error later. This should just be
my ( %records, @separate);
> open (FILE, "<import0.dat") || die "Couldn't open file; $!\n";
> open (OUT, ">output.dat") || die "Couldn't create file; $!\n";
> open (NEWOUT, ">newout.dat") || die "Couldn't create; $!\n";
>
> while ( <FILE> ) {
> my @fields = split ( /,/ );
> if ( $fields[7] =~ m{^\$\$S\/N:(\w+)} ) {
> my $ser = '$$' . $1 . '$$';
> ( $fields[1], $ser ) = ( $ser, $fields[1] );
> push (@seperate, join (',', @fields));
> $records{$ser} = $fields[1];
>
> }
> print NEWOUT "User =$fields[1]\n";
> print NEWOUT "Number =$ser\n";
Well, you are trying to print $ser, which is only defined inside the
"if"-block. What you are accessing is the variable "$ser" you declared
earlier, which muddles the issue. Perl wouldn't have compiled the code
without the spurious declaration, and would have been right.
What you really must do here is decide whether something should go to
NEWOUT at all if $fields[7] doesn't match the pattern. If it shouldn't,
move the two print-statements into the if-block, and you're done.
If you need to print something to NEWOUT in every case, pull the
declaration of $ser out of the if-block (but not out of the loop). Then
add an else-clause that sets $ser to something reasonable when $fields[7]
doesn't match. The print-statements are positioned right for this case,
but should be indented to match the other material in the loop.
>
> }
[...]
Anno
------------------------------
Date: 15 Mar 2003 20:00:46 -0800
From: dwlepage@yahoo.com (david)
Subject: Re: file parse into hash and writing output with certain format to new file
Message-Id: <b09a22ae.0303152000.2e4b0d15@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<b50dn8$dbj$1@mamenchi.zrz.TU-Berlin.DE>...
> david <dwlepage@yahoo.com> wrote in comp.lang.perl.misc:
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> > news:<b4vp2u$s2o$1@mamenchi.zrz.TU-Berlin.DE>...
> > > david <dwlepage@yahoo.com> wrote in comp.lang.perl.misc:
>
> [...]
>
> > Thank you for the feedback. I have changed my code using your
> > suggestions, and here is where I am.
> >
> > #!/usr/bin/perl -w
> > use strict;
> >
> > my %records;
> > my (@ser, @seperate, @fields);
> > my $ser;
>
> You still declare variables you never use. Only %records and @separate
> seem to have a meaning outside the loop. Declaring $ser here makes it
> hard to find an error later. This should just be
>
> my ( %records, @separate);
>
> > open (FILE, "<import0.dat") || die "Couldn't open file; $!\n";
> > open (OUT, ">output.dat") || die "Couldn't create file; $!\n";
> > open (NEWOUT, ">newout.dat") || die "Couldn't create; $!\n";
> >
> > while ( <FILE> ) {
> > my @fields = split ( /,/ );
> > if ( $fields[7] =~ m{^\$\$S\/N:(\w+)} ) {
> > my $ser = '$$' . $1 . '$$';
> > ( $fields[1], $ser ) = ( $ser, $fields[1] );
> > push (@seperate, join (',', @fields));
> > $records{$ser} = $fields[1];
> >
> > }
> > print NEWOUT "User =$fields[1]\n";
> > print NEWOUT "Number =$ser\n";
>
> Well, you are trying to print $ser, which is only defined inside the
> "if"-block. What you are accessing is the variable "$ser" you declared
> earlier, which muddles the issue. Perl wouldn't have compiled the code
> without the spurious declaration, and would have been right.
>
> What you really must do here is decide whether something should go to
> NEWOUT at all if $fields[7] doesn't match the pattern. If it shouldn't,
> move the two print-statements into the if-block, and you're done.
>
> If you need to print something to NEWOUT in every case, pull the
> declaration of $ser out of the if-block (but not out of the loop). Then
> add an else-clause that sets $ser to something reasonable when $fields[7]
> doesn't match. The print-statements are positioned right for this case,
> but should be indented to match the other material in the loop.
>
> >
> > }
>
> [...]
>
> Anno
Anno - You da man. I've gotten my program to function as I want it to
now, thanks to your suggestions. This is what I have now. I have found
that running this under 'use strict;' and with -w causes errors if I
do not define the variables at the start of the program. Maybe they
dont need to be defined at the beginning? Is there something im
missing here?
One last thing - where I have the print NEWOUT statements, Is it
possible to define a syntax like:
print <<MYOUT;
User= $ser
Number = $fields[1]
MYOUT
where I currently have my 'print NEWOUT' statements? I am currently
getting an error "Cant find stirng terminator "MYOUT" anywhere before
EOF at test.pl line 20."
Again, thanks for your help. It has been very useful.
#!/usr/bin/perl -w
use strict;
my %records;
my (@ser, @seperate, @fields);
my $ser;
open (FILE, "<import0.dat") || die "Couldn't open file; $!\n";
open (OUT, ">output.dat") || die "Couldn't create file; $!\n";
open (NEWOUT, ">newout.dat") || die "Couldn't create; $!\n";
while ( <FILE> ) {
my @fields = split ( /,/ );
if ( $fields[7] =~ m{^\$\$S\/N:(\w+)} ) {
my $ser = '$$' . $1 . '$$';
( $fields[1], $ser ) = ( $ser, $fields[1] );
push (@seperate, join (',', @fields));
$records{$ser} = $fields[1];
print NEWOUT "User = $ser\n";
print NEWOUT "Number = $fields[1]\n";
}
}
#while ( ($key,$value ) = each %records ) {
# print OUT "$key --> $value\n"
#}
print OUT "@seperate\n";
close(FILE);
close (OUT);
close (NEWOUT);
------------------------------
Date: Sat, 15 Mar 2003 22:34:26 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: FILEHANDLE and search and replace question
Message-Id: <3E73F0C2.254FDF34@earthlink.net>
Marek Stepanek wrote:
>
> Hello,
>
> I am new to perl and have a question about a search and replace, which
> is not working in my script.
>
> How do I open the file correctly (with < or > or +< or +>) to make a
> search and replace? If I understand well, first the script has to read
> in the lines and than replace them. So I opt for "+<" - but I tried
> every combination ...
If you want to do a truly in-place edit of a file (that is, using only
*one* filehandle, and no backup file), then "+<" is the right open mode.
However, there's the caveat that you must be careful not to overwrite
data which you haven't read yet, which generally requires doing your own
buffering, and seeking back and forth within the file.
my $dir = $bearbeitetverzeichnis;
my $file = "resultsglobal.htm";
open( my ($fh), "<+", "$dir/$file" )
or die "Couldn't open $file for read/write: $!";
my $s = (stat $fh)[11] || 8192;
my $write_to = 0;
my $buffer = "";
my $pristine = 1;
while( my $n = sysread( $fh, $buffer, $s, length $buffer ) {
my $from = rindex( $buffer, "\n", length($buffer)-$n );
my $to = rindex( $buffer, "\n" );
next if $to <= $from;
next if !(substr( $buffer, $from+1, $to ) =~
s/(ohne|mit)/<SPAN CLASS="wichtich">$1<SPAN>/g)
and $pristine;
my $read_from = sysseek $fh, 0, 1;
if( $pristine ) {
$write_to = $read_from - $n;
$pristine = 0;
}
sysseek $fh, $write_to, 0;
my $n2 = syswrite( $fh, $buffer, $read_from - $write_to );
$write_to += $n2;
substr( $buffer, 0, $n2 ) = "";
sysseek( $fh, $read_from, 0 ) if $write_to != $read_from;
}
print $fh $buffer;
close $fh;
[untested; error checking omitted for brevity]
The purpose of the $pristine variable is so that the data before the
first change doesn't need to get written back to the file... So if the
data you're looking for doesn't exist in the file, nothing gets changed.
Note that the length of $buffer gets longer, for every substitution
performed. This is inevitable, due to the fact that your substitution
replaces a small amount of data with a longer amount of data.
A much more "normal" way of doing in-place edit is to write a script as
follows, passing it the filename to be changed on the commandline:
#!/path/to/perl -wpi.bak
s/(ohne|mit)/<SPAN CLASS="wichtich">$1<SPAN>/g;
__END__
[untested]
This uses magic that's already built into perl to perform the in-place
editing of the file. It doesn't *really* change the file in place,
though -- it reads from one file, makes the change, writes to another
(new) file, and when it's all done reading, renames the new file back to
the old one.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Sat, 15 Mar 2003 21:59:10 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: frames without files ?
Message-Id: <3MRca.29128$a24.368419@weber.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Eric Osman wrote:
>
> Hi,
>
> I've got a Perl CGI that takes as its input some text the user pastes
> into an HTML TEXTAREA.
>
> When user clicks on the SUBMIT button, the Perl CGI then writes the text
> back with enhancing HTML tags (to add hotspots, for example) .
>
> But here's the clincher:
>
> Now I want to enhance the Perl so that it adds a table of contents
> frame. Because of SECURITY I'd rather not write any files.
>
> When it was just the one page being written back, it was simple, as
> I just put in "print" lines in Perl to write HTML code back to the
> browser.
>
> But if I want my Perl to generate a frameset page pointing at two other
> pages (the table of contents and the body), is there a way I can do this
> without writing auxiliary disk files ?
In adition to my previous reply, I just recalled something slightly
similar I had to implement some time ago.
Have the perl CGI create a new listening socket on a random port then
fork() to create a child of itself. The child would then listen on to
the port for incoming HTTP connections and serve up the content once
connected to, followed by dying.
In the meantime, the parent can output the normal HTML and for the table
of contents frame, have it go to your server:port that the child is
listening on.
There are numerous security considerations to keep in mind when doing
something like this, including making sure you don't kill your box with
hanging child servers because the end-client never connected to retrieve
the data, or the size of the data each client holds in memory etc...
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+c+iEeS99pGMif6wRAjxvAJ96kviMRs0iPbUGVzfCF+Q29DYOUACglSkG
ahGfkPNMOYVM7gSPDAmqo0M=
=zu4C
-----END PGP SIGNATURE-----
------------------------------
Date: Sun, 16 Mar 2003 10:16:55 +1100
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: how to create NULL character in perl
Message-Id: <3e73b53e$0$26612@echo-01.iinet.net.au>
"David Efflandt" <efflandt@xnet.com> wrote in message
news:slrnb77719.94a.efflandt@typhoon.xnet.com...
<snip>
> I thought a null string ($null = '') was the same, but apparently NOT the
> same as a null character.
<snip>
I expected the same as you, and also did the following:
$x = chr(0);
$y = '';
if($x eq $y) {print "SAME\n"}
else {print "DIFFERENT\n"}
# prints DIFFERENT.
print ord($x), "\n"; # prints 0
print ord($y), "\n"; # prints 0
Cheers,
Rob
------------------------------
Date: Sun, 16 Mar 2003 04:17:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: how to create NULL character in perl
Message-Id: <x7znnw3py5.fsf@mail.sysarch.com>
>>>>> "S" == Sisyphus <kalinabears@hdc.com.au> writes:
S> "David Efflandt" <efflandt@xnet.com> wrote in message
S> news:slrnb77719.94a.efflandt@typhoon.xnet.com...
S> <snip>
>> I thought a null string ($null = '') was the same, but apparently NOT the
>> same as a null character.
bad thinking.
a null string is empty with a length of 0.
a null char is a single byte (\0) with a length of 1.
S> <snip>
S> I expected the same as you, and also did the following:
S> $x = chr(0);
S> $y = '';
S> if($x eq $y) {print "SAME\n"}
S> else {print "DIFFERENT\n"}
S> # prints DIFFERENT.
print their lengths.
S> print ord($x), "\n"; # prints 0
S> print ord($y), "\n"; # prints 0
ord returns the numeric value of the first char in $y. there is none so
it has to return something which will be 0. you don't check for a null
string with ord, you check it with length.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: 15 Mar 2003 23:15:58 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: How to find a word which is palindromica using REGEXP
Message-Id: <slrnb77d1e.6og.abigail@alexandra.abigail.nl>
qin jiang wei (qin@freebsd.lzu.edu.cn) wrote on MMMCDLXXXIII September
MCMXCIII in <URL:news:863clo1xd0.fsf@freebsd.lzu.edu.cn>:
..
.. How can I find the palindromica words in /usr/share/dict/words
.. For example , the word 'level'.
Regexp::Common has a regexp.
$ perl -MRegexp::Common -wnle 'print if /^$RE{lingua}{palindrome}$/' \
> /usr/share/dict/words
bib
bob
boob
civic
dad
deed
did
dud
eke
ere
ewe
eye
gag
gig
huh
level
madam
non
noon
nun
peep
pep
pip
pop
pup
radar
redder
refer
reviver
rotator
rotor
sees
sexes
solos
tit
Abigail
--
#!/opt/perl/bin/perl -- # Remove trailing newline!
BEGIN{$SIG{__WARN__}=sub{$_=pop;y-_- -;print/".*(.)"/;
truncate$0,-1+-s$0;exec$0;}}//rekcaH_lreP_rehtona_tsuJ
------------------------------
Date: Sat, 15 Mar 2003 23:29:27 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: How to find a word which is palindromica using REGEXP
Message-Id: <shd77voasb1v6khn9otptd2dmtfll3a9nq@4ax.com>
On 15 Mar 2003 23:08:11 +0800, in comp.lang.perl.misc, qin jiang wei <qin@freebsd.lzu.edu.cn> wrote:
>How can I find the palindromica words in /usr/share/dict/words
>For example , the word 'level'
Not regex but here it is anyway ...
perl -e 'while (<>){chomp; print "$_\n" if join "",reverse(split //) eq $_}' /usr/share/dict/words
--
Sharon
------------------------------
Date: 15 Mar 2003 23:49:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to find a word which is palindromica using REGEXP
Message-Id: <b50e5t$dbj$2@mamenchi.zrz.TU-Berlin.DE>
Sharon Grant <peakpeek@purethought.com> wrote in comp.lang.perl.misc:
> On 15 Mar 2003 23:08:11 +0800, in comp.lang.perl.misc, qin jiang wei
> <qin@freebsd.lzu.edu.cn> wrote:
>
> >How can I find the palindromica words in /usr/share/dict/words
> >For example , the word 'level'
>
> Not regex but here it is anyway ...
> perl -e 'while (<>){chomp; print "$_\n" if join "",reverse(split //) eq
^^^^^^^^^^^^^^^^^^^^^^^^^
This does too much work. reverse() in scalar context reverses a string
directly: "reverse() eq $_" (as in Jue's solution upthread).
> $_}' /usr/share/dict/words
Anno
------------------------------
Date: 16 Mar 2003 00:03:03 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: it's true but can I say so ?
Message-Id: <slrnb77fpn.6og.abigail@alexandra.abigail.nl>
Martien Verbruggen (mgjv@tradingpost.com.au) wrote on MMMCDLXXXIII
September MCMXCIII in <URL:news:slrnb77b9a.j8t.mgjv@martien.heliotrope.home>:
&&
&& But you can't use NULL (or something evaluating to NULL) in a spot where
&& a boolean expression is expected.
From the Sybase SQL Server 11.0.x Reference Manual, Vol 1 5-32:
Relational and Logical Expressions
A logical expression or relational expression returns TRUE, FALSE,
or UNKNOWN. The general patterns are:
...
logical_expression {and | or} logical_expression
Abigail
--
BEGIN {$^H {join "" => ("a" .. "z") [8, 13, 19, 4, 6, 4, 17]} = sub
{["", "Just ", "another ", "Perl ", "Hacker"] -> [shift]};
$^H = hex join "" => reverse map {int ($_ / 2)} 0 .. 4}
print 1, 2, 3, 4, "\n";
------------------------------
Date: Sat, 15 Mar 2003 21:08:45 -0500
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: it's true but can I say so ?
Message-Id: <kevin-A9A76E.21084515032003@vienna7.his.com>
In article <slrnb77b9a.j8t.mgjv@martien.heliotrope.home>,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> On Sat, 15 Mar 2003 03:21:19 -0500,
> Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> > Martien Verbruggen wrote:
> >> Benjamin Goldberg wrote:
> >> > Martien Verbruggen wrote:
> >> >> Abigail wrote:
> >> >> > Martien Verbruggen wrote:
> >> >> > -:
> >> >> > -: But, again, I've seen many people try it. And in languages
> >> >> > -: where boolean truth and falseness isn't a bipolar situation,
> >> >> > -: that's really broken.
> >> >> >
> >> >> > Many people, including myself, wouldn't call SQL really broken.
> >> >>
> >> >> But in SQL, truth and falseness _is_ a bipolar situation.
> >> >
> >> > What about NULL?
> >>
> >> NULL is neither true nor false. It is null, and has its own sematics.
> >
> > Precisely. In other words, in SQL truth and falseness _is not_ a
> > bipolar situation -- it's tripolar: true, false, and NULL.
>
> But you can't use NULL (or something evaluating to NULL) in a spot where
> a boolean expression is expected.
Sure you can. Comparing anything to a NULL value yields a NULL result,
neither true nor false.
--
Kevin Michael Vail | Dogbert: That's circular reasoning.
kevin@vaildc.net | Dilbert: I prefer to think of it as no loose ends.
http://www.vaildc.net/kevin/
------------------------------
Date: Sat, 15 Mar 2003 21:36:06 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: it's true but can I say so ?
Message-Id: <3E73E315.E55D94A4@earthlink.net>
Consider the following code:
BEGIN {
package Boolean;
sub new {
my $class = shift;
my $self = shift() ? 1 : !1;
bless \$self, $class;
}
sub neg { ref($_[0])->new(!${$_[0]}) }
sub bool { ${$_[0]} }
use overload
(map { $_ => \&neg } qw(! ~ neg)),
(map { $_ => \&bool } qw(bool +0 "")),
(map { $_ => eval sprintf q[sub {
my $other = $_[1] ? 1 : !1;
ref($_[0])->new( ${$_[0]} %s $other );
}], $_ } qw(| & ^ == eq != ne)),
# anything else?
;
}
use constant true => Boolean->new(1);
use constant false => Boolean->new(0);
Does anyone see any flaws in this design? The goal of course is to be
able to write:
if( $foo == true ) { .... }
And have it enter the { .... } if $foo is any value perl considers true.
I'm not using a 'nomethod' method, since I don't want other arithmetic
operators to be overloaded -- let a '+0' conversion happen, and then
ordinary arithmetic.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Sun, 16 Mar 2003 02:38:10 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: it's true but can I say so ?
Message-Id: <msRca.13566$Ad6.3350@nwrddc01.gnilink.net>
Benjamin Goldberg wrote:
[...]
> Does anyone see any flaws in this design? The goal of course is to be
> able to write:
> if( $foo == true ) { .... }
Call me stupid but I don't see the advantage or purpose.
Why not just a simple
if ($foo) {....}
jue
------------------------------
Date: Sat, 15 Mar 2003 22:49:07 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: it's true but can I say so ?
Message-Id: <3E73F433.B643F69B@earthlink.net>
"Jürgen Exner" wrote:
>
> Benjamin Goldberg wrote:
> [...]
> > Does anyone see any flaws in this design? The goal of course is to
> > be able to write:
> > if( $foo == true ) { .... }
>
> Call me stupid but I don't see the advantage or purpose.
> Why not just a simple
>
> if ($foo) {....}
Because some wierdos *like* to be able to compare things with 'true' or
'false' :P
Mainly, it was a response to posts I've seen saying that you should
"never" write code like '$true = ...', due to the problems that would
arise when you try and compare things (using "eq" or "==") to $true...
I was just showing that it *can* be done, without too much strangeness.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: 15 Mar 2003 18:43:27 -0800
From: srigowrisn@hotmail.com (shree)
Subject: Perl - How to parse a data file to display occurances of each type (hash)?
Message-Id: <49b5740e.0303151843.38d00c55@posting.google.com>
Hello,
I wrote an html survey form whose action invokes a perl cgi script to
append form submission as a new record into a flat file. This is
working fine. Now, I'm asked to process this results file. Here I'm
running into difficulties and would appreciate if anyone can help
share a code snippett.
The survey consists of 2 types of questions: radio button and text
area (comment) questions. Radio button questions (Q1-Q4) all have 3
identical options to choose from. They are: Agree, Neutral and
Disagree
Comment questions (Q5-Q6) are of course free form questions so the
submitter can type in a text string.
I need to tally responses for each radio button question and
concatanate results of text area questions.
The response file (without the headerline) looks like this
Responses|Q1|Q2|Q3|Q4|Q5|Q6
1|Agree|Disagree|Neutral|Neutral|Cmts by submitter 1|Cmts by Submitter
1
2|Disagree|Disagree|Neutral|Disagree|Cmts by submitter 2|Cmts by
submitter 2
3|Neutral|Agree|Disagree|Agree|Cmts by submitter 3|Cmts by submitter 3
4|Neutral|Agree|Disagree|Disagree|Cmts by submitter 4|Cmts by
submitter 4
5|Agree|Agree|Disagree|Neutral|Cmts by submitter 5|Cmts by submitter 5
I would like to process the above file..to get something like the
illustration below. Can anyone show me how? Thank you in advance
Radio Button results (counts no. of occurances)
Questions|Agree|Netural|Disagree
Q1|2|2|1
Q2|3|2|0
Q3|0|2|3
Q4|1|2|2
Text Area results
Question 5
Cmts by Submitter 1
Cmts by Submitter 2
..
Cmts by Submitter 5
Question 6
Cmts by Submitter 1
Cmts by Submitter 2
..
Cmts by Submitter 5
Thank you,
Shree
srigowrisn@hotmail.com
------------------------------
Date: Sun, 16 Mar 2003 05:32:40 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl - How to parse a data file to display occurances of each type (hash)?
Message-Id: <b50v5v$23sg42$1@ID-184292.news.dfncis.de>
shree wrote:
> I wrote an html survey form whose action invokes a perl cgi script to
> append form submission as a new record into a flat file. This is
> working fine. Now, I'm asked to process this results file. Here I'm
> running into difficulties and would appreciate if anyone can help
> share a code snippett.
Here is a try:
my (%question);
open FH, 'results' or die "Couldn't open 'results'\n$!";
while (<FH>) {
chomp (my @record = split /\|/);
for (1..4) { $question{$_}{$record[$_]}++ }
for (5..6) { push @{$question{$_}}, $record[$_] if $record[$_] }
}
close FH;
print "Radio Button results\n",
'Questions|Agree|Neutral|Disagree', "\n";
for (1..4) {
print "Q$_", '|', $question{$_}{'Agree'} || 0, '|',
$question{$_}{'Neutral'} || 0, '|',
$question{$_}{'Disagree'} || 0, "\n";
}
print "\n";
print "Text Area results\n";
for (5..6) {
print "Question $_\n";
for (@{$question{$_}}) { print "$_\n" }
print "\n";
}
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 15 Mar 2003 22:46:49 -0600
From: Joe Creaney <mail@annuna.com>
To: Joe Creaney <mail@annuna.com>
Subject: Re: Printing a 2d array
Message-Id: <3E7401B9.6050205@annuna.com>
I got it is was reading one of my books and came across what I needed.
Joe Creaney wrote:
> I am having trouble writing a function that will print out a 2d array.
> I figure the logic goes something like this but I can't get the syntax
> right.
>
> @array
> for each loop (@array) {
> for each loop1 (@array [loop]{
> print $array [loop][loop1]
> }
> print new line
> }
>
> Is this possible in perl?
>
>
------------------------------
Date: Sat, 15 Mar 2003 21:06:30 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Question: What's the proper way to retrieve last mod dates for all files in a directory?
Message-Id: <slrnb77qhm.7vb.tadmc@magna.augustmail.com>
LinkSeer <linkseer@yahoo.com> wrote:
> If I use something like:
>
> @dirlist = readdir(html);
> foreach $f(@dirlist){
> if(-f $f){
> Any assistance will be greatly appreciated!
Simply read the documentation for the function that you are using:
perldoc -f readdir
If you're planning to filetest the return values
out of a "readdir", you'd better...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 15 Mar 2003 19:33:42 -0800
From: "smackdab" <smackdab1@hotmail.com>
Subject: socket question
Message-Id: <OdSca.3902$8s4.2379@fed1read01>
Hi,
I am creating a non-blocking io::socket to talk to a remote server, which I
got working ;-)
Now, I need to create a listen socket in my program and accept a connection
myself.
Can I reuse the io::select I already created for the listen socket or should
I create a new one?
Hope this question makes sense ;-)
thanks!
------------------------------
Date: Sun, 16 Mar 2003 02:13:16 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: Sorting using DB_File/btree
Message-Id: <fqk77vk3mbhccniedkb83ptc4pcj9ib5d2@4ax.com>
On Sat, 15 Mar 2003 21:16:04 GMT, in comp.lang.perl.misc, "Anand Kandasamy" <anandks@optonline.net> wrote:
>I have four huge arrays (with 22986152 numbers), that needs to be sorted
>to extract the min and the max. Posting this question earlier, it is
>understood that
>I should use the Berkley DB to strore my array and sort them
Your earlier question did not mention that you only wanted
the minimum and maximum, only that you were struggling to sort
your data
jue and Anno have already posted simple techniques for finding
minimum and maximum values without sorting
>My array is not an associative array, so no keys are involved. It contains
>floating point
>numbers
How to load floating point numbers in ascending sequence and
descending sequence into a Berkeley/DB btree file using DB_File ...
#!/usr/bin/perl -T
my $floatsort = '/path/to/files/floatsort';
my $floatsort_desc = '/path/to/files/floatsort_desc';
use strict;
use warnings;
use DB_File;
my ($x, %h, $k, $v);
# tested with these values
my @floats = (1.2, 2.5, 10.8, 198.2, 54.999, 5.4, 90258769.79756, .23E-10, 4.1E10, 5.92E6);
# define numeric sequence for Berkeley/DB btree
# ascending sequence - to find minimum value
sub numeric_sequence { my ($key1, $key2) = @_; $key1 <=> $key2; }
# descending sequence - to find maximum value
sub numeric_sequence_desc { my ($key1, $key2) = @_; $key2 <=> $key1; }
# tell Berkeley/DB to use the ascending numeric sequence defined above
$DB_BTREE->{'compare'} = \&numeric_sequence;
$x = tie %h, 'DB_File', $floatsort, O_RDWR|O_CREAT, 0600, $DB_BTREE
or die "Cannot open database $floatsort: $!\n";
# load the data into the Berkeley/DB database via the tied hash
for (@floats) { $h{$_} = $_; }
# minimum value is the first record in the database
($k, $v) = (0, '');
$x->seq($k, $v, R_CURSOR); print "Minimum is $k\n";
undef $x; untie %h;
# tell Berkeley/DB to use the descending numeric sequence defined above
$DB_BTREE->{'compare'} = \&numeric_sequence_desc;
$x = tie %h, 'DB_File', $floatsort_desc, O_RDWR|O_CREAT, 0600, $DB_BTREE
or die "Cannot open database $floatsort_desc: $!\n";
for (@floats) { $h{$_} = $_; }
# maximum value is the first record in the database
# this assumes all numbers are less than 1E100 - adjust if necessary
($k, $v) = (1E100, '');
$x->seq($k, $v, R_CURSOR); print "Maximum is $k\n";
undef $x; untie %h;
--
Sharon
------------------------------
Date: Sat, 15 Mar 2003 17:03:20 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Stupid Perl Questions
Message-Id: <b50bo2$vr0$1@slb6.atl.mindspring.net>
"Caesar_Ancheta" <caesar_ancheta@yahoo.com> wrote in message
news:5d34f091.0303151422.132a933c@posting.google.com...
<snip>
> Bill,
> You are quite right that Perl by itself on a Server is innocuous,
> because control on the Server is understood.
Caesar,
You may wish to look at http://tinyperl.sourceforge.net/ to keep the
discussion in the proper context.
Actually, TinyPerl itself is not installed on the floppy; but rather, what
is installed is the executable program created by compiling the Perl script
with TinyPerl, the per58.dll file, and lib.zip, all of which are in the
cgi-bin directory used by the TinyWeb server. You can look inside of
lib.zip, as well as review the TinyPerl documentation at SourceForge (link
above) to see if you still have any concerns about running "standalone" from
a floppy disk.
> I wonder what technology
> can be used to offset the threat posed by total control passed from a
> Server to a Client. Java solved it by limiting the facilities passed
> to the Client, by delegating execution to the JVM. At the very least,
> disabling back-tick and exec() at the Client, if those facilities
> exist in the TinyPerl.
I've read that some people have actually deployed TinyWeb as a "real" web
server. Personally, I wouldn't be inclined to run it from *my* Win32
workstation, while said workstation is connected to the Web, as TinyWeb
binds itself to the IP addresses it finds when it is started.
> Perhaps also a way to detect tainting, ought to
> be layered on top of the TinyPerl. The issue is the size of the
> executable. Current Perl's are large enough to detect and deal with.
All of your issues should, IMO, be raised with the developer of TinyPerl.
My specific example was aimed simply at provideing a live TCP/IP connection
on a stanalone Win32 system, so that Acrobat Reader, operating as a plugin
in the browser, would be able to "submit" form data for processing to a form
savable by the user for future use.
> But a floppy-sized "Perl" with an attendant Web "Server" which can be
> downloaded to a Client, is like a plastic gun; Congress disallowed
> plastic guns.
>
Guns don't kill people. People kill people. Even so, I wouldn't discount the
possibility that some fool would deliberately/accidentally do his computer
harm by misuse of TinyPerl, in combination with TinyWeb. The same could be
said for any other easily installed Perl + Web Server suite, e.g.,
IndigoPerl.
> It is best that this information be dealt with wisely. I am not sure
> that posting it elsewhere is responsible.
I agree. Let's leave the security responsibilities where they belong, i.e.,
with the user.
If the uncertainy is an important issue, potential users of the scheme I've
crafted can always duck the security issues completely by buying Acrobat
Approval to allow them to save form data from an Acrobat PDF form.
Cheers.
Bill Segraves
------------------------------
Date: Sat, 15 Mar 2003 18:06:22 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: War against spam
Message-Id: <slrnb77fvu.79k.tadmc@magna.augustmail.com>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> Vincent Granville <vincentg@datashaping.com> wrote in comp.lang.perl.misc:
[snip blatant come-on]
> What idea? Plugging your own web site by spamming Usenet with disingenuous
> questions about it? The idea is old,
At least 3 months old, as that is when he did it here last.
Date: Tue, 10 Dec 2002 06:17:58 GMT
Message-ID: <3DF58400.3637954F@datashaping.com>
> and its practice is insulting.
Vincent weighed the negative of insulting all of us against the
positive of increasing traffic at his web site.
His decision seems clear to me. :-(
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4715
***************************************