[12108] in Perl-Users-Digest
Perl-Users Digest, Issue: 5708 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 18 01:07:09 1999
Date: Mon, 17 May 99 22:00:15 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 17 May 1999 Volume: 8 Number: 5708
Today's topics:
Re: $var interpolation in regular expressions (Ronald J Kimball)
Re: error passing a CGI object to a function in a pm. (Ronald J Kimball)
Re: FAQ 4.15: How do I find yesterday's date? <bill@fccj.org>
Re: FAQ 4.39: How can I extract just the unique element <ken@forum.swarthmore.edu>
Form Output Format <rx7@adhere.on.ca>
Re: help needed (Tad McClellan)
Re: help needed (Ronald J Kimball)
Re: how to free a Socket (Ronald J Kimball)
Re: Perl "constructors" armchair@my-dejanews.com
Re: Perl "constructors" armchair@my-dejanews.com
Re: Perl "constructors" armchair@my-dejanews.com
Re: Perl "constructors" (Randal L. Schwartz)
Re: Problem with CGI.pm need an example smnayeem@my-dejanews.com
Question 'bout LWP <mkshanx@ust.hk>
Removing Data from the File <wassimk@iname.com>
Re: Sorting problem tbsmith@deltacom.net
Re: Your assistance humbly requested (file processing p (Tad McClellan)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 18 May 1999 00:54:43 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: $var interpolation in regular expressions
Message-Id: <1drz2lh.1kkj0qzakdh7qN@p135.block1.tc4.state.ma.tiac.com>
Rick Hensh <hensh@math.msu.edu> wrote:
> According to (Win32 version) Learning Perl the following should work:
>
> $missOne = "\t[\-0-9]+\t[\-0-9]+\t[\-0-9]+\t(.+\b0[^\n])";
>
> if (/$missOne/) {
> stuff;
> }
>
>
> I've tested the regex directly and so I know that it works. Did I
> misunderstand how var interpolation works in this case?
Just to clarify the other responses, which explained that the
double-quoted string interpolates all the backslashed characters...
The only reason this particular code will not work is the "\b". In a
regular expression, \b is a word-boundary, but in any other
double-quotish string, \b is a backspace character (ASCII 8). [*] Of
course, it is rather unlikely that your target string contains a
backspace character for the regex to match. If not for that, your code
would have worked as expected.
Nonetheless, you should be using single-quotes instead of double-quotes.
[*] But in a character class in a regular expression, \b is backspace
again. :)
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
perl -le 'print "Just another \u$^X hacker"'
------------------------------
Date: Tue, 18 May 1999 00:54:44 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: error passing a CGI object to a function in a pm.
Message-Id: <1drz3me.w2qxyog3nothN@p135.block1.tc4.state.ma.tiac.com>
Bradley W. Langhorst <bwlang@genome.wi.mit.edu> wrote:
> if you want to see the actual source take a look at a previous posing
> entitled
> Can't call method "isaCGI" on unblessed reference at (eval 11)
> line1.
> to which i got no meaningful response (bad title i guess)
Okay, so I actually took the trouble to go hunt down the previous
posting and look at your code...
I think you got no meaningful response for other reasons. In
particular:
1. Too much code: we generally prefer to debug _short_ code samples.
190 lines takes too much time to go through.
2. Wrapped lines: code with wrapped lines is extremely difficult to
debug. Just running it requires manual unwrapping. When you
post code, make sure each line is less than 80 characters long.
Anyway, I would suggest printing out the value of $q before the line
where the error occurs. It should look something like this:
CGI=HASH(0x102c5128)
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Mon, 17 May 1999 22:36:59 -0400
From: "Bill Jones" <bill@fccj.org>
Subject: Re: FAQ 4.15: How do I find yesterday's date?
Message-Id: <3740d23e.0@usenet.fccj.cc.fl.us>
In article <ylpv3ztbbt.fsf@windlord.stanford.edu>, Russ Allbery
<rra@stanford.edu> wrote:
> Bill Jones <bill@fccj.org> writes:
>
>> Pray tell, when isn't there 60 seconds in each of the 60 minutes which,
>> as a group, each make up 24 hours in a 'normal day'?
>
> Days do not always have 24 hours in a time zone that has daylight saving's
> time.
I've seen that. Thx for the URL reference!
23 or 25 - Damn those DST corrections...
-Sneex- :]
__________________________________________________________________
Bill Jones | FCCJ DSS | Life is a 'Do it yourself' thing...
http://www.fccj.org/cgi/mail?dss
Jacksonville Perl Mongers
http://jacksonville.pm.org
jax@jacksonville.pm.org
'Be not the first by whom the new are tried,
nor yet the last to lay the old aside...'
------------------------------
Date: Mon, 17 May 1999 23:34:02 -0500
From: Ken Williams <ken@forum.swarthmore.edu>
Subject: Re: FAQ 4.39: How can I extract just the unique elements of an array?
Message-Id: <170519992334022393%ken@forum.swarthmore.edu>
[[ This message was both posted and mailed: see
the "To," "Cc," and "Newsgroups" headers for details. ]]
In article <373edd6f@cs.colorado.edu>, Tom Christiansen
<perlfaq-suggestions@perl.com> wrote:
>
> How can I extract just the unique elements of an array?
I think this title is a little misleading - based on the title, I
expected the techniques below to extract only (1,4) from
(1,2,2,3,3,3,4,5,5). How about one of these alternatives (or better):
"How can I remove duplicates from a list of values?"
"How can I extract the elements of an array with duplicates removed?"
[...]
> d) A way to do (b) without any loops or greps:
> undef %saw;
> @saw{@in} = ();
> @out = sort keys %saw; # remove sort if undesired
Sometimes I don't like to use temporaries, here's yet another solution:
@out = sort keys %{{ map {$_,1} @in }};
------------------------------
Date: Tue, 18 May 1999 04:44:43 GMT
From: Adam Prentice <rx7@adhere.on.ca>
Subject: Form Output Format
Message-Id: <3740EEF5.649F8420@adhere.on.ca>
I'm trying to figure out a way to take the results from a form and send
them via email in a specific format. I know how to output the form to
email but it shows up as
var1=something
var2=something else
ver3=yet something else
I'm making a form for users to subscribe to mailing list, however the
mail server wants to be emailed as follows:
subscribe emailaddress@wherever.com name
OR
unsubscribe emailaddress@wherever.com name
I can get a form to be emailed with all the data, just not in the right
format.
Any help would be appreciated.
Adam Prentice
------------------------------
Date: Mon, 17 May 1999 18:28:28 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: help needed
Message-Id: <c65qh7.pr8.ln@magna.metronet.com>
tex2121@my-dejanews.com wrote:
: I am trying to write a program that counts the m most frequent n word
: sequences in a text file.
: here is the code. Thanks.
You should enable warnings on all of your Perl scripts.
Really.
All of them.
: # User must pass the n for most frequent, m word sequneces, filenames.
: my $numofseq = @ARGV[0] || die "Please enter how many most frequent
^
^
That isn't really doing what you think it's doing, though it
often does the Right Thing even when you have done the
Wrong Thing.
Enable warnings and see what it says about that line...
: sequences you
: want.";
: my $mwordseq = @ARGV[1] || die "Please enter the length of the
: sequences.";
: my $filename = @ARGV[2] || die "Please pass file name.";
: open (FILE, $filename) or die "Can't open input file";
1) you should include the name of the file in the diagnostic message.
2) you should include the $! special variable in the diagnostic message.
open (FILE, $filename) or die "Can't open '$file' $!";
: # Read contents of file into a string. Concatinates each line on to
: # the end of the string.
: while (<FILE>) {
: $contents .= $_;
: }
That is a slow way of slurping a file.
Here is a better way:
{ local $/; # undef is slurp mode
$contents = <FILE>;
}
: close (FILE);
: # Take contents of file and split it on whitespace, then insert into
: array.
: @wordlist = split (/ /,$contents);
You will have null fields wherever there are consecutive
spaces. Is that what you wanted?
: foreach $word (@wordlist) {
You don't need the @wordlist temp variable either.
foreach $word ( split / +/,$contents) {
: # Remove newlines, punctuation from each line so we can ingore them
: later.
: # Replace them with whitespace.
: $word =~ s/[\n|.|,|"|?|>|<|_|-|=|+|`|~|!|@|#|$|%|^|&|*|(|)
: |;|:|'|\/|\\]//g;
You do not need *any* of those vertical bar chars (|) there!
( Try it! Take them all (but one) out. You will get identical output )
A characters class is a list of characters. It is not a
regular expression where you can do alternation.
But that doesn't matter much anyway since a regex is not a
good way to delete individual characters:
$word =~ tr/\n.,"?><_-=+`~!@#$%^&*();:'\/\\//d;
: push(@wordlist2,$word);
: }
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 18 May 1999 00:54:46 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: help needed
Message-Id: <1drz4sq.196vxyc10rog86N@p135.block1.tc4.state.ma.tiac.com>
<tex2121@my-dejanews.com> wrote:
Hey, you followed up that you were able to figure it on your own, so I
just wanted to comment on this one bit:
> $word =~ s/[\n|.|,|"|?|>|<|_|-|=|+|`|~|!|@|#|$|%|^|&|*|(|)
> |;|:|'|\/|\\]//g;
You seem to be confused about character classes. | is not special in a
character class; a character class is already a list of alternatives.
Try this instead:
$word =~ s/[\n.,"?><_-=+`~!\@#\$%^&*();:'\/\\]//g;
(Note that you need to backslash the @ and the $.)
But a better way would be to list all the characters you want to keep,
and negate the character class with a ^ at the beginning:
$word =~ s/[^a-zA-Z0-9]//g;
But if you're doing substitutions on single characters, you probably
want to use tr/// instead:
$word =~ tr/a-zA-Z0-9//cd;
/c complements the class, just like ^ in [^a-zA-Z0-9].
/d deletes characters which don't have a replacement character.
That's all of them here, because the replacement part is empty.
HTH!
--
#!/usr/bin/sh -- chipmunk (aka Ronald J Kimball)
perl -se 'print sort grep tr/ \n//, keys %main::
' -- -is -' Just' -' another ' -'Perl ' -'hacker
' http://www.tiac.net/users/chipmunk/ [rjk@linguist.dartmouth.edu]
------------------------------
Date: Tue, 18 May 1999 00:54:47 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: how to free a Socket
Message-Id: <1drz5r9.ix0cz21ng8itsN@p135.block1.tc4.state.ma.tiac.com>
Sebastian Ahrens <dataadm@elfi2.rz.ruhr-uni-bochum.de> wrote:
> I am using IO::Socket and IO::Select for a server-application. Now
> obviously a used socket is not freed immediately, because after a
> control-d and a restart of the server-app the handle for the socket is
> not valid -- I get this error:
>
> Can't use an undefined value as a symbol reference at
> /usr/local/lib/perl5/5.00502/sun4-solaris/IO/Select.pm line 57, <> chunk
> 1.
Since Tony Smith already explained about SO_REUSEADDR....
You probably get that error because you forgot to make sure that you
actually created the socket successfully. Something like:
$socket = IO::Socket::INET->new(@args) ||
die "Can't create socket";
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 18 May 1999 03:51:00 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hqo34$hlt$1@nnrp1.deja.com>
In article <7hp2fa$bj9$1@nnrp1.deja.com>,
John Porter <jdporter@min.net> wrote:
> In article <7hippv$8j0$1@nnrp1.deja.com>,
> armchair@my-dejanews.com wrote:
>
> As I understand it, what you are proposing is that perl disallow
> any method from returning a blessed lexical except those whose
> name is in some special set (i.e. either 'new', or the final
> element of the class path name* -- you haven't said which).
I said "new", but I think the same name as the Module/Class would
actually be better. But since Perl does not have what C++ calls
"function overloads" where the same name can be used for different
functions, who each differ by input parameter types - having only one
allowable name for a constructor would preclude having multiple
constructors of an object. I can see where that would be undesirable. So
I wouldn't propose any restriction on the constructor name unless Perl
added support for two or more methods having the same name.
>
> But this is a bogus restriction that makes life worse for Perl
> programmers while adding nothing of any benefit to anyone else.
I think there is some benefit to be looking at code and instantly see
that a method is a constructor, or not.
>
> > And since C++ is
> > used for major projects, whereas Perl is used on more "quick and
> dirty"
> > small projects, I am very surprised that you would feel that the
Perl
> > way is the right way.
>
> "Right" is only meaningful in context. When you're programming
> in Perl, the Perl way *is* the right way. At least, "more right" than
> the way of some alien language.
I would agree that "right" is a matter of opinion in many things,
including this.
>
> The size of the projects on which Perl is used is irrelevant.
I am using size of the project to try and amplify a value or benefit.
If I recommended you use a squeegee to clean your windshielf, you would
laugh and say "I've been using a paper towel just fine for years and
so have all my friends and we have the cleanest windhields in town". And
that's true, with one windshield cleaning
a month, the benefit of a squeegee is negligible. But when you are
assigned the task of cleaning every windshield in the mall parking, the
benefit of a squeegee starts to become significant. Size matters.
>
> > I have not run into any brick wall,
>
> Then your argument is merely academic.
> Perl doesn't respect academic arguments.
> Perl gets real work done in the real world.
> That its design philosophy! Perl is Practical.
You write "Perl doesn't respect academic arguments".
Can you please define Perl as used in your statement.
>
> > but having worked
> > with C++, I can assure you that having only one reference in an
object
> > point to its data (none of which is a struct or true
multi-dimensional
> > array) does not lead to a great convenience in programming.
>
> As a professional Perl programmer, I can assure you that it does
> indeed lead to great convenience. Based on my own personal
> experiences. This carries rather more weight with me that your
> "assurances", which seem to be based on nothing more than some
> familiarity with a kludgy half-baked OOPL wannabe. Not that Perl
> is Smalltalk or Eiffel, but C++ isn't either. You need to get past
> the biases you bring from other languages, and understand Perl
> for what it is. The similarity of the syntax is misleading; Perl
> is really nothing like C++, and any expectations that it is are
> bound to lead to frustration.
As a Perl advocate, I would refrain from using the phrase "kludgy
half-baked OOPL wannabe".
Perl has some real pluses versus C. Strings, dynamic arrays, dynamic
"hashes". The programmer doesn't have to worry about memory allocation
or deallocation. And I will againe give credit for the type of a
variable being
semi-conveyed in variable names (I have discussed the ambiguity of $
before). Perl is interpreted which is great in many situation.
And Perl has objects.
Which leads us to the fact that Perl has not always had objects. So,
presumably, at one time in the not so
distant past, someone said "hey, Perl should have objects" at which
point I would have to guess that there was a chorus of - "you don't need
objects, objects don't buy you anything, you can get there from here
without objects, don't put your box on Perl,
think the Perl way, you're not smart enough for Perl, go use a language
other than Perl." And yet.... now Perl has objects. The point being,
Perl is a dynamic language, like most languages seeing continued usage.
Things have been added to Perl over the years, and I am sure they will
continue to be added, in the same way C++ has added strings, and via the
STL, dynamic arrays and maps. So I can only hope that you won't try and
put Perl in a box regarding things like records. I don't think Perl
would like that.
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Tue, 18 May 1999 03:53:56 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hqo8k$hte$1@nnrp1.deja.com>
In article <7hpa1r$grq$1@nnrp1.deja.com>,
John Porter <jdporter@min.net> wrote:
> In article <7hjjuu$sbm$1@nnrp1.deja.com>,
> armchair@my-dejanews.com wrote:
> > If Perl doesn't enforce a name for a constructor, due to it's
> > "libertarian attitude" that allows the programmer to do what they
> > think is right, then you are commiting heresy by suggesting that
> > anyone's naming of a constructor is wrong.
>
> Heh. If you were simply arguing that certain names are better than
> others, and that programmers should therefore prefer them, then you
> would have a point. But (up to now, at least), you have been arguing
> that perl should enforce a restriction on names, flagging some as
> illegal. That, of course, is the heresy.
I think I am catching on. It is okay to criticize a programmer's style,
but not Perl's style.
>
> --
> John Porter
> Put it on a plate, son. You'll enjoy it more.
>
> --== Sent via Deja.com http://www.deja.com/ ==--
> ---Share what you know. Learn what you don't.---
>
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Tue, 18 May 1999 04:08:51 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hqp4j$ibh$1@nnrp1.deja.com>
In article <7hpar3$hdh$1@nnrp1.deja.com>,
John Porter <jdporter@min.net> wrote:
> In article <7hjioj$rks$1@nnrp1.deja.com>,
> armchair@my-dejanews.com wrote:
> > ... records are fixed in the number and type (but not
> > possible in Perl) of fields they hold, whereas a hash or array can
> hold
> > 0 to n fields and has to be checked if the code is going to be
> "robust"
> > and handle invalid passed parameters gracefully.
>
> You know, an analogous situation exists in C++ (and in OO langs
> in general, including Perl).
>
> class A;
>
> class B : A {
> public:
> int foo();
> };
>
> class C : A {
> public:
> int bar();
> };
>
> int f( A& a ) {
> a.foo(); // can I call this?
> a.bar(); // or this? and how do I know?
> };
This code is not valid, at least not in C++, as it won't compile:
ERROR: A has no member foo
ERROR: A has no member bar
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: 17 May 1999 21:56:24 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl "constructors"
Message-Id: <m1d7zzm0w7.fsf@halfdome.holdit.com>
>>>>> "armchair" == armchair <armchair@my-dejanews.com> writes:
armchair> I think I am catching on. It is okay to criticize a
armchair> programmer's style, but not Perl's style.
You're not tolerated to criticize Perl's style until you know why
the things *are* the way they are.
Hint: it's not haphazard. Most everything in Perl is by design. You
must first understand why the designers chose their methods before
saying "I have a better way". I don't yet see any evidence that you
could understand that Perl *is* the way that it is for many reasons,
most of them good. When you can say "I see why it was chosen to be
this way, and has anyone considered this other way", you will be
heard.
And this is why the others in the thread also rebuke your challenges.
You are claiming an arrogance which you have not earned.
Certainly, the developers that have earned their pennance are
permitted to suggest changes to syntax. But they've also worked with
Perl for many months, perhaps years, longer than you.
When you have done that, you will be heard. Until then, you sound a
bit like the child getting behind the steering wheel of his first car
going "gee, those pedals should be a lot closer to my feet". We think
not.
print "Just another Perl hacker," (since almost day one :)
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Tue, 18 May 1999 03:56:09 GMT
From: smnayeem@my-dejanews.com
Subject: Re: Problem with CGI.pm need an example
Message-Id: <7hqocp$hva$1@nnrp1.deja.com>
In article <7hpae8$h0h$1@nnrp1.deja.com>,
bmccormack7477@my-dejanews.com wrote:
> In article <7hosp4$7u8$1@nnrp1.deja.com>,
> smnayeem@my-dejanews.com wrote:
> > does anyone have an example of the correct way of using the label
and
> > the values for say a radio group?
> > heres my cgi script but its not giving the desired output.
> >
> > #!g:/perl/bin/perl
> >
> > use CGI::Carp qw(fatalsToBrowser);
> > use CGI;
> >
> > $query = new CGI;
> >
> > print $query->header;
> > print $query->start_html("Agni Billing System");
> >
> > print_prompt($query);
> >
> > print $query->end_html;
> > exit;
> >
> > ## Subroutines ##
> >
> > sub print_prompt {
> > my ($query) = @_;
> > print $query->start_multipart_form;
> > %labels = ('male'=>'m','female'=>'f');
> > print
> > "Login ",
> > $query->textfield(-name => 'LOGIN', -size => 10),"<BR>",
> > "User name ",
> > $query->textfield(-name => 'USERNAME', -size => 25),"<BR>",
> > "Sex",
> > $query->radio_group(-name => 'SEX', -values => ['m','f'],
> > -default => 'm', -label=>\%labels);
> > print $query->checkbox(-name=>'checkbox_name',
> >
> > -checked=>'checked',
> >
> > -value=>'ON',
> >
> > -label=>'CLICK ME');
> >
> > }
> >
> > if i run the above script the SEX radio group field should be
> displaying
> > male and female and internally storing m or f. however its
displaying
> m
> > and f. anyone knows where i went wrong?
> > please help me on this :)
> > thanks
> >
> > smnayeem
> > smnayeem@agni.com
> >
> > --== Sent via Deja.com http://www.deja.com/ ==--
> > ---Share what you know. Learn what you don't.---
> >
> Make your values "values %labels"
> and your labels "keys %labels"
> cgi doesn't automatically dereference
> the keys of the named hash at labels=>'\%hash'
> with the named values at values=>'\@array'
ive changed the problem line as follows :
$query->radio_group(-name => 'SEX', -values => [values %labels],
-default => 'm', -label=>keys %labels);
but it doesnt seem to work either, is giving f and m instead of m and f.
but again thats not what i really wanted hehe :)
smnayeem
smnayeem@agni.com
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Tue, 18 May 1999 12:30:59 +0800
From: "Shashank Tripathi" <mkshanx@ust.hk>
Subject: Question 'bout LWP
Message-Id: <7hqqfj$7mq@ustsu10.ust.hk>
Hi,
Would really appreciate if someone could tell me how I can get a page (thru
LWP) which has nothing but a redirect tag in it..
Thanks
Shanx
------------------------------
Date: Mon, 17 May 1999 23:03:01 -0500
From: "Wassim Metallaoui" <wassimk@iname.com>
Subject: Removing Data from the File
Message-Id: <3740e732.0@wznews.webzone.net>
Can someone please explain some of this too me.. . I am trying to remove the
line from the file if it exsists. If not tell them so.
The comments are mine...
I am just not getting were it removes the line from the database... My
friends tell me its happening and I know its happening because i see it work
but....!! how does it do it!! can someone point it out to me...
Please send an e-mail to wassimk@iname.com with a reply or post a reply.
Special thanks to David Cassell (cassell@mail.cor.epa.gov) for helping me
understand the fork(); process and answering some questions about the
sendmail program.
sub unsubscribe {
&checkaddress; #routine that makes sure its an okay e-mail address to use.
if its not okay then it will exit and tell me
open (DAT,"$listdir/emails.txt"); #opens the database file, each line is an
e-mail address
if ($LOCK_EX){ flock(DAT, $LOCK_EX); } #just locks the file
@database_array = <DAT>; #puts everything into an array
close(DAT); #closes the file
print "Content-type: text/html\n\n"; #standard html header
open (DAT,"<$listdir/emails.txt"); #opens the file again
if ($LOCK_EX){ flock(DAT, $LOCK_EX); } #locks it
foreach $lines(@database_array) { #defines the lines from the
database array
chomp($lines); #chops off the end character on the lines
$email = $INPUT{'email'}; #e-mail inputted from the web
$lines =~ tr/A-Z/a-z/; # changes all of the lines contents from
uppercase to lowercase
$email =~ tr/A-Z/a-z/; # changes all of the e-mails contents from
uppercase to lowercase
if ($lines eq $email) { # if the database has the e-mail in it then tell me
so and move on
print "removed successfully"; #tell me whats going on
close (DAT); #close the data file
open (DAT,">$listdir/emails.txt"); #opens file with write permissions
if ($LOCK_EX){ flock(DAT, $LOCK_EX); } #locks it
foreach $lines(@database_array) { #defines the lines in the array
chomp($lines); #chops of the ends of the lines
$email = $INPUT{'email'}; #the e-mail from the web
$lines =~ tr/A-Z/a-z/; #converts uppercase to lower
$email =~ tr/A-Z/a-z/; #converts uppercase to lower
if ($lines ne $email) { #if the email is not in the database then there is
nothing to remove
print DAT "$lines\n"; #so put everything back in
}
}
close (DAT); #close the file
exit; #exit the script
}
}
print "Your not in the database"; #tell me I am not in it...
close (DAT); #close something again..
exit; #exit the script
} #closes the sub
------------------------------
Date: Tue, 18 May 1999 03:46:38 GMT
From: tbsmith@deltacom.net
Subject: Re: Sorting problem
Message-Id: <7hqnqu$hjn$1@nnrp1.deja.com>
In article <7hom4b$g9g$1@fleetstreet.Austria.EU.net>,
"Thomas Klinger" <t.klinger@mobilkom.at> wrote:
> Hi there, again me! :)
>
> I've written this code:
>
> [...]
> foreach $techline (
#(untested):
sort{ (split /;/, $a)[2] cmp (split /;/, $b)[2]} @techlines
> ) {
> ($type, $setnr, $technr, $subject, $s5, $s6, $s7, $note) = split
(/;/,
> $techline);
> chop ($note) if $note =~ /\n$/;
This is why Perl has 'chomp'.
> $s5 =~ s/^/\-/ if $s5 eq "";
better written: $s5 ||= "-";
> $s6 =~ s/^/\-/ if $s6 eq "";
> $s7 =~ s/^/\-/ if $s7 eq "";
> if ($setnr =~ m/$FORM{'TNSET'}/i){
> print
>
"<tr><td>$type</td><td>$setnr</td><td>$technr</td><td>$subject</td><td>$
s5</
> td><td>$s6</td><td>$s7</td><td>$note</td></tr>\n";
> }
> }
> [...]
>
> The problem: in variable $technr are numbers in miscellaneues order.
How do
> I have to change the code that the results are ordered by their value
> $technr descending?
> Should I push the values into an array/hash then do a sort? That would
mean
> that I'm doing the job twice (split, looking for match, push, sort,
split).
> Is there an easier way?
>
> Thanx to all in forward for the help.
>
> --
> Best regards,
> Thomas Klinger
> ========================================
> ......E-Mail: t.klinger@mobilkom.at.....
> .........WWW: http://www.mobilkom.at....
> ========================================
>
>
--
----------------
Todd Smith -japh
ITC^DeltaCom
tbsmith@deltacom.net
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Mon, 17 May 1999 18:53:28 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Your assistance humbly requested (file processing problem)
Message-Id: <8l6qh7.pr8.ln@magna.metronet.com>
Josh Pointer (josh@bitwell.net) wrote:
: My problem is as follows. I need to read in an existing file, throw away
: certain predefined lines and write the remaining lines to a new file
: which replaces the existing file. Being overly blessed with hubris, I
: thought I had it, but I apparently don't. The following code produces a
: blank file.
It seems to work for me (after fixing whatever horrid thing
happened to the formatting of the code).
The code is so ugly, that I have snipped it all.
You are writing C code in Perl. Your hubris will continue to
suffer until you start writing Perl code in Perl.
You seldom need to index arrays yourself in Perl programming.
This program produces output identical to your original program:
--------------------
#!/usr/bin/perl -w
use strict;
my $temp_file = 'data';
my(@initialize) = ( -27, 2, -16, 3, -8, 3, -8, 3, -10, 2, -8, 3, -9, 3,
-8, 3, -8, 3, -29 );
open(FILE_IN, $temp_file) or die "could not open '$temp_file' $!";
open(FILE_OUT, ">$temp_file.tmp") or die "could not open '$temp_file.tmp' $!";
foreach my $length ( @initialize ) {
if ($length < 0) {
<FILE_IN> while $length++;
}
else {
print FILE_OUT scalar <FILE_IN> while $length--;
}
}
close(FILE_IN);
close(FILE_OUT);
--------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 5708
**************************************