[19371] in Perl-Users-Digest
Perl-Users Digest, Issue: 1566 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 19 18:05:34 2001
Date: Sun, 19 Aug 2001 15:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <998258709-v10-i1566@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 19 Aug 2001 Volume: 10 Number: 1566
Today's topics:
Does anyone know a good mailing list script? (Jerry)
EXEs from within Perl <me@REMOVETHIStoao.net>
Re: EXEs from within Perl <Tassilo.Parseval@post.rwth-aachen.de>
FAQ: I put a regular expression into $/ but it didn't w <faq@denver.pm.org>
Re: Hash of Complex Records <mark.riehl@agilecommunications.com>
Re: Hash of Complex Records (Eric Bohlman)
How to remove duplicate records in a huge file?? <smitw1@hotmail.com>
Re: How to remove duplicate records in a huge file?? <tsee@gmx.net>
Re: How to remove duplicate records in a huge file?? (Eric Bohlman)
new modules - looking for (sort-of-)pre-release input <sean@quinlan.org>
new modules - looking for (sort-of-)pre-release input <sean@quinlan.org>
newbie: two things.. <jippie@yahoo.com>
Re: newbie: two things.. <ilya@martynov.org>
Re: Parameter asserts?? <iltzu@sci.invalid>
qw(). <seedkum-aladeem@home.com>
Re: qw(). <ilya@martynov.org>
Split <asgar@tkusa.com>
Re: Split <me@REMOVETHIStoao.net>
Re: Split <asgar@tkusa.com>
Re: Split <tony_curtis32@yahoo.com>
Re: Split <godzilla@stomp.stomp.tokyo>
Re: String Parsing > Remove everything after the first (DB)
Subs are automatically executing in my module? <mark.riehl@agilecommunications.com>
Re: Subs are automatically executing in my module? <Tassilo.Parseval@post.rwth-aachen.de>
Re: Subs are automatically executing in my module? <mark.riehl@agilecommunications.com>
Re: Uh Oh: URL Encode <iltzu@sci.invalid>
Re: Uh Oh: URL Encode <iltzu@sci.invalid>
Re: Uh Oh: URL Encode <ilya@martynov.org>
Unix command : write - how to detect a message <newspub@free.fr>
Re: URL Encode <iltzu@sci.invalid>
Re: Webserver environment settings <gnarinn@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Aug 2001 12:08:47 -0700
From: jnance@earthlink.net (Jerry)
Subject: Does anyone know a good mailing list script?
Message-Id: <18f2db06.0108191108.4349f18b@posting.google.com>
Hello,
I'm trying this question again in the hopes someone can suggest
something.
Does anyone know a mailist list opt-in script that can automatically
send daily messages?
I need a script where I can add 7 days of meditations and have the
script send out each daily meditation automatically for the week.
I have seen lots of mailing list scripts, but I haven't found one that
will send out automatic messages for the days of the week.
I don't know enough to really create it myself. I'm looking for a
perl/cgi script that already does this or is very close.
Thanks for any suggestions.
Jerry
------------------------------
Date: Sun, 19 Aug 2001 19:24:22 GMT
From: "Graham W. Boyes - TOAO.net" <me@REMOVETHIStoao.net>
Subject: EXEs from within Perl
Message-Id: <GnUf7.78840$B37.1843976@news1.rdc1.bc.home.com>
Hi,
Using the latest versions of ActivePerl and Perl2EXE on DOS 7. (E.g., a
Windows 98SE boot disk.)
I was wondering if it's possible to to run a DOS executable, for example,
Mem.exe (displays used and unused memory) and have the output put into a
variable inside my Perl program. Right now I'm doing something like "mem >
temp.txt" at the DOS prompt, and then running my Perl program which opens
the file temp.txt and works on it. This is rather cumbersome as I do it six
times (with different programs) in my Perl program.
Thanks for any help in advance,
Graham W. Boyes
--
me AT toao DOT net - http://www.toao.net/
http://www.hawhawjokes.com/ - http://hbfanfiction.hypermart.net/
------------------------------
Date: Sun, 19 Aug 2001 21:51:47 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: EXEs from within Perl
Message-Id: <3B8018D3.1060706@post.rwth-aachen.de>
Graham W. Boyes - TOAO.net wrote:
> Hi,
> Using the latest versions of ActivePerl and Perl2EXE on DOS 7. (E.g., a
> Windows 98SE boot disk.)
>
> I was wondering if it's possible to to run a DOS executable, for example,
> Mem.exe (displays used and unused memory) and have the output put into a
> variable inside my Perl program. Right now I'm doing something like "mem >
> temp.txt" at the DOS prompt, and then running my Perl program which opens
> the file temp.txt and works on it. This is rather cumbersome as I do it six
> times (with different programs) in my Perl program.
There are different more convenient ways of doing that.
1) Using backticks:
my $var = `mem`;
2) Using open:
open MEM, "mem |" or die "Error: Could not fork: $!";
my @var = <MEM>;
The second approach is more sophisticated since it forks off the program.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sun, 19 Aug 2001 18:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: I put a regular expression into $/ but it didn't work. What's wrong?
Message-Id: <xoTf7.259$V3.170762752@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
I put a regular expression into $/ but it didn't work. What's wrong?
$/ must be a string, not a regular expression. Awk has to be better for
something. :-)
Actually, you could do this if you don't mind reading the whole file
into memory:
undef $/;
@records = split /your_pattern/, <FH>;
The Net::Telnet module (available from CPAN) has the capability to wait
for a pattern in the input stream, or timeout if it doesn't appear
within a certain time.
## Create a file with three lines.
open FH, ">file";
print FH "The first line\nThe second line\nThe third line\n";
close FH;
## Get a read/write filehandle to it.
$fh = new FileHandle "+<file";
## Attach it to a "stream" object.
use Net::Telnet;
$file = new Net::Telnet (-fhopen => $fh);
## Search for the second line and print out the third.
$file->waitfor('/second line\n/');
print $file->getline;
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
06.04
--
This space intentionally left blank
------------------------------
Date: Sun, 19 Aug 2001 18:48:48 GMT
From: "Mark Riehl" <mark.riehl@agilecommunications.com>
Subject: Re: Hash of Complex Records
Message-Id: <kSTf7.1408$uC2.691309@typhoon1.gnilink.net>
The output didn't work for me, it only printed the vehicle IDs from the
outer loop, never entered the inner loop. I'm wondering if there's a
problem on the input side. Here's what is filling the hash (this is inside
another while, which performs the same task for multiple vehicle ids).
$rec = {};
$rec->{urn} = $this_urn;
@movement_records = ();
while (<INPUT>) {
... Get the time, lat, long from a file
%fields = (time=>$time, latitude=>$latitude, longitude=>$longitude);
push @movement_records, {%fields};
}
$LocationData{ $rec->{vid} } = @movement_records;
Thanks,
Mark
"Samneric" <samneric@tigerriverOMIT-THIS.com> wrote in message
news:MPG.15e9a260ea2b396098968a@news.usit.net...
> Mark Riehl wrote:
>
> > my %LocationData = (
> > 1001 => [
> > { time => "8456823", lat => "35.311", long => "-116.4101", },
> > { time => "8456824", lat => "35.312", long => "-116.4201", },
> > { time => "8456825", lat => "35.313", long => "-116.4301", },
> > ],
> > };
>
> ");" -> hoof error :)
>
> > Two questions - how do I display a count of the time, lat, long records
for
> > each key? Also, how do I loop through all the keys and display the data
for
> > each key? I thought I'd be able to do the following to see one record:
>
> foreach my $vid (keys %LocationData) { # each vehicle id
> print "Vehicle ID: $vid\n";
> foreach my $rec ( @{$LocationData{$vid}} ) { # each $rec is hashref
> print "Time: $rec->{time}\n";
> print "Lat: $rec->{lat}\n";
> print "Long: $rec->{long}\n\n";
> }
> print "\n";
> }
------------------------------
Date: 19 Aug 2001 20:06:16 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Hash of Complex Records
Message-Id: <9lp67o$6og$1@bob.news.rcn.net>
Mark Riehl <mark.riehl@agilecommunications.com> wrote:
> The output didn't work for me, it only printed the vehicle IDs from the
> outer loop, never entered the inner loop. I'm wondering if there's a
> problem on the input side. Here's what is filling the hash (this is inside
> another while, which performs the same task for multiple vehicle ids).
> $rec = {};
> $rec->{urn} = $this_urn;
> @movement_records = ();
> while (<INPUT>) {
> ... Get the time, lat, long from a file
> %fields = (time=>$time, latitude=>$latitude, longitude=>$longitude);
> push @movement_records, {%fields};
> }
> $LocationData{ $rec->{vid} } = @movement_records;
There's your problem. An element of a hash can hold only a scalar, not
an array, so your assignment is taking place in scalar context and what's
actually being assigned to your hash element is the number of entries in
@movement_records. You need to assign a *reference* to @movement_records
to the hash element; since you seem to have declared it outside your loop,
the easiest way would be to change @movement_records to
[@movement_records] in the above assignment (if you had declared it inside
the loop, you could have written \@movement_records, avoiding making a
copy).
------------------------------
Date: Sun, 19 Aug 2001 19:49:28 GMT
From: Wim <smitw1@hotmail.com>
Subject: How to remove duplicate records in a huge file??
Message-Id: <vk60otcm719i1q8qutk4cvmhk9iuhqtuad@4ax.com>
How can I remove duplicate records in a huge file?
The file contains about 3.000.000 records (=800Mb)
Many thanks for your help!!!!!!!!!!!
Wim
------------------------------
Date: Sun, 19 Aug 2001 22:05:53 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: How to remove duplicate records in a huge file??
Message-Id: <9lp60b$t36$03$1@news.t-online.com>
"Wim" <smitw1@hotmail.com> schrieb im Newsbeitrag
news:vk60otcm719i1q8qutk4cvmhk9iuhqtuad@4ax.com...
> How can I remove duplicate records in a huge file?
> The file contains about 3.000.000 records (=800Mb)
I usually use the following code for arrays:
@array = sort @array;
{
my $prev = '';
@array = grep($_ ne $prev && ($prev = $_), @array);
}
But that won't be all that fast for such a large file.
You'd have to read the records into an array first anyway. Do you have 800Mb
memory to spare? The sort'd take hours (at the least, I guess). The quickest
step would be the actual removal of the duplicates.
I'm sure there's a better way to do this, but it won't be quick either.
Steffen Müller
------------------------------
Date: 19 Aug 2001 20:13:00 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: How to remove duplicate records in a huge file??
Message-Id: <9lp6kc$6og$2@bob.news.rcn.net>
Wim <smitw1@hotmail.com> wrote:
> How can I remove duplicate records in a huge file?
> The file contains about 3.000.000 records (=800Mb)
Whenever you see "duplicate," think "hash." The simplest way would be to
read each record, use the entire record as a key into a hash, and check if
there's already an entry for that key. That, however, will likely use up
way to much memory with the amount of data you have. Therefore, I'd
compute a "checksum" (e.g. an MD5 digest) for each record and use that as
the hash key instead.
If the file has already been sorted, then you merely need to go through it
record by record and compare each record to the previous one.
------------------------------
Date: Sun, 19 Aug 2001 18:51:01 GMT
From: Sean Quinlan <sean@quinlan.org>
Subject: new modules - looking for (sort-of-)pre-release input
Message-Id: <3B800C3B.9CE88218@quinlan.org>
Thanks in advance to anyone who takes the time to look this over!
I'm in the process of 'creating' a few modules that I will be or have
uploaded to CPAN and hope to have listed in the modules list. They are
currently developed under the CompBio namespace. Most of the code for
the main three modules already exists in modules in use at the
BioMolecular Engineering Research Center (bmerc-www.bu.edu), but in less
portable formats (and in some cases just primitive/kludged versions). I
would appreciate comments both on the namespace and on the modules
themselves.
The first two modules, CompBio.pm and CompBio/Simple.pm are available in
one tarball at
http://www.cpan.org/authors/id/S/SE/SEANQ/CompBio-0.44.tar.gz
All the initial methods for CompBio.pm are 'completed' except for the
blast handlers. CompBio.pm can be used both in an OO manner (w/in my
limited understanding thereof) or by importing specific functions (yes,
I used EXPORT_OK). This module contains all the basic 'core' functions
that we have found get used in one form or another in many of the
programs written at our center and in work we have collaborated on. See
the bottom of this post for a list and _brief_ descriptions of currently
available and planned methods.
Simple.pm does not export any functions at all at this time (and
probably will never). Simple.pm's job is only to provide a much more
flexible interface to the core functions provided in CompBio.pm. It also
does more error checking and will provided more debugging output when
requested. Interfaces to many of the core functions are already complete
and I hope to have all of them done w/in the next couple weeks.
The distribution includes documentation [in real need of editing though!
:) ] and tests. I'm currently using Test::More, but as most people
probably don't have this installed yet, I may switch that. In the
meantime the next version will incorporate a fix kindly provided by John
Tobey of Boston.pm to skip running tests if Test::More is not available
and output the minimal skip requirement '[to satisfy] the "test suite
protocol"'.
The next module in this set I'm planning on making available is
CompBio::DB, which is, as you may guess, a biological database
interface. It uses DBI to communicate with the database and provides,
hopefully, easier ways to access commonly needed data without having to
learn SQL or the DBI. Developed against our large set of databases
currently contained in a MySQL server. These databases are maintained by
the BMERC and are available by FTP (well, a couple are already and the
rest will be shortly - we're upgrading our server in the next week or so
and looking for a new person to maintain the databases). It should
however be fairly easy to add necessary linkage tables to existing
databases and change the target names in CompBio::DB to use current in
house databases instead.
I also welcome any suggestions for appropriate additions to these
modules, modules that would fit well in this group, and/or if interested
in collaborating on this project. Please feel free to e-mail me at
seanq@darwin.bu.edu.
TIA!
Current functions in CompBio.pm:
# note - table format is tab delimited, such as id\tsequence[\n|\tother
fields]
new - create new CompBio object
check_type - try to determine what format sequence data is in
tbl_to_fa - convert sequence data in table format to fasta
tbl_to_ig - convert sequence data in table format to intelligenics
fa_to_tbl - convert sequence data in fasta to table format
ig_to_tbl - convert sequence data in intelligenics format to table
dna_to_protein - convert dna sequence to protein sequence
complement - convert dna sequence to it's compliment
six_frame - translate dna sequence to protein across all six frames
aa_hash - hash lookup of aa using codons as keys - includes ambiguous
codes
_stop - internal method used by six_frame
wu_blast - interface to WUBlast old, ugly and not portable - next
project after catching up Simple.pm
_error - internal method for varying error handling behavior without
extra typing every time
Planned (in most cases some code already exists elsewhere):
ncbi_blast - interface to NCBI's version of the blast tools
parse_blast - simple blast output parser - may need to be multiple
versions for WU and NCBI blasts. Return tab delimited data in consistent
format, such as score, %identity, start/stop positions of match, etc.
calculate_scores - calculates %equivalent identities and #effective
identities from blast output
dnastar_to_tbl - convert sequence data in dna* format to table
tbl_to_dnastar - and back
gcg_to_tbl - convert sequence data in gcg format to table
tbl_to_gcg - and back
ncbi_to_tbl - convert sequence data in ncbi 'format' (as cut and pasted
from .gbk reports or ncbi's website) to table
tbl_to_ncbi - and back
------------------------------
Date: Sun, 19 Aug 2001 18:52:49 GMT
From: Sean Quinlan <sean@quinlan.org>
Subject: new modules - looking for (sort-of-)pre-release input
Message-Id: <3B800CAC.64D24B11@quinlan.org>
Thanks in advance to anyone who takes the time to look this over!
I'm in the process of 'creating' a few modules that I will be or have
uploaded to CPAN and hope to have listed in the modules list. They are
currently developed under the CompBio namespace. Most of the code for
the main three modules already exists in modules in use at the
BioMolecular Engineering Research Center (bmerc-www.bu.edu), but in less
portable formats (and in some cases just primitive/kludged versions). I
would appreciate comments both on the namespace and on the modules
themselves.
The first two modules, CompBio.pm and CompBio/Simple.pm are available in
one tarball at
http://www.cpan.org/authors/id/S/SE/SEANQ/CompBio-0.44.tar.gz
All the initial methods for CompBio.pm are 'completed' except for the
blast handlers. CompBio.pm can be used both in an OO manner (w/in my
limited understanding thereof) or by importing specific functions (yes,
I used EXPORT_OK). This module contains all the basic 'core' functions
that we have found get used in one form or another in many of the
programs written at our center and in work we have collaborated on. See
the bottom of this post for a list and _brief_ descriptions of currently
available and planned methods.
Simple.pm does not export any functions at all at this time (and
probably will never). Simple.pm's job is only to provide a much more
flexible interface to the core functions provided in CompBio.pm. It also
does more error checking and will provided more debugging output when
requested. Interfaces to many of the core functions are already complete
and I hope to have all of them done w/in the next couple weeks.
The distribution includes documentation [in real need of editing though!
:) ] and tests. I'm currently using Test::More, but as most people
probably don't have this installed yet, I may switch that. In the
meantime the next version will incorporate a fix kindly provided by John
Tobey of Boston.pm to skip running tests if Test::More is not available
and output the minimal skip requirement '[to satisfy] the "test suite
protocol"'.
The next module in this set I'm planning on making available is
CompBio::DB, which is, as you may guess, a biological database
interface. It uses DBI to communicate with the database and provides,
hopefully, easier ways to access commonly needed data without having to
learn SQL or the DBI. Developed against our large set of databases
currently contained in a MySQL server. These databases are maintained by
the BMERC and are available by FTP (well, a couple are already and the
rest will be shortly - we're upgrading our server in the next week or so
and looking for a new person to maintain the databases). It should
however be fairly easy to add necessary linkage tables to existing
databases and change the target names in CompBio::DB to use current in
house databases instead.
I also welcome any suggestions for appropriate additions to these
modules, modules that would fit well in this group, and/or if interested
in collaborating on this project. Please feel free to e-mail me at
seanq@darwin.bu.edu.
TIA!
Current functions in CompBio.pm:
# note - table format is tab delimited, such as id\tsequence[\n|\tother
fields]
new - create new CompBio object
check_type - try to determine what format sequence data is in
tbl_to_fa - convert sequence data in table format to fasta
tbl_to_ig - convert sequence data in table format to intelligenics
fa_to_tbl - convert sequence data in fasta to table format
ig_to_tbl - convert sequence data in intelligenics format to table
dna_to_protein - convert dna sequence to protein sequence
complement - convert dna sequence to it's compliment
six_frame - translate dna sequence to protein across all six frames
aa_hash - hash lookup of aa using codons as keys - includes ambiguous
codes
_stop - internal method used by six_frame
wu_blast - interface to WUBlast old, ugly and not portable - next
project after catching up Simple.pm
_error - internal method for varying error handling behavior without
extra typing every time
Planned (in most cases some code already exists elsewhere):
ncbi_blast - interface to NCBI's version of the blast tools
parse_blast - simple blast output parser - may need to be multiple
versions for WU and NCBI blasts. Return tab delimited data in consistent
format, such as score, %identity, start/stop positions of match, etc.
calculate_scores - calculates %equivalent identities and #effective
identities from blast output
dnastar_to_tbl - convert sequence data in dna* format to table
tbl_to_dnastar - and back
gcg_to_tbl - convert sequence data in gcg format to table
tbl_to_gcg - and back
ncbi_to_tbl - convert sequence data in ncbi 'format' (as cut and pasted
from .gbk reports or ncbi's website) to table
tbl_to_ncbi - and back
------------------------------
Date: Sun, 19 Aug 2001 18:14:13 GMT
From: "Jippie@yahoo.com" <jippie@yahoo.com>
Subject: newbie: two things..
Message-Id: <VlTf7.117393$ef.3002685@Flipper>
Hi,
I have a string that I split, and the third element is either a word or a
numeric value.
How can I test if it is a numeric or not??
@parts = split(/[ ]/,$_);
#check if a string
if( $words[2] == $parts[2] )
{
print "mib $words[0]: OK\n";
}
else
{
print "$words[0]: $words[2] != $parts[2]\n";
}
second, I get a string from withn a file, and this variable has
"varaible(numeric)" format.
What I want to do is spilt this string into var = varaible; value =
numeric;
Can you help with this too??
Jippie
------------------------------
Date: 19 Aug 2001 22:53:07 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: newbie: two things..
Message-Id: <87pu9r990s.fsf@abra.ru>
Jc> Hi,
Jc> I have a string that I split, and the third element is either a word or a
Jc> numeric value.
Jc> How can I test if it is a numeric or not??
See 'perldoc -q scalar.*number'
Jc> [..skip..]
Jc> second, I get a string from withn a file, and this variable has
Jc> "varaible(numeric)" format.
Jc> What I want to do is spilt this string into var = varaible; value =
Jc> numeric;
Jc> Can you help with this too??
# $line - is a string from file
my($var, $num) = $line =~ /(.*?) \( (.*?) \)/x;
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 19 Aug 2001 18:06:51 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Parameter asserts??
Message-Id: <998242829.15614@itz.pp.sci.fi>
In article <slrn9nom9s.ksf.abigail@alexandra.xs4all.nl>, Abigail wrote:
>Carlos C. Gonzalez (miscellaneousemail@yahoo.com) wrote on MMCMIV
>September MCMXCIII in <URL:news:MPG.15e11f1e5b1786e3989738@news.edmonton.telusplanet.net>:
>==
>== If that is what parameter asserts are, no problem (at least in terms of
>== my using them). I check just about every possible scenario I can think
>== of in my most important functions. I first write a basic function and
>== get it working. Then I rewrite the function in pseudocode. Working into
>== the pseudocode a check for every possible input that I can think of. Then
>== I implement the pseudocode and flesh out the function to check for bad
>== input. It's a labor intensive work but I have to do this because of the
>
>That isn't the right way of doing it. Checks shouldn't be put in as an
>after thought, nor should you write a check for all inputs you can think
>of - you are bound to forget one.
Agreed, at least for the afterthough part. To be fair, however, the
OP's decription is not detailed enough to tell if he's doing the actual
checking right or not.
The wrong way is to think of a single potential case and see that it
doesn't cause problems. No matter how many times you do this, you're
bound to miss some harmful input case some day.
The right way is to think in terms of sets. You assert that the input
belong to set A. You write a bit of code where you assume it belongs to
set B. Is A a subset of B? If not, what happens if the input doesn't
belong to B? What should happen?
The solution will generally involve one or more of the following:
a) Terminate abnormally if the input is not in the acceptable set.
b) Rewrite the code to broaden the set of acceptable input.
c) Define a mapping from the input set to the acceptable set.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Sun, 19 Aug 2001 20:36:35 GMT
From: Seedkum Aladeem <seedkum-aladeem@home.com>
Subject: qw().
Message-Id: <3B7FC08C.61863D0A@home.com>
Can someone please tell me why the two programs below do not give the
same result?
-------------------------------------------------
#!/usr/bin/perl -W
#@a = <STDIN>;
@a =
qw
(
a\n
bb\n
ccc\n
dddd\n
eeeee\n
ffffff\n
ggggggg\n
hhhhhhhh\n
jjjjjjjjj\n
kkkkkkkkkk\n
lllllllllll\n
mmmmmmmmmmmm\n
nnnnnnnnnnnnn\n
oooooooooooooo\n
ppppppppppppppp\n
qqqqqqqqqqqqqqqq\n
rrrrrrrrrrrrrrrrr\n
ssssssssssssssssss\n
ttttttttttttttttttt\n
uuuuuuuuuuuuuuuuuuuu\n
);
print "@a";
chomp(@a);
foreach $b (@a){
$c = " " x 20 . $b;
$d = "z";
for ($i = 1; $i < 21; $i++){
$d = chop($c) . $d;
}
chop($d);
print "$d\n";
}
--------------------------------------------
#!/usr/bin/perl -W
#@a = <STDIN>;
@a =
#qw
(
"a\n",
"bb\n",
"ccc\n",
"dddd\n",
"eeeee\n",
"ffffff\n",
"ggggggg\n",
"hhhhhhhh\n",
"jjjjjjjjj\n",
"kkkkkkkkkk\n",
"lllllllllll\n",
"mmmmmmmmmmmm\n",
"nnnnnnnnnnnnn\n",
"oooooooooooooo\n",
"ppppppppppppppp\n",
"qqqqqqqqqqqqqqqq\n",
"rrrrrrrrrrrrrrrrr\n",
"ssssssssssssssssss\n",
"ttttttttttttttttttt\n",
"uuuuuuuuuuuuuuuuuuuu\n"
);
print "@a";
chomp(@a);
foreach $b (@a){
$c = " " x 20 . $b;
$d = "z";
for ($i = 1; $i < 21; $i++){
$d = chop($c) . $d;
}
chop($d);
print "$d\n";
}
------------------------------------------------------------
Thanx,
Seedkum
------------------------------
Date: 20 Aug 2001 00:48:30 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: qw().
Message-Id: <87u1z37p41.fsf@abra.ru>
SA> Can someone please tell me why the two programs below do not give the
SA> same result?
SA> [skip]
qw() doesn't inerpolate combinations of chars like \X (X - some char)
to special chars. qw(\n) is equivalent to ('\n') but not to
("\n"). Read 'perldoc perlop' section 'Quote and Quote-like Operators'
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Sun, 19 Aug 2001 16:06:26 -0400
From: "Asgar" <asgar@tkusa.com>
Subject: Split
Message-Id: <3b801b9a$0$9821@wodc7nh0.news.uu.net>
a newbie here:
I am reading a file of fields separated by space:
while (<FILEH>)
($a, $b, $c, ....) = split (/ /); # Total of 23 fields
# Doing some stuff & writing it back to another file:
print OUTPUTFILE "$a $b $c ...."
Everything works fine, except that I am getting the first
9 fields written back into the output file.
what am doing wrong?
Thanks for any input.
------------------------------
Date: Sun, 19 Aug 2001 20:23:58 GMT
From: "Graham W. Boyes - TOAO.net" <me@REMOVETHIStoao.net>
Subject: Re: Split
Message-Id: <yfVf7.79243$B37.1847766@news1.rdc1.bc.home.com>
Run this by me again...you're getting ONLY the first 9 and not the full 23?
Graham W. Boyes
> Everything works fine, except that I am getting the first
> 9 fields written back into the output file.
> what am doing wrong?
> Thanks for any input.
>
>
>
------------------------------
Date: Sun, 19 Aug 2001 16:41:10 -0400
From: "Asgar" <asgar@tkusa.com>
Subject: Re: Split
Message-Id: <3b8022ce$0$9824@wodc7nh0.news.uu.net>
correct.
I am reading 23 fields, but when writing them out to the output file, I see
only the first 9 fields.
I am writing them back by the statment:
print OUTPUTH "$a $b $c ...." # all 23 fileds.
Thanks
"Graham W. Boyes - TOAO.net" <me@REMOVETHIStoao.net> wrote in message
news:yfVf7.79243$B37.1847766@news1.rdc1.bc.home.com...
> Run this by me again...you're getting ONLY the first 9 and not the full
23?
>
> Graham W. Boyes
>
>
> > Everything works fine, except that I am getting the first
> > 9 fields written back into the output file.
> > what am doing wrong?
> > Thanks for any input.
> >
> >
> >
>
>
------------------------------
Date: 19 Aug 2001 15:41:15 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Split
Message-Id: <87n14vdbpw.fsf@limey.hpcc.uh.edu>
>> On Sun, 19 Aug 2001 16:06:26 -0400,
>> "Asgar" <asgar@tkusa.com> said:
> a newbie here: I am reading a file of fields separated
> by space:
> while (<FILEH>) ($a, $b, $c, ....) = split (/ /); #
> Total of 23 fields
It would be simpler to use an array here surely?
> # Doing some stuff & writing it back to another file:
> print OUTPUTFILE "$a $b $c ...."
I see you're using variables called $a and $b. See
"perldoc -f sort" for why this is a bad idea. You don't
show the processing code, but if this involves a "sort"
you may be courting trouble.
> Everything works fine, except that I am getting the
> first 9 fields written back into the output file. what
> am doing wrong?
Can you write a small but complete example using a small
data set that demonstrates this problematic behaviour? If
so, please post it. I suspect you snipped the problem
code in your original post, and there's clearly not enough
there to diagnose with any certainty.
hth
t
--
Hmmmmm...sacrilicious!
------------------------------
Date: Sun, 19 Aug 2001 14:26:52 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Split
Message-Id: <3B802F1C.FB51F87A@stomp.stomp.tokyo>
Asgar wrote:
(snipped)
> # Doing some stuff & writing it back to another file:
> Everything works fine, except...
Engineer Scott, drunk on Saurian Brandy, shoved an
Oscar Meyer weiner in your warp drive.
Godzilla!
------------------------------
Date: 19 Aug 2001 14:08:51 -0700
From: rubbish_tip@hotmail.com (DB)
Subject: Re: String Parsing > Remove everything after the first non-number
Message-Id: <5e79838e.0108191308.25c8cf7f@posting.google.com>
Thanks guys - that's exactly what I need. Your efforts are much appreciated!
DB
------------------------------
Date: Sun, 19 Aug 2001 18:35:17 GMT
From: "Mark Riehl" <mark.riehl@agilecommunications.com>
Subject: Subs are automatically executing in my module?
Message-Id: <FFTf7.4208$gf.2084251@typhoon2.gnilink.net>
All - I followed the example from the Camel book, and created a file called
my_module.pm. I've got two subroutines that I'd like to make available -
load_data and find_location. For some reason, when I include "use
my_module" in a test script, it executes the two subroutines w/o calling
them.
For example, this script executes the subs:
#!perl -w
use my_module;
# The subs are executed here w/o being called.
Here's the top of my module file:
#my_module.pm
package my_module;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(load_data, find_location);
our @EXPORT_OK = qw();
our $VERSION = 1.00;
## My functions are below in the real file
...
1;
Any suggestions?
Thanks,
Mark
------------------------------
Date: Sun, 19 Aug 2001 21:06:39 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Subs are automatically executing in my module?
Message-Id: <3B800E3F.6090500@post.rwth-aachen.de>
Mark Riehl wrote:
> All - I followed the example from the Camel book, and created a file called
> my_module.pm. I've got two subroutines that I'd like to make available -
> load_data and find_location. For some reason, when I include "use
> my_module" in a test script, it executes the two subroutines w/o calling
> them.
[...]
> Here's the top of my module file:
Well, show us also at least one sub. The top of your module doesn't seem
to be responsible for that behaviour.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sun, 19 Aug 2001 19:16:34 GMT
From: "Mark Riehl" <mark.riehl@agilecommunications.com>
Subject: Re: Subs are automatically executing in my module?
Message-Id: <mgUf7.4282$gf.2120731@typhoon2.gnilink.net>
Tassilo,
Here's one of the subs:
sub find_location {
my ($this_urn, $this_time) = @_;
my ($this, $lat, $lon);
# Set as a default in case a match isn't found.
$lat = $lon = 0;
# Does this urn exist as a key in the hash?
if ( exists($LocationData{$this_urn}) ) {
# Yes, find the matching lat/long based on the time.
for $this ( @{ $LocationData{$this_urn}{movement_records} } ) {
if ($this->{time} == 8458895) {
print "Match: $this->{time}, $this->{latitude}, $this->{longitude}\n";
$lat = $this->{latitude};
$lon = $this->{longitude};
}
}
}
return ($lat, $lon);
}
Thanks,
Mark
"Tassilo von Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in
message news:3B800E3F.6090500@post.rwth-aachen.de...
> Mark Riehl wrote:
>
> > All - I followed the example from the Camel book, and created a file
called
> > my_module.pm. I've got two subroutines that I'd like to make
available -
> > load_data and find_location. For some reason, when I include "use
> > my_module" in a test script, it executes the two subroutines w/o calling
> > them.
>
> [...]
>
> > Here's the top of my module file:
>
> Well, show us also at least one sub. The top of your module doesn't seem
> to be responsible for that behaviour.
>
>
> Tassilo
>
> --
> $a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
> [1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
> (chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
> ),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
> 10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
> ord(chr($h->{$_}))))};
>
------------------------------
Date: 19 Aug 2001 21:32:07 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Uh Oh: URL Encode
Message-Id: <998255404.21655@itz.pp.sci.fi>
In article <comdog-D759F7.18140413082001@news.panix.com>, brian d foy wrote:
>In article <bafgntkd4fv5pntj7k9j9dqducdtl453h7@4ax.com>, Bart Lateur
><bart.lateur@skynet.be> wrote:
>
>> It DOES NOT escape the most dangerous characters "=" and "&". It's a
>> know bug, or feature, depending on what side you're on.
>
>i think you want to say "it does not, by default, escape all
>of the special characters that matter to the CGI". after all,
>HTTP is only one scheme out of many. :)
What Bart really wants to say is that it doesn't escape the reserved
characters [;/?:@&=+$,]. This is broken, since according to RFC 2396
these characters must be escaped _except when used for their reserved
purpose_.
Why is that broken, then? Because if the input contains any reserved
characters that are not meant to be escaped, then the input must already
be past the stage where escaping should be done.
There are exactly two meaningful classes of characters to escape: One is
[^A-Za-z0-9\-_.!~*'()], and the other is *no characters at all*. The
former should be used on fragments of an URI before joining them, while
the latter should be (not) used if you ever get the temptation to escape
an already-composed URI.
There's absolutely nothing HTTP- or CGI-specific about this. This is
just basic RFC 2396 compliance.
I still can't believe Gisle Aas got this wrong. I wonder if changing
the default character class would break more existing code than it would
fix.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: 19 Aug 2001 21:47:44 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Uh Oh: URL Encode
Message-Id: <998256767.22153@itz.pp.sci.fi>
In article <m1vgjnv5vk.fsf@halfdome.holdit.com>, Randal L. Schwartz wrote:
>>>>>> "Bart" == Bart Lateur <bart.lateur@skynet.be> writes:
>
>Bart> use URI::Escape;
>Bart> print uri_escape('a=b&c=d');
>-->
>Bart> a=b&c=d
>
>That's not a bug. Those are NOT reserved characers in a URI.
Actually, they are. "Reserved" is exactly the word RFC 2396 uses to
denote the characters in the class [;/?:@&=+$,].
>If you are constructnig a query form, parts of the query form must be
>encoded specially, and a global escaping function over the whole
>string *CANNOT* cut it.
True, though somewhat irrelevant. In fact, according to RFC 2396
escaping an already-composed URI is *never* okay. (Well, almost. You
are allowed to escape "safe" characters if for some external reason they
cannot be kept in unescaped form -- for example, if you are converting
the URI to a character set that lacks some of them, perhaps.)
>If you are sending a URI as part of an HTML response, you *must* also
>HTML-escape it, as you must *all* of your HTML data.
True again, though completely irrelevant.
>It is doing the right thing. Stop calling it a bug.
It is not doing the right thing, for any value of "right". The default
set of escaped characters in URI::Escape is good for *nothing*.
It cannot be used to escape data according to RFC 2396 before including
it in a URI, since it does not include the reserved characters. It
_also_ cannot be used for the dubious practice of ensuring that a URI
contains no invalid characters, since it does include "%".
One could argue that useless and broken default behavior isn't enough to
constitute a bug, if the documentation directly or indirectly implies
that said default behavior should never be used. But it's still bloody
silly, and ought to be fixed.
------------------------------
Date: 20 Aug 2001 02:05:36 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Uh Oh: URL Encode
Message-Id: <87y9of66z3.fsf@abra.ru>
IK> [..skip..]
>> It is doing the right thing. Stop calling it a bug.
IK> It is not doing the right thing, for any value of "right". The default
IK> set of escaped characters in URI::Escape is good for *nothing*.
IK> It cannot be used to escape data according to RFC 2396 before including
IK> it in a URI, since it does not include the reserved characters. It
IK> _also_ cannot be used for the dubious practice of ensuring that a URI
IK> contains no invalid characters, since it does include "%".
IK> One could argue that useless and broken default behavior isn't enough to
IK> constitute a bug, if the documentation directly or indirectly implies
IK> that said default behavior should never be used. But it's still bloody
IK> silly, and ought to be fixed.
Probably it is good idea to ask Gisle Aas about it on libwww
maillist. He can shed some light on decision about default safe
charset. He usually respond very quickly.
I think arguing here on c.l.p.misc hardly can improve URI::Escape.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Sun, 19 Aug 2001 21:53:18 GMT
From: "Christophe" <newspub@free.fr>
Subject: Unix command : write - how to detect a message
Message-Id: <izWf7.199$3O2.442393@nnrp6.proxad.net>
I would like to make a perl program to detect the message :
Message from someone@somewhere on ttyp3 at 23:49 ...
which appears when someone tries to have a chat with you through the 'write'
command.
I don't know how to read the messages which appear in the term through
'write'.
Thanks for your help.
Christophe
------------------------------
Date: 19 Aug 2001 21:50:17 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: URL Encode
Message-Id: <998257718.22453@itz.pp.sci.fi>
In article <997743224.65706066833809.gnarinn@hotmail.com>, gnari wrote:
>
>the CGI module also provides escaping functionality:
>
> use CGI;
> $encoded=CGI::escape($plain);
> $plain=CGI::unescape($encoded);
And, unlike URI::Escape, the functions provided by CGI.pm actually do
the right thing and escape _all_ reserved and invalid characters.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Sun, 19 Aug 2001 21:30:18 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Webserver environment settings
Message-Id: <998256618.472160566598177.gnarinn@hotmail.com>
In article <9lor0i$75d$1@neptunium.btinternet.com>,
Peter Mann <Pcmann1@btinternet.com> wrote:
>Dear All,
>I am trying to locate a relevant library/module to help attain information
>relating to a webserver.
>
>I have found plenty of scripts that reside on a webserver and provide
>information about your web server, including your perl version, environment
>variables, perl version, server time, etc.
>
>However, I am looking to do this remotely. Does anyone have any suggestions
>for a relevant library/module to assist with this.
i am not sure what you want.
if you want to access this info via cgi then you simply make a
perl script using CGI.pm that prints out the contents of %ENV,gmtime(),$]
and so on...
or it might just do
print `full_path_to_the_scripts_you_mention`;
if you are not talking about cgi access, you should look at
Net::Telnet or Net::SSH
if yoy are talking about something else, explain
in any case, the answer is most probably http://search.cpan.org/
gnari
------------------------------
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 1566
***************************************