[13259] in Perl-Users-Digest
Perl-Users Digest, Issue: 669 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 28 16:07:24 1999
Date: Sat, 28 Aug 1999 13:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 28 Aug 1999 Volume: 9 Number: 669
Today's topics:
Re: bizarre PERL/CGI behavior question rancid@best.com
Re: Can anyone lend a hand please? <richard@madchicken.com>
Re: Debug question <richard@madchicken.com>
Re: essentially; making a long file name into a 8.3 fil (Larry Rosler)
Re: help with signal handler <yeeliu@convex.hhmi.columbia.edu>
Re: help with signal handler <meowing@banet.net>
Re: How do I ... ? (Pete Holsberg)
Re: How do I ... ? (Larry Rosler)
Insecure dependency with setuid() <zylou@altern.org>
Re: Insecure dependency with setuid() <jbc@shell2.la.best.com>
Re: IRC CONNECT <jeff@vpservices.com>
Re: Matching E-mail <jbc@shell2.la.best.com>
Re: Removing <HTML> Tags (Abigail)
Re: Removing <HTML> Tags <revjack@radix.net>
Re: Removing a line from a text file (Larry Rosler)
Re: Removing a line from a text file <jbc@shell2.la.best.com>
Re: sorting a delimited string by second field <apter@panix.com>
Re: sorting a delimited string by second field (Abigail)
Re: sorting a delimited string by second field (Larry Rosler)
Style question: where should my declarations go? <jbc@shell2.la.best.com>
Re: The extent of double-quotish interpolation (Mark W. Schumann)
Re: The extent of double-quotish interpolation (Randal L. Schwartz)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 28 Aug 1999 18:33:19 GMT
From: rancid@best.com
Subject: Re: bizarre PERL/CGI behavior question
Message-Id: <37c82a86.227553082@nntp.best.com>
On Fri, 27 Aug 1999 23:58:45 -0600, "Arunas Salkauskas"
<arunas@an!m.org> wrote:
>Have you tried refreshing your cache? On the browser? What works for some
>browsers is to hold down shift while clicking on the refresh/reload button,
>I've also seen CTRL+SHIFT have a stronger effect...
>
>I just looked again, and the page still works fine.
>
Yep, I know the browser reload tricks and had tried those (although
I've found that you don't really need them when you're causing a CGI
script to rerun). I just went in and cleared my memory and disk caches
and that had no effect either. Oh well, if I'm the only person that
can't see that one label, I can live with that. But what a bizarre
bug.
thanks for the response.
chanel
>
>rancid@best.com wrote in message <37c6eb0f.145757984@nntp.best.com>...
>>On Fri, 27 Aug 1999 13:27:40 -0600, "Arunas Salkauskas"
>><arunas@an!m.org> wrote:
>>
>>>I gather you found the problem, since Audible Deafenings was there, and
>the
>>>link was fine.
>>>
>>
>>Hmm, that's interesting. It isn't showing up for me (still), but it is
>>for you. That's weird.
>>
>>chanel
>>
>>>
>>>rancid@best.com wrote in message <37c6cd93.138209076@nntp.best.com>...
>>>>
>>>>I have flat-file "database" containing record labels and the URL of
>>>>their web page that consists of 3 fields delimited by the pipe
>>>>character (|). The first field is for alphabetization purposes, the
>>>>second field is the name of the label, and the third field is the URL.
>>>>To speed lookup (users can retrieve labels by the first letter),
>>>>there's another file that contains the byte location of where each
>>>>chunk of the alphabet begins and for how many lines that chunk
>>>>continues.
>>><SNIP>
>>>>You can see the lack of output in action at
>>>>http://www.arancidamoeba.com/lettersearch.cgi?a
>>>>Scroll down the page to where the label Audible Deafenings ought to be
>>>>located.
>>>>
>>>>Thanks for any help you can provide! This has me scratching my head
>>>>verging on pulling hair out.
>>>>
>>>>chanel
>>>>rancid@best.com
>>>
>>>
>>
>
>
------------------------------
Date: Sat, 28 Aug 1999 20:31:38 +0100
From: "Richard" <richard@madchicken.com>
Subject: Re: Can anyone lend a hand please?
Message-Id: <37c83976_1@newsread3.dircon.co.uk>
Hi,
Thanks go to all for helping me out. It's much appreciated!
Best Regards,
Richard.
Arunas Salkauskas wrote in message <37c77e6c@news.cadvision.com>...
>Writing to a file probably isn't the big problem.
>
>There are basically two approaches to the while thing, one is to use
>cookies, where you expect the browser to identify itself to you once you've
>decided that the password is valid, and the other is to create a session
>identifier and encode that into the URL (ie
>/cgi-bin/infoscript.pl/some/path/?sessionid=19290498039807 ), and then make
>sure that when somebody responds with this sessionid, that it corresponds
to
>a user that has recently logged in.
>
>Putting the sessionid in the URL can be tricky - it means you can't
>accidentally redirect the person to a plain HTML page unless you know that
>all the links out of that page will be able to encode the sessionid into
the
>URL again (remember this has to be done dynamically, the sessionid has to
be
>different for every visitor - well not always, but it might help with
>security, otherwise I can notice what the id is, and type the URL in by
hand
>and break in without getting authenticated).
>
>Try making user-password-action files where each line in the file is a row
>of these bits of information separated by : or |, and be careful that
people
>don't use these in their usernames or passwords - that will really mess you
>up.
>
>Either way, most of this is very conceptual, and requires a bit of thought,
>and perhaps a visit to a newsgroup that deals with CGI, like
>comp.infosystems.www.authoring.cgi once you wrap your mind around the
>concepts of how to direct the flow of information, then look into the
>language of perl, and figure out how to read and write files etc.
>
>You can also make the user pick a username and password, and then use this
>to generate a file that the web server would recognize (this requires
fairly
>low level access to the server) as a source for authenticating users. Then
>once they login (the get prompted by the browser) the server will pass a
>variable called REMOTE_USER to your CGI programs. Once again, this is a
>topic for a CGI group, and possible a web server group.
>
>--
>- Arunas Salkauskas
>High Point Designs
>www.highpointdesigns.com
>
>Richard wrote in message <37c6ce56_2@newsread3.dircon.co.uk>...
>>Hi All,
>>
>>My name is Richard and I'm 17 years old. I'm frantically trying to get to
>>grips with Perl. I can get it to do the more simple tasks, such as return
>>values from a form when submitted and then act on the contents of a hidden
>>field, eg..
>>
>>if ($in{'action'} eq "gotonextstage") { &some_sub }
>>
>>I'm Ok with that. But where I really need help is being able to 'register'
>a
>>user. For example, visitor fills out a form that has Username, Password
and
>>Full Name as fields. This stuff is stuck in one large user database which
>is
>>used to validate users when they try to 'log in'. When they try to log
in -
>>if they are successful - they are given access to a specific subroutine
>>within a cgi-program, perhaps containing HTML or such to be protected.
>>
>>Does anyone know how I can do this? Or maybe you have a sub-routine that
>>would be of use to me?
>>
>>Thanks very much for your time and help.
>>
>>Best Regards,
>>
>>Richard.
>>
>>
>
>
------------------------------
Date: Sat, 28 Aug 1999 20:27:49 +0100
From: "Richard" <richard@madchicken.com>
Subject: Re: Debug question
Message-Id: <37c83892_1@newsread3.dircon.co.uk>
Many thanks for your input, it is much appreciated.
Regards,
Richard.
Alan J. Flavell wrote in message ...
>On Fri, 27 Aug 1999, Richard wrote:
>
>> My ISP has given me access and permission to create and run my own
perl/cgi
>> scripts, but I can't telnet to the system in order to debug the scripts
>
>Same answer as plenty before you got, I'd say. Debugging from the
>command line can take you so far, but there's no real substitute for
>doing the final debugging of a CGI script via a web server.
>
>Installing Apache for this is no big deal (you might even get to like it
>and use it as a real web server, rather than just as a test harness for
>CGI scripts ;-)
>
>Btw, if you're fighting the evil empire instead of a real OS, then
>perhaps the following remark helps. From a standing start, I'd say it
>took little more than half an hour to install activestate perl and win32
>apache on Win95, and get them to the point where they were running a
>"hello world" CGI script in Perl. That was just following the
>instructions. OK, I admit I was already familiar with Perl and Apache
>under unix, but whether that really helped or hindered, I'm not sure.
>
>> the telnet prompt via the borwser? I'll tear my hair out if I see that
>> "Internal Server Error" message one more time!!
>
>Exactly, and that's part of the reason that you'll want to debug via
>a server. But don't miss the Idiot's Guide to debugging CGI scripts, it
>has certainly helped me on several occasions when I've missed some vital
>point.
>
>have fun (as Jacqui says, if it isn't fun then you aren't doing
>it right ;-)
>
>Oh, could I steer you towards the more-relevant groups for questions
>that aren't specific to Perl, i.e c.i.w.authoring.cgi or the
>appropriate c.i.w.servers.OS that's appropriate to the OS you are
>running? This here group tries to focus on Perl-specific matters.
>
------------------------------
Date: Sat, 28 Aug 1999 11:27:35 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: essentially; making a long file name into a 8.3 filename..
Message-Id: <MPG.1231c9eb7393189b989ec5@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <37C7D11A.77B78EE6@0011.com> on Sat, 28 Aug 1999 05:07:54 -
0700, Kin Lum <kin@0011.com> says...
> Jim Matzdorff wrote:
> > I want to essentially take a string that is a long filename, with any
> > number of periods being replaced by "_" except for the last, all to make
> > it into a 8.3 valid format.
>
> I think the following solution is the most complete so far:
...
> Output:
> =======
> thislongfile.name => thislong.nam
> a.long.file.description => a_long_f.des
> noextention => noextent.ion
> no_extention => no_exten.tio
> thislongfilehello => thislong.fil
> hello => hello
> hi => hi
> a => a
> 0.abcdefghijklm => 0.abc
> abc.db => abc.db
> abc. => abc
> .c => _c
> .cshrc => _cshrc
> .cshrc123456789 => _cshrc12.345
> a.b => a.b
> 0.0 => 0.0
>
> I think Larry's solution is very nice, short and
> elegant.
Based on an original attempt by Abigail.
> There are a few catches, however, and
> I can't seem to fix it using Larry's solution:
These are all matters of interpretation of the loose problem
specification.
> thislongfilehello => thislong.llo
Using the last three characters as the extension makes more sense to me
than using the ninth through the eleventh characters.
> hello => he.llo
For creating 8.3 where there is no extension, why should a shorter name
be treated differently from one with nine or more characters?
> 0.abcdefghijklm => 0_abcdef.klm
The latest variation fixes this bug: '0.abc'.
$s =~ s/(.*?)(?:\.([^.]{0,3})[^.]*|([^.]{3}))$/
(my $l = substr $1, 0, 8) =~ y!.!_!; "$l.$+"/e;
> .c => .c
> .cshrc => _cs.hrc
> .cshrc123456789 => _cshrc12.789
It now produces '.csh' for the last two above.
> incidentally, it seems filenames such as ".login"
> or "abc." are not valid 8.3 filenames.
> I took the liberty of converting ".cshrc"
> to "_cshrc" instead of considering it to be invalid.
As this is not well specified, one is free to do anything reasonable. I
choose to truncate the 'extension' to three characters. Otherwise it
might take more than a one-liner. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 27 Aug 1999 13:08:03 -0400
From: Yee Liu <yeeliu@convex.hhmi.columbia.edu>
Subject: Re: help with signal handler
Message-Id: <37C6C5F3.9440EC56@convex.hhmi.columbia.edu>
Hi,
Thanks for the reply. I tried adding a line to reinstall the signal handler
in both init() and hup_handler() and it still has the same problem. I even
tried replacing the last line in the signal handler, "init();", with "exec
$0;" and that didn't help either.
yee
Larry Rosler wrote:
> In article <37C6A46A.EFE2D330@convex.hhmi.columbia.edu> on Fri, 27 Aug
> 1999 10:44:58 -0400, Yee Liu <yeeliu@convex.hhmi.columbia.edu> says...
> > #!/bin/perl -l
> > $SIG{HUP} = \&hup_handler;
> > init();
> >
> > sub init() {
> > print "init";
> > sleep;
> > }
> > sub hup_handler() {
> > print "hup receiverd";
> > init();
> > }
> >
> > What I want is a little program that sits there and waits, do something
> > when it receives
> > a HUP signal and then waits again. The above code worked only with the
> > first HUP signal it received, but it does not work when subsequent HUP
> > signals were sent. What is wrong here?
>
> Signal handlers need to be reestablished after being used. Move the
> assignment to $SIG{HUP} into init().
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
------------------------------
Date: 28 Aug 1999 15:51:12 -0400
From: meow <meowing@banet.net>
Subject: Re: help with signal handler
Message-Id: <87ogfrof9r.fsf@banet.net>
Larry Rosler <lr@hpl.hp.com> wrote:
>> #!/bin/perl -l
>> $SIG{HUP} = \&hup_handler;
>> init();
>>
>> sub init() {
>> print "init";
>> sleep;
>> }
>> sub hup_handler() {
>> print "hup receiverd";
>> init();
>> }
>>
>> What I want is a little program that sits there and waits, do something
>> when it receives
>> a HUP signal and then waits again. The above code worked only with the
>> first HUP signal it received, but it does not work when subsequent HUP
>> signals were sent. What is wrong here?
> Signal handlers need to be reestablished after being used. Move the
> assignment to $SIG{HUP} into init().
That won't work, because now init() is running inside the handler.
Another problem is that Perl can leak memory like crazy if you
reestablish a handler inside the handler, on a system that doesn't
need that extra kick. ('twould be nice if Configure figured out what
style signal was compiled in and reported on it or even did the right
thing automagically).
eg: The following construct copied straight from perlipc does heinous
malloc things under FreeBSD of about a year ago (probably current
stable releases too; for this one, you'll need something that forks
lots and lots of kids to make it go boom):
sub REAPER {
$waitedpid = wait;
# loathe sysV: it makes us not only reinstate
# the handler, but place it after the wait
$SIG{CHLD} = \&REAPER;
}
$SIG{CHLD} = \&REAPER;
# now do something that forks...
This is where that stuff about doing nothing more than setting a
prefab flag var in a handler comes in. Basically, you end up with the
goofy-but-if-it-works-what-the-hey tactic of moving the signal
handler outside the signal handler.
#!/bin/perl -wl
use strict;
print "For a good time, kill -HUP $$";
my $hupped = 0;
$SIG{HUP} = \&hup_handler;
while (1) {
init();
if ($hupped) {
print "hup received";
$hupped = 0;
$SIG{HUP} = \&hup_handler;
}
}
sub init() {
print "init";
sleep;
}
sub hup_handler() {
$hupped = 1;
}
__END__
------------------------------
Date: 28 Aug 1999 16:38:00 GMT
From: pjh@mccc.edu (Pete Holsberg)
Subject: Re: How do I ... ?
Message-Id: <7q9398$34v$1@lawrenceville.mccc.edu>
Pete Holsberg (pjh@mccc.edu) wrote:
:
: I'm reading fixed length values into a set of variable
: (data file is a screen dump) and the values are of course
: padded with trailing blanks. (I'm trying to convert each
: screen's values into a line of delimited field values.)
:
: Is there a simply way to eliminate those blanks?
Never mind. $var =~ s/ +$//; did it.
Pete
------------------------------
Date: Sat, 28 Aug 1999 10:39:10 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How do I ... ?
Message-Id: <MPG.1231be9bc4f759ee989ec3@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <7q92fq$1t5$1@lawrenceville.mccc.edu> on 28 Aug 1999 16:24:26
GMT, Pete Holsberg <pjh@mccc.edu> says...
> I'm reading fixed length values into a set of variable
> (data file is a screen dump) and the values are of course
> padded with trailing blanks. (I'm trying to convert each
> screen's values into a line of delimited field values.)
>
> Is there a simply way to eliminate those blanks?
Yes. The simplest way is with a regex. It is so simple that even the
FAQ (perlfaq4: "How do I strip blank space from the beginning/end of a
string?") deals with a harder problem -- stripping both ends at once.
But you can read it and extract the simpler solution from it.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 28 Aug 1999 19:41:02 +0200
From: Nathan ZYLBERSZTEJN <zylou@altern.org>
Subject: Insecure dependency with setuid()
Message-Id: <37C81F2E.E1A76564@altern.org>
Hi,
I'm trying to use setuid() in a script, but I have always the Insecure
dependency error.
I 've looked in the documentation and I found this but I don't
understand:
" Perl presumes that if you reference a substring using $1, $2,
etc., that you knew what you were doing when you wrote the pattern.
That means using a bit of thought--don't just blindly untaint anything,
or you defeat the entire mechanism. It's better to verify that the
variable has only good characters (for certain values of ``good'')
rather than checking whether it has any bad characters. That's because
it's far too easy to miss bad characters that you never thought of.
Here's a test to make sure that the data contains nothing but ``word''
characters (alphabetics, numerics, and underscores), a hyphen, an at
sign, or a dot.
if ($data =~ /^([-\@\w.]+)$/) {
$data = $1; # $data now untainted
} else {
die "Bad data in $data"; # log this somewhere
}
"
what is $1 ?
what is $data ?
what is the variable containing the string I want to untaint ?
Thank you
Nathan
nathan.zylbersztejn@advalvas.be
------------------------------
Date: 28 Aug 1999 18:35:32 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: Insecure dependency with setuid()
Message-Id: <37c82bf4$0$17161@nntp1.ba.best.com>
Nathan ZYLBERSZTEJN <zylou@altern.org> wrote:
> Hi,
> I'm trying to use setuid() in a script, but I have always the Insecure
> dependency error.
> I 've looked in the documentation and I found this but I don't
> understand:
> if ($data =~ /^([-\@\w.]+)$/) {
> $data = $1; # $data now untainted
> } else {
> die "Bad data in $data"; # log this somewhere
> }
> what is $1 ?
$1 is the special Perl variable that holds whatever matched inside the
first (leftmost) set of capturing parentheses in the previous regular
expression.
> what is $data ?
> what is the variable containing the string I want to untaint ?
$data is some variable containing the "tainted" data that is causing
your insecure dependency error.
Running your script setuid automatically puts Perl in taint mode, where
it gets very worried about any information coming into the script from
the outside world. Any data coming in from outside your script is
considered "tainted", or unclean. Any variable in any expression
containing a tainted variable becomes tainted itself. Perl keeps track
of all the variables that are tainted, and won't let you do certain
things with them.
The idea is that you probably want to make sure that a malicious user
who might be executing this script can't feed the script bad
information that will make it do bad things.
It's your job to make a regular expression that will let "good" data be
captured into $1 (or $2, $3, etc.), after which you can re-assign the
contents of $1 to the original variable, which is now considered by
Perl to be "un-tainted", or clean, and safe to use.
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: 28 Aug 1999 18:06:45 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: IRC CONNECT
Message-Id: <37C8243F.1F7F70D4@vpservices.com>
Webmaster wrote:
>
> Does anyone of you know a perl script or someway to connect to a irc server
> from perl???
Check CPAN for Net::IRC
--
Jeff
------------------------------
Date: 28 Aug 1999 17:53:06 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: Matching E-mail
Message-Id: <37c82202$0$216@nntp1.ba.best.com>
Webmaster <webmaster@compre-ya.com> wrote:
> if ($form{'email'} =~ /.+\@.+/)
> {
> ALL RIGHT!
> }
It should probably be pointed out that this expression will match the
value in $form{email} in any case where that value contains @ with at
least one character before it and one character after it. That may or
may not be what you want. As it turns out, writing a regular expression
to match "valid" (that is to say, deliverable) email addresses is
something that beginners tend to think should be pretty easy, but
which turns out to be considerably more complicated than that.
As others have already pointed out, albeit somewhat obliquely, you
should read what the FAQ has to say about this. Try entering
% perldoc -q address
at the shell/DOS prompt (if your perldoc is recent enough to support
the -q "search the FAQ headers" thingy), or browse perlfaq9 at:
http://www.perl.com/pub/doc/manual/html/pod/perlfaq9.html
and look for the section titled "How do I check a valid mail address?"
The gist of the FAQ entry is that there isn't any sure way to verify
that a string corresponds to a valid email address, other than to send
mail to it and see if anyone answers.
The expression given in the article I'm responding to will match most
valid addresses (except local addresses like 'postmaster', or 'jbc' for
users on a west.net server, both of which are perfectly deliverable
despite failing to match the pattern), but it will also match many,
many "false positives," including the following:
1@1
Meet you @ the park.
' @ '
and so on. You can make that expression considerably better at
excluding undeliverable addresses, but only at the risk of excluding an
increased number of valid ones. Since you're the only one who knows how
much you care about those issues, you're the only one who can answer
your question, and (if you choose to go that route) write an expression
that makes the appropriate tradeoffs.
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: 28 Aug 1999 12:06:26 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Removing <HTML> Tags
Message-Id: <slrn7sg5u4.tt.abigail@alexandra.delanet.com>
revjack (revjack@radix.net) wrote on MMCLXXXVIII September MCMXCIII in
<URL:news:7q92lu$54c$1@news1.Radix.Net>:
^^ Joe Kline explains it all:
^^
^^ :s!<[^>]+?>!!g;
^^ ^^
^^ I keep seeing '+?'
^^
^^ What does it mean? "One or more or zero"?
RTFM. It's documented.
^^ Wouldn't '*' work better?
For which definition of ``better''? It depends on what you want to do
with <>.
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 28 Aug 1999 19:16:25 GMT
From: revjack <revjack@radix.net>
Subject: Re: Removing <HTML> Tags
Message-Id: <7q9ci9$kpa$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight
Abigail explains it all:
:revjack (revjack@radix.net) wrote on MMCLXXXVIII September MCMXCIII in
:<URL:news:7q92lu$54c$1@news1.Radix.Net>:
:^^ Joe Kline explains it all:
:^^
:^^ :s!<[^>]+?>!!g;
:^^ ^^
:^^ I keep seeing '+?'
:^^
:^^ What does it mean? "One or more or zero"?
:RTFM. It's documented.
Thanks, I forgot about those.
:^^ Wouldn't '*' work better?
:For which definition of ``better''? It depends on what you want to do
:with <>.
Fringe cases are why I read this froup.
------------------------------
Date: Sat, 28 Aug 1999 10:41:41 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Removing a line from a text file
Message-Id: <MPG.1231bf3083d23984989ec4@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <7q9347$89l$1@panix3.panix.com> on 28 Aug 1999 12:35:19 -
0400, Greg Shalette <gshalet@panix.com> says...
> How does one remove a line of text from the middle of a text file
> in perl? Is rewriting the file without the line the only way
> or is their a function? Thanks.
That question is Frequently Asked here. So it has an answer in the FAQ,
which you might consider perusing.
perlfaq5: "How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the beginning of a
file?"
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 28 Aug 1999 18:05:31 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: Removing a line from a text file
Message-Id: <37c824eb$0$216@nntp1.ba.best.com>
Greg Shalette <gshalet@panix.com> wrote:
> How does one remove a line of text from the middle of a text file
> in perl? Is rewriting the file without the line the only way
> or is their a function? Thanks.
This is covered in the FAQ:
[jbc@buffy jbc]$ perldoc -q middle
=head1 Found in /usr/lib/perl5/5.00503/pod/perlfaq5.pod
=head2 How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the beginning of a
file?
You could also read perlfaq5 on the Web at:
http://www.perl.com/pub/doc/manual/html/pod/perlfaq5.html
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: Sat, 28 Aug 1999 14:39:27 -0400
From: "stevan apter" <apter@panix.com>
Subject: Re: sorting a delimited string by second field
Message-Id: <7q9a5g$i7i$1@news.panix.com>
again, why loop more than you have to? (see http://www.kx.com)
let's make an array of strings with a million rows:
m:($!1000000),'",",'1000000#$`one`two`three`four`five
so
m 0
"0,one"
m 1
"1,two"
m 999999
"999999,five"
in k, we get the second piece of a comma-delimited pair
by finding the comma and dropping it and what precedes it:
(1+m[0]?",")_ m 0
"one"
so functionalize this expression and apply it to each string
in m:
{(1+x?",")_ x}'m
symbols sort quicker than strings, so:
`${(1+x?",")_ x}'m
to get the indices of this in sorted order:
<`${(1+x?",")_ x}'m
using this to index m into sorted order:
n:m@<`${(1+x?",")_ x}'m
on my 450 mhz pentium II, the complete operation runs in a
little over five seconds:
\t n:m@<`${(1+x?",")_ x}'m
5067
4.5 of which is spent splitting the strings in m. in k, we would
strive to move the data into vector form as early as possible:
t.n:!1000000
t.f:1000000#`one`two`three`four`five
\t t[]:t[;<t.f]
300
ten million takes a little more than 10 times longer:
t.n:!10000000
t.f:10000000#`one`two`three`four`five
\t t[]:t[;<t.f]
5107
i hope people don't object to my posting competing solutions in this
forum (this is the third in the last few days). perl and k are similar
enough (and different enough) to make for some interesting comparisons.
i think we're a lot faster, but k has a narrower focus than perl (we
don't do primitive pattern matching). there is a version of k free
for downloading (~90k) at the site mentioned above.
Larry Rosler <lr@hpl.hp.com> wrote in message
news:MPG.1231ae9629d6ad2c989ec2@nntp.hpl.hp.com...
> In article <37C7D47A.DB780EBC@0011.com> on Sat, 28 Aug 1999 05:22:18 -
> 0700, Kin Lum <kin@0011.com> says...
> >
> > LinksNetwork Admin wrote:
> > > I have an array of delimited strings, which I would like to sort by
the
> > > second field.
> > > 17|Afghanistan
> > > 18|Albania
> > > My question is basically, how can I form an expression to return just
the
> > > second part of each record, to include in a sort{} operation?
> >
> > you can use something like this:
> > ($i,$name) = split(/\|/, "26|Australia");
> >
> > for making the sort call, use something like
> >
> > @sorted = sort byName @array;
> >
> > sub byName {
> > # split ... $a $b
> >
> > lc($nameA) cmp lc($nameB); # lc to make lower case
> > }
>
> If the list is short, or processing time is irrelevant, this naive
> approach is acceptable. But it repeats the same computation over and
> over every time two variables are compared. There are several ways to
> do the computation only once per variable and to store the results for
> further use in comparisons.
>
> See `perldoc -f sort`, perlfaq4: "How do I sort an array by (anything)",
> or the comprehensive paper at
> <URL:http://www.hpl.hp.com/personal/Larry_Rosler/sort/>.
>
> > the books Learning Perl and Programming Perl could
> > help you a lot:
> > http://www.0011.com/books/perl
> > getting books there will help support me
> > as a poor programmer.
>
> At least you are open about getting kickbacks if your links are used.
> But I wonder about the propriety of such a posting. Others haven't been
> as honest, and this trend is proliferating.
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
------------------------------
Date: 28 Aug 1999 14:27:22 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: sorting a delimited string by second field
Message-Id: <slrn7sge6c.tt.abigail@alexandra.delanet.com>
stevan apter (apter@panix.com) wrote on MMCLXXXVIII September MCMXCIII in
<URL:news:7q9a5g$i7i$1@news.panix.com>:
~~ again, why loop more than you have to? (see http://www.kx.com)
Please take your advocacy elsewhere. If you want k, you know where to
get it.
Abigail
--
There is no k in comp.perl.lang.misc
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sat, 28 Aug 1999 12:40:09 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: sorting a delimited string by second field
Message-Id: <MPG.1231daed6278d09b989ec6@nntp.hpl.hp.com>
In article <7q9a5g$i7i$1@news.panix.com> on Sat, 28 Aug 1999 14:39:27 -
0400, stevan apter <apter@panix.com> says...
<SNIP off-topic non-Perl stuff>
> i hope people don't object to my posting competing solutions in this
> forum (this is the third in the last few days). perl and k are similar
> enough (and different enough) to make for some interesting comparisons.
> i think we're a lot faster, but k has a narrower focus than perl (we
> don't do primitive pattern matching). there is a version of k free
> for downloading (~90k) at the site mentioned above.
I object a great deal. Would you like us all to see postings and
advocacy ads about Ada, Basic, COBOL, Fortran, Java, Lisp, Pascal, RPG,
Snobol, VB++, or God knows what? (Yes, I left a couple of hundred out.)
Please stop now!
> Larry Rosler <lr@hpl.hp.com> wrote in message
> news:MPG.1231ae9629d6ad2c989ec2@nntp.hpl.hp.com...
<SNIP of long complete posting not referred to in this response>
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 28 Aug 1999 18:45:07 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Style question: where should my declarations go?
Message-Id: <37c82e33$0$17161@nntp1.ba.best.com>
In declaring a my variable that needs to be declared at the outermost
scope of a script, but which will first be modified inside a while loop
or if block that occurs fairly far down the script, which is better: to
put it in a big, collective my declaration up at the top of the script,
or to declare it immediately before the loop or if block where it will
first be used? I realize that it will work the same either way; I'm
curious about the opinions of the old hands around here about the
clarity/maintainability implications of the different approaches.
The approach I've been using is to stick the declaration at the top,
but I wonder if it might make more sense to put it just before the
first use if it's only going to be used in that one area of the script.
I seem to recall seeing this discussed here recently, but I can't find
it now.
Thanks.
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: 28 Aug 1999 13:43:45 -0400
From: catfood@apk.net (Mark W. Schumann)
Subject: Re: The extent of double-quotish interpolation
Message-Id: <7q974h$ccq@junior.apk.net>
In article <m1k8qi78pe.fsf@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Lauren" == Lauren Smith <laurensmith@sprynet.com> writes:
>
>Lauren> I'm somewhat surprised that "$f->()" does not make the call to the sub,
>Lauren> but "$a[$f->()]" does.
>
>This is simple, when you remember the very simple rule:
>
> Perl doesn't interpolate expressions, just variables.
[examples snipped]
Gracious. I think I just understood that, and it perfectly explains my
recent disagreements with perl on this topic.
Thanks, Randal.
------------------------------
Date: 28 Aug 1999 12:40:13 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: The extent of double-quotish interpolation
Message-Id: <m1pv071yoy.fsf@halfdome.holdit.com>
>>>>> "Mark" == Mark W Schumann <catfood@apk.net> writes:
>> Perl doesn't interpolate expressions, just variables.
Mark> Gracious. I think I just understood that, and it perfectly explains my
Mark> recent disagreements with perl on this topic.
As long as you remember that this is one of those rules where "20%
covers 80%, and it would take another 80% to explain the other 20%".
But yes, in classrooms all across America, I've run into this problem
time and again, and the rule seems to awaken most people in a useful
way. Even if it's inaccurate on the corner cases :).
print "Just another Perl trainer,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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.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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu.
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 V9 Issue 669
*************************************