[6788] in Perl-Users-Digest
Perl-Users Digest, Issue: 413 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 2 10:07:17 1997
Date: Fri, 2 May 97 07:00:28 -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 Fri, 2 May 1997 Volume: 8 Number: 413
Today's topics:
Re: [DRAFT] RFD: comp.lang.perl.{data-structure,inter-p (Tad McClellan)
Re: [DRAFT] RFD: comp.lang.perl.{data-structure,inter-p (David Alan Black)
[Q]: l.f. suggestions for implementing lookahead <lpa@sysdeco.no>
Bug in goto? <minaret@sprynet.com>
Re: Call By Reference <seay@absyss.fr>
Re: getting and derefencing in one go (David Alan Black)
Re: Hexadecimal search and replace? <sarapata@pobox.com>
Re: How do I round things off? (Tad McClellan)
Re: Lisp is neither (was Re: Ousterhout and Tcl lost th (David Monniaux)
Re: Looking for more SPEED! (Tad McClellan)
Re: Looking for more SPEED! (Jon Bell)
moderation <seay@absyss.fr>
Re: Notice to antispammers <rsi@lucent.com>
Re: Perl auto-replier <seay@absyss.fr>
Re: Perl auto-replier <seay@absyss.fr>
Re: Perl auto-replier (Tad McClellan)
perl5 & gdbm on different platforms <wdell@ptc.com>
Re: program for perl? <merlyn@stonehenge.com>
Re: program for perl? (E.)
Re: Q on: map { @M=$_=~/(\S+)/g && [$_, $M[$col]] } @in (David Alan Black)
Re: Q: Cutting a string by position (like cut(1) can) (Tad McClellan)
Re: Q: Cutting a string by position (like cut(1) can) (Andrew M. Langmead)
Re: question: how to trim a string passed via hard refe (Andrew M. Langmead)
Re: Remove HTML tags from docs???? (Bob Wilkinson)
Re: Replacing + (Jordyn A. Buchanan)
Re: request for help (Bob Wilkinson)
Re: variable substitution (Honza Pazdziora)
Re: What is the best way of learning Perl? (Jon Bell)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 2 May 1997 05:42:33 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: [DRAFT] RFD: comp.lang.perl.{data-structure,inter-process,programmer,regex}
Message-Id: <pegck5.gh.ln@localhost>
David Alan Black (dblack@icarus.shu.edu) wrote:
: I-hate-cyber-promo@man.ac.uk (A. Deckers) writes:
: >+ that is deemed to contain text encoded using HTML or similar
: > schemes;
: While I completely share the general alarm at the flood of
: irrelevant HTML/CGI questions in clpm, I would question whether
: it is indeed *impossible* for a worthwhile question about
: Perl data structures to contain fragments of HTML. If the
: question is basically sound, but some sample code/data happens
: to involve HTML, I don't think the poster should be excluded.
I think the provision is not meant to exclude HTML as _contents_
but to exclude HTML encoding of the entire post itself (eg.
posting from a misconfigured Netscrape).
Right?
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 2 May 1997 13:23:47 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: [DRAFT] RFD: comp.lang.perl.{data-structure,inter-process,programmer,regex}
Message-Id: <5kcpt3$eqt@pirate.shu.edu>
Hello -
tadmc@flash.net (Tad McClellan) writes:
>David Alan Black (dblack@icarus.shu.edu) wrote:
>: I-hate-cyber-promo@man.ac.uk (A. Deckers) writes:
>: >+ that is deemed to contain text encoded using HTML or similar
>: > schemes;
>: While I completely share the general alarm at the flood of
>: irrelevant HTML/CGI questions in clpm, I would question whether
>: it is indeed *impossible* for a worthwhile question about
>: Perl data structures to contain fragments of HTML. If the
>: question is basically sound, but some sample code/data happens
>: to involve HTML, I don't think the poster should be excluded.
>I think the provision is not meant to exclude HTML as _contents_
>but to exclude HTML encoding of the entire post itself (eg.
>posting from a misconfigured Netscrape).
>Right?
That sounds right - I was envisioning it being done automatically,
based on a scan of the text, and therefore possibly prone
to over-doing. Which probably makes no sense anyway....
David Black
dblack@icarus.shu.edu
------------------------------
Date: Fri, 02 May 1997 15:38:09 +0200
From: Luca Passani <lpa@sysdeco.no>
Subject: [Q]: l.f. suggestions for implementing lookahead
Message-Id: <3369EE41.6851@sysdeco.no>
Hallo,
I'm parsing a file and it would be useful to have some kind of lookahead
which allows me to take actions before I start the loop again.
open(FILE, "file.txt") || die;
while(<FILE>)
if (/regexp/) {
if (NEXTLINE matches /regexp2/) {
action1;
} else {
action2;
}
}
}
Of course I could save some status information and decide which action
to take afterwards, but the lookahead would let me have a much more
elegant solution. One solution I've been thinking of is slurping
the whole file into an array in advance in order to do things like:
if ($arraywithfile[$currentline+1] =~ /regexp2/)
but maybe someone has a good reason not to.
thanx for your suggestions
Luca
--
======================================================================
Luca Passani. | Sysdeco Innovation AS, http://www.sysdeco.no
Email: lpa@sysdeco.no | Trondheimsveien 184, 0570 Oslo, Norway
Tel: (+47) 22 09 66 06 | Fax: (+47) 22 09 65 03
======================================================================
------------------------------
Date: 2 May 1997 13:11:40 GMT
From: "Geoff Mottram" <minaret@sprynet.com>
Subject: Bug in goto?
Message-Id: <01bc56fa$307c5a80$61bfaec7@cactus>
Is there a known bug in Perl 5.003 with regards goto statements and
contexts?
I have a situation where a goto inside a while loop that is in a subroutine
is jumping into the body of an if statement. When that subroutine returns,
the Perl_pp_leavesub function is freeing one of the subroutines that was
called within the while loop.
It looks like the goto is messing up Perl's contexts and causing the
reference count for the subroutine that was called in the while loop to go
to zero, causing the subroutine to be freed. The program eventually causes
a segmentation violation when the freed subroutine is called again.
I'm hoping someone out there will say "Oh yeah, that's the old goto context
bug" and also tell me it's been fixed or at least that someone is aware of
it.
Geoff Mottram
minaret@sprynet.com
------------------------------
Date: Fri, 02 May 1997 14:06:56 +0100
From: Douglas Seay <seay@absyss.fr>
To: Tran Phan Anh <anh@gte.net>
Subject: Re: Call By Reference
Message-Id: <3369E6F0.6F665D26@absyss.fr>
[posted and mailed
Tran Phan Anh wrote:
>
> Hello,
>
> I need to pass a file handle to a subroutine, magic, which uses the
> filehandle to read some data.
>
> Magic is going to be called in a loop, and I would like that magic
> modifies the original filehandle, so that everytime magic is called, it
> will process the file from where it left off.
>
> I tried the glob thing but it does not seem to work, and I don't want
> to
> use global variables.
How about using the FileHandle.pm module to open and manipulate files?
Instead of a global variable, or even a reference to a GLOB, you have an
object that does file manipulation. Just pass this object to your
subroutine. As the object stays around between calls, you never reset
the file pointer. If you want to stick with GLOBs, could you use tell()
and seek() to go back to where you had been earlier?
------------------------------
Date: 2 May 1997 11:37:16 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: getting and derefencing in one go
Message-Id: <5kcjlc$726@pirate.shu.edu>
Hello -
junkmail@sysa.abdn.ac.uk (Kyzer) writes:
>Hello, I like to pass in hashes (I will be caught one of these days)
>#!/local/bin/perl -w
># this is an example, guv
>use strict qw(subs vars refs); my %mates;
>$mates{'james'}='clever'; $mates{'kevin'}='stupid';
>print &myfunc("Hello", \%mates) || "bugger all\n";
>sub myfunc {
> return unless my $name = shift @_;
> return unless my $hashref = shift @_; # statement 1, get in ref arg
> my %hashes = %$hashref; # statement 2, convert ref to var
> $name, ', I am kevin and I am ',%hashes{'kevin'},"\n";
>}
>Now, what I would like to know is:
>Can I get arg2 in and dereferenced into %hashes with 1 statement,
>rather than 2?
>I was thinking 'my %hashes = %${shift @_};' but this nets me
>a 'not a SCALAR reference'. I'm missing something here, and I haven't spotted
>it in the FAQ or perlref manpage.
The version you've given fails syntactically because of %hashes{'kevin'},
which should be $hashes{'kevin'}. It also fails logically because all you're
returning is "\n". If you want to return the whole string, put it
all in double quotes or use the '.' concatenation operator.
In any case, you can use @_ itself:
sub myfunc {
return $_[0] && $_[1] &&
"$_[0], I am kevin and I am $_[1]->{'kevin'}\n";
}
(Did you really mean $name to be "Hello"? Well, you can tinker
with that :-)
David Black
dblack@icarus.shu.edu
------------------------------
Date: Fri, 02 May 1997 09:21:17 -0400
From: Steve Sarapata <sarapata@pobox.com>
Subject: Re: Hexadecimal search and replace?
Message-Id: <3369EA4D.54C0@pobox.com>
Timothy Lindgren wrote:
>
> Greetings!
>
> I have a large number of ascii text files that have a badly formed "new line"
> character. The only way I have found to see the bad character is with a hex
> editor.
>
> The format for new line (Carrage Return) in HEX is " 0D0A ".
>
> Can anyone help describe a routine that will open a file from command line,
> then search for the bad hex value ( "0D0D0A" ) and replace it with the HEX
> value of " 0D0A "?
>
> Is there a command/function in SED that would find these and replace them with
> a standard new-line (" \n ")?
>
> Anyone?
> Tim
Try 'dos2unix'.
------------------------------
Date: Fri, 2 May 1997 06:21:18 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How do I round things off?
Message-Id: <enick5.3o.ln@localhost>
Tom Kruk (tomkruk@perfekt.net) wrote:
: Have
: you ever had this problem?
I would expect that, just maybe, this Question is Asked Frequently.
So Frequently, in fact, that it might be answered in the Perl FAQ.
grep round faq.* | wc -l
26
26 lines isn't too bad. Could probably scan them in 20 seconds or so.
But maybe we could make it even easier.
grep ' round' faq.*
faq.4:=head2 Does perl have a round function? What about ceil() and floor()? Trig functions?
faq.4:For rounding to a certain number of digits, sprintf() or printf() is
faq.4:the rounding method used should be specified precisely. In these
faq.4:cases, it probably pays not to trust whichever system rounding is
faq.4:being used by Perl, but to instead implement the rounding function you
That sure does make it look like someone has indeed "had this problem"...
Want to get the answer to your questions in a few seconds (as well
as follow Usenet etiquette) and not annoy the people who might
answer it?
Consult the man pages and FAQ before posting!
: You are doing some kind of math procedure in perl and you are
: multiplying decimals like (tax) .0825 and the result is an answer
: with as many decimals. I was wondering if someone could help
^^^^^^^
Or even more decimal places. Or even less decimal places.
: me or point me in the right direction,
: If I get something like 80.0456 how do I round it to 80.05 or how do I cut
: off the 56
: to get 80.04 ???
: If anyone could answer I would greatly appreciate it!!
If anyone could check the FAQs before posting, the entire c.l.p.m
community would appreciate it!!
: Thanks
Uh huh.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 2 May 1997 10:57:08 GMT
From: dmonniau@ens-lyon.fr (David Monniaux)
Subject: Re: Lisp is neither (was Re: Ousterhout and Tcl lost the plot)
Message-Id: <5kcha4$i2c@cri.ens-lyon.fr>
Donal K. Fellows (fellowsd.cs@man.ac.uk) wrote:
: > the SPARC architecture has several instructions that C compilers doesn't
: > use, but which are convenient with type-tagged languages. the _fact_ is
: > that it has an the instruction, with Sun's recommended mnemonic "taddcctv",
: > that is specifically useful in Lisp, and specifically unused in C. other
: > instructions are also measurably useful in languages _other_ than C.
:
: What does the instruction do? I've not got a SPARC manual to hand and
: I'm quite sure that there are other people reading this thread who are
: also unaware of the meaning of that instruction.
The Sparc architecture has support for a "tagged integer" data type.
The two low-weight bits of a tagged word contain a tag, the other bits contain
a 30-bit integer. The two provided operations (add and substract) work as
one would expect on words with tag=0. With other values, they generate an
overflow error. taddcctv (resp. tsubcctv) adds (resp. subtracts) two tagged
words, sets the condition codes (cc) and traps on overflow; alternatively,
one may use taddcc/tsubcc, which do not trap.
This is meant for use with dynamically typed languages. Integers are tagged 0,
and the most commonly used operations (add/sub) on them work transparently.
Pointers are tagged with 1, 2 or 3. If a pointer is mistakenly used as an
integer, it generates an error (and maybe a trap). To compensate for the tag,
data is accessed with relative offsets -1, -2 or -3 respectively from a
tagged pointer. As words are 4-byte aligned, addressing data with the wrong
offset generates a bus error. That is, data with one tag used mistakenly
as if it were to bear another tag make the processor trap.
(all this taken from "The Sparc architecture manual, version 8").
The tags may be used by the garbage collection process to see what words
contain integers and what words contain pointers. I do not have examples
of implementations using the Sparc tagged arithmetic, but the only garbage
collecting implementation I know quite well, Objective CAML, tags data
using the lowest weight bit.
Hope this helps.
-- David
PS: Sorry, but the overall aggressive tone of the discussions around
("You aren't competent on that topic! - Yes, I am, it's you who don't
know anything about what is talked of!") disturb me.
We should spend more time actually working on improving computer languages,
tools and libraries, and less arguing about, as Xavier Leroy said,
whether angels are male or female. :-)
PS2: I've trimmed the followup-to. If we are to discuss generally upon the
use of processor features for garbage collection and sanity checks in
garbage-collected language, I think we can restrict ourselves to
comp.lang.functional...
--
"If computers worked, it'd be known."
Computer science student at ENS, Lyon, France
http://www.ens-lyon.fr/~dmonniau
------------------------------
Date: Fri, 2 May 1997 06:24:13 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Looking for more SPEED!
Message-Id: <tsick5.3o.ln@localhost>
Nik Trivedi (ntrivedi@shrike.depaul.edu) wrote:
: Hello fellow programmers,
: I was looking for a way to speed up some of my perl scripts, so I just
: had a few questions. What is faster, a for loop or a while loop? A
^^^^^^^^^^^^^^
use the Benchmark module to test the alternatives on your real
data and see...
: switch or a series of else-if statements? Any help is greatly
: appreciated!
My understanding is that, in perl, a switch is *infinitly* slower
than a series of else-if statements...
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Fri, 2 May 1997 12:42:32 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Looking for more SPEED!
Message-Id: <E9K0Mw.B30@presby.edu>
Nik Trivedi <ntrivedi@shrike.depaul.edu> wrote:
>Hello fellow programmers,
>
>I was looking for a way to speed up some of my perl scripts, so I just
>had a few questions. What is faster, a for loop or a while loop? A
>switch or a series of else-if statements?
Perl has a switch statement? That's the first I've heard of it!
--
Jon Bell <jtbell@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
[for beginner's Usenet info, see http://web.presby.edu/~jtbell/usenet/ ]
------------------------------
Date: Fri, 02 May 1997 14:58:09 +0100
From: Douglas Seay <seay@absyss.fr>
Subject: moderation
Message-Id: <3369F2F0.6F6FE99A@absyss.fr>
Moderation seems to be the buzz word of the day. I can't say I like it,
but it might be better than the insanity of today. I know squat about
Usenet moderation rules, but everything I've seen has been human
moderated. I'm not sure how well that would work here. Maybe there is
too much stuff, moderation would be a full time job, or would need to be
distributed amoung several people like with alt.humor.best-of-usenet.
Would it be possible to build an auto-moderating robot that looks at the
sender's address and if the sender is on the "approved" list, allow the
post, otherwise send a copy of the FAQ and forward the post to the human
moderator(s). The human(s) could then accept or reject the post
depending upon content, complexity, phase of the moon, personal whim,
whatever. As for this "approved" list, it isn't be in our best
interests to keep this a closed, good-ol-boy network, so this list
should be fairly open. If someone has been approved for posting by the
human moderator(s) 3 times, they are on the list. Maybe also build some
sort of Perl test, and if someone can score well enough (knows the
basics), then let them on the list.
Note that I'm not offering to be a moderator nor to write this robot
approval system. I'm just shooting the breeze. But I would like to
know what the rest of you think. As I've never seen the creation of a
moderated group, I don't know what problems await.
Oh yea, I think this moderated group should be in addition to a
open-to-anybody group. Cutting people off from any Usenet source of
help would be counter productive.
- doug
------------------------------
Date: 02 May 1997 08:48:32 -0400
From: Rajappa Iyer <rsi@lucent.com>
Subject: Re: Notice to antispammers
Message-Id: <xny207qf3a7.fsf@placebo.hr.lucent.com>
fl_aggie@hotmail.com (I R A Aggie) writes:
> + > It's no more or less ethical than publishing the "Anarchist Cookbook",
> + > or selling nitrogen-based fertilizer. How many technological advances
> + > has Lucent developed that can be abused? should Lucent be held responsible
> + > for them?
>
> + This is a silly analogy. The primary purpose of the technological
> + advances in Lucent was not so it could be abused.
>
> Ah, but what *safeguards* have you placed within your technology to
> prevent abuse? If you haven't put them in, you're encouraging abusive
> use of technology.
Read what Tom wrote again... he intends for spambots to get the
addresses easily. There's a difference between creating something with
unintended bad consequences and creating something with intended bad
consequences.
--
Rajappa Iyer <rsi@lucent.com> #include <std_disclaimer.h>
They also surf who only stand on the waves.
------------------------------
Date: Fri, 02 May 1997 14:16:56 +0100
From: Douglas Seay <seay@absyss.fr>
Subject: Re: Perl auto-replier
Message-Id: <3369E948.498CED6D@absyss.fr>
Randal Schwartz wrote:
>
> Well, for what it's worth, *I'm* still here, but I count on others to
> send away the CGI questions so that I don't have to get riled up.
Glad to read it. I was afraid that you were thinking about jumping ship
too. Not that there aren't several other excellent sources who post on
this group, but you, Larry and Tom have a special status.
- doug
------------------------------
Date: Fri, 02 May 1997 14:30:01 +0100
From: Douglas Seay <seay@absyss.fr>
Subject: Re: Perl auto-replier
Message-Id: <3369EC59.34E18A7F@absyss.fr>
Chipmunk wrote:
> (And while I'm being self-righteous, why do some people have a bug up
> their ass about people who request e-mail replies?)
I guess I'm on the "bug up their ass" list because I don't like it.
comp.lang.perl.misc is mostly just a question and answer session, I
don't see the advantage of turning it into a questions only session.
When I post I hope that there are several people who'll read it
(directly or later via deja news). Maybe I can help several people at
once. If I reply via email, what I write isn't public, so if I make a
mistake, there is less of a chance for someone to correct me. Tom
Christiansen has corrected/commented upon my posts several times, for
which I'm greatful. This helps me learn more about the subtle points of
Perl and it adds to the sense of community where we all help each
other. This is a good thing.
But the thing that really sets me off when someone posts "send me email
because I don't read this group". These people are not adding anything
to the "community" but thay want to profit from it. It is a simple case
of wanting the fruits without the labor. And many of these questions
are in some FAQ, a man page, the Camel, whatever. Although I am lazy
and arrogant, I'm not _that_ bad. Sheesh.
- doug
------------------------------
Date: Fri, 2 May 1997 07:04:35 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Perl auto-replier
Message-Id: <j8lck5.cu.ln@localhost>
Douglas Seay (seay@absyss.fr) wrote:
: Chipmunk wrote:
: > (And while I'm being self-righteous, why do some people have a bug up
: > their ass about people who request e-mail replies?)
: I guess I'm on the "bug up their ass" list because I don't like it.
: comp.lang.perl.misc is mostly just a question and answer session, I
: don't see the advantage of turning it into a questions only session.
: When I post I hope that there are several people who'll read it
: (directly or later via deja news). Maybe I can help several people at
: once. If I reply via email, what I write isn't public, so if I make a
: mistake, there is less of a chance for someone to correct me. Tom
: Christiansen has corrected/commented upon my posts several times, for
: which I'm greatful. This helps me learn more about the subtle points of
: Perl and it adds to the sense of community where we all help each
: other. This is a good thing.
That's pretty much exactly my opinion too.
The ONLY acceptable way to request email responses, that doesn't
invoke the "next article" key, is to state that you will (and
follow through) post a summary of responses back to the newsgroup.
: But the thing that really sets me off when someone posts "send me email
: because I don't read this group". These people are not adding anything
^^^^^^^^^^^^^^^^^^^^^^^
This (IMO anyway) is the "suicide sin" of Usenet. That is, there is
no forgiveness for this particular transgression.
I do my level best to killfile Subjects rather than individuals,
but this statement leads to an immediate and permanent killfile entry.
: to the "community" but thay want to profit from it. It is a simple case
: of wanting the fruits without the labor. And many of these questions
: are in some FAQ, a man page, the Camel, whatever. Although I am lazy
: and arrogant, I'm not _that_ bad. Sheesh.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Fri, 02 May 1997 09:33:03 -0400
From: Bill Dell <wdell@ptc.com>
Subject: perl5 & gdbm on different platforms
Message-Id: <3369ED0F.41C6@ptc.com>
Hi all
I've run into a problem with a current project i'm working on and
i'm unclear as to why it isn't working as it should.
I have perl5 compiled over IRIX 6.2 and OSF/1 4.0 linked with
gdbm. When I create a tied hash DB (with GDBM_File) on irix, I can't
access this same data on the OSF/alpha. Shouldn't the DB be readable
at least regardless of platform? Or is this not at all a possibility?
using:
Perl 5.003
gdbm-1.7.3
Thanks in advance
------------------------------
Date: 02 May 1997 06:27:13 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: suzanne@intrepid.axess.com (Suzanne L.)
Subject: Re: program for perl?
Message-Id: <8cu3kmuhqm.fsf@gadget.cscaper.com>
>>>>> "Suzanne" == Suzanne L <suzanne@intrepid.axess.com> writes:
Suzanne> Is there a program that is needed to write in perl or can they be
Suzanne> written in any text editor?
Any text editor will do. My favorite is:
$ cat >myscript
#!/usr/bin/perl
... [rest of script]
...
^D
$ chmod +x myscript
$ ./myscript
[runs perfectly]
$
:-)
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 487 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
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@ora.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: 2 May 1997 06:39:00 -0700
From: erisson@kallisti.sw-tech.com (E.)
Subject: Re: program for perl?
Message-Id: <slrn5mjriu.nrf.erisson@kallisti.sw-tech.com>
Randal Schwartz <merlyn@stonehenge.com> wrote:
> >>>>> "Suzanne" == Suzanne L <suzanne@intrepid.axess.com> writes:
>
> Suzanne> Is there a program that is needed to write in perl or can they be
> Suzanne> written in any text editor?
>
> Any text editor will do. My favorite is:
>
> $ cat >myscript
> ...
> [runs perfectly]
Showoff. :P
-E (who wants to be JAPH when he grows up)
--
PGP Public Key Fingerprint: BE FC C5 FB 30 47 E5 5C DC DF C3 C0 AD A5 27 17
Homepage: http://www.primenet.com/~fnargle/erisson/ PGP Key available here
"If your VCR is blinking 12:00, you don't want to use Linux." -Bruce Perens
"Every day is like burning paper." -Slimebard
------------------------------
Date: 2 May 1997 10:47:16 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: Q on: map { @M=$_=~/(\S+)/g && [$_, $M[$col]] } @in;
Message-Id: <5kcgnk$4p5@pirate.shu.edu>
Hello -
Jong <jong@mrc-lmb.cam.ac.uk> writes:
>Hi,
>I am making a subroutine which uses map to sort
>things in any column given.
>The map function part above does not seem to produce
>array and put it to next level
>&& [$_, $M[$col]]
>The whole line is:
>$col=2;
>@out= map {$_->[0]} sort { $a->[1] <=> $b->[1] } map {@M=$_=~/(\S+)/g &&
>[$_, $M[$col]] } @in;
Change the && to a semicolon:
@out= map {$_->[0]} sort { $a->[1] <=> $b->[1] } map {@M=$_=~/(\S+)/g;
[$_, $M[$col]] } @in;
You could also do this:
@out= map {$_->[0]} sort { $a->[1] <=> $b->[1] }
map { [$_, ($_=~/(\S+)/g)[$col]] } @in;
Note that while your regex is looking for \S's, your sort routine is
expecting numbers. If there are non-number characters involved, you
might want to be sorting with cmp rather than <=>.
David Black
dblack@icarus.shu.edu
------------------------------
Date: Fri, 2 May 1997 05:47:16 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Q: Cutting a string by position (like cut(1) can)
Message-Id: <kngck5.gh.ln@localhost>
brian d foy (comdog@computerdog.com) wrote:
: In article <01bc5691$feba4c40$011618cb@caesar.bit.net.au>, "Andrew
: Pollock" <apollock@bit.net.au> wrote:
: > How do you dissect a string based on column? (Like the way cut(1) works?)
: > I know all about splitting on whitespace, but I've got a string where
: > tokens don't always appear, and splitting on whitespace is impractical.
: see substr() in the perlfunc man page. you might want to scan through
: the man page a couple of times to get an idea of what functions are
: available. :)
Or, just get a list of function names from the perlfunc man page:
perl -ne 'print if /^=item/' perlfunc.pod >perlfuncs
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Fri, 2 May 1997 13:15:50 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Q: Cutting a string by position (like cut(1) can)
Message-Id: <E9K26E.3pJ@world.std.com>
"Andrew Pollock" <apollock@bit.net.au> writes:
>How do you dissect a string based on column? (Like the way cut(1) works?)
>I know all about splitting on whitespace, but I've got a string where
>tokens don't always appear, and splitting on whitespace is impractical.
I don't understand, Andrew. A few days ago, you post asking how to use
"unpack", which is the precise answer to your problem. Now you are
asking how grab a certain fixed column of text, to which the most
common answers will be "unpack" or "substr".
The shell command:
cut -c5,12 file
Turns into the perl:
open FILE, 'file' or die "Can't open file: $!\n";
while(<FILE>) {
print unpack 'x5a7', $_;
}
--
Andrew Langmead
------------------------------
Date: Fri, 2 May 1997 12:52:49 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: question: how to trim a string passed via hard reference?
Message-Id: <E9K141.8t0@world.std.com>
zeadeATstanford.edu <spammers_suck@[127.0.0.1]> writes:
>I have been wondering for awhile if something like @array[1] was ever
>illegal in perl.
Its not illegal syntax, but is doing something other than what you
think it is. (What is that "Princess Bride" quote that Randal always
uses?)
It is a one element slice of the array "@array". Very often people
don't notice the problem because it can be masked very well.
#grab one elements from @array. Assign the last one to $scalar
$scalar = @array[1];
#pass one elements from @array to the subroutine.
some_sub(@array[1]);
But if fails when perl is particular about scalar/array context.
# store the broken down time and store the seconds in the one array
# elements specified.
@array[1] = localtime;
The singular/plural mismatches in the comments are intentional. It is
a rough English equivilent of the problem. When say @array you are
always saying "these elements" when often you want to say "this
element".
If you were using slices of more than one element, it is obvious that
you mean a list.
# grab the second and fourth elements out of @array. Store the fourth in
# $scalar.
$scalar = @array[1,3];
# pass elements 5 and 7 to the subroutine.
sub_sub(@array[5,7]);
# get month, day, year, hour, minutes, seconds from localtime
@array[5,4,3,1,0,2] = localtime
(OK, they are silly examples. Everyone would write "$scalar = @array[3]"
and most people would write "@array = (localtime)[4,3,5,2,1,0]". I
hope they illustrate the point, though.)
--
Andrew Langmead
------------------------------
Date: Fri, 02 May 1997 14:41:02 +0100
From: b.wilkinson@pindar.co.uk (Bob Wilkinson)
Subject: Re: Remove HTML tags from docs????
Message-Id: <b.wilkinson-0205971441020001@ip57-york.pindar.co.uk>
In article <33669651.1028679@news.hooked.net>, steve@gamespot.com (Steven
Young) wrote:
> It sure would be nice if someone could post a script that removes IMG
> and TABLE tags from HTML docs.
And what have you tried to accomplish this task?
Bob
--
I have become death, destroyer of the worlds.
------------------------------
Date: Fri, 02 May 1997 09:13:42 -0400
From: jordyn@bestweb.net (Jordyn A. Buchanan)
Subject: Re: Replacing +
Message-Id: <jordyn-ya02408000R0205970913420001@nntp.bestweb.net>
"John D. Hamel" <john@RevereMa.com> wrote:
> I'm trying to write me first perl program and can't get this line to work:
>
> $value=~s/+/ /g;
>
> I'm trying to transfer the data from the form to the perl script.
> This line should get rid of the + signs.
Remember that the "+" symbol has a special meaning in regular expressions.
You need to use the "\" to let perl know that you mean the literal symbol
"+" rather than the special meaning of the symbol, which is "match the
previous character one or more times".
Try this instead:
$value =~ s/\+/ /g;
> Please let me know what is wrong. Also, please suggest
> another way of getting the data from the form.
> I can't get the -->param( ) stuff to work either!
The param() syntax should work fine, but you need to make sure that you are
using the CGI.pm module. Also, the correct syntax is ->param(), not
-->param().
The CGI.pm documentation is very good--look carefully at the examples and
all will become clear. It's possible CGI.pm is not installed on your
system, though, in which case you may need to download it.
Jordyn
|---------------------------------------------------------------|
|Jordyn A. Buchanan jordyn@bestweb.net|
|Bestweb Corporation http://www.bestweb.net|
|Senior System Administrator +1.914.271.4500|
|---------------------------------------------------------------|
------------------------------
Date: Fri, 02 May 1997 14:38:45 +0100
From: b.wilkinson@pindar.co.uk (Bob Wilkinson)
Subject: Re: request for help
Message-Id: <b.wilkinson-0205971438450001@ip57-york.pindar.co.uk>
In article <3368ACDF.23C9@cs.wayne.edu>, mallela reddy <rkm@cs.wayne.edu> wrote:
> Respected Sir/Madam,
>
> I am a student of Wayne State university
> presently working on a perl project(grad course) namely
> "pizza online delivery"(address is
> www.cs.wayne.edu/~rkm). In the project I have given a
> variable $discount (which is 95% or 90% or 75%
> depending upon the total amount you order)of the total
> dollars. In this calculation some times it is giving
> for example as $45.5625 or some times as $45 if I tried
> to give a chop to the $discount twice it is truncating
> but in this process i am loosing $1 or it is giving $45
> as above. please suggest me how to tackle the problem.
> I need something which might convert the variable
> $discount in to a standard datatype in the form of
> money i.e, $00.00(two digits to the right of decimal
> pointer. Please mail the suggestion to rkm@cs.wayne.edu
>
> Thanking you Sir,
> Sincerely,
> MALLELA REDDY
> --
Hello
sprintf (or printf) - see perlfunc or any book about Perl.
Bob
--
I have become death, destroyer of the worlds.
------------------------------
Date: Fri, 2 May 1997 12:12:27 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: variable substitution
Message-Id: <adelton.862575147@aisa.fi.muni.cz>
Bob Lockie <bjlockie@nortel.ca> writes:
> I have 2 variables,
> one named $type and one named $index.
>
> I want to do the following inside a print statement.
>
> print "$type_ac$index\n";
>
> but Perl treats "$type_ac" as a variable name.
>
> I tried "$type\_ac" with no luck.
>
> I want to do this INSIDE :-) a print statement. :-)
>
> Is there a way to force Perl to take the variable name that
print "${type}_ac$index\n";
Hope this helps.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: Fri, 2 May 1997 12:37:19 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: What is the best way of learning Perl?
Message-Id: <E9K0E7.Avo@presby.edu>
Philippe Benichou <benichop@reality.cse.fau.edu> wrote:
>What is the best way for learning Perl? Looking at other people's scripts
>is too confusing, and the O'Rielly book doesn't explain things well.
Which O'Reilly book? "Programming Perl" (the Camel book) isn't supposed
to be a tutorial. "Learning Perl" (the Llama book) *is* supposed to be
an introductory-type book, although it's still probably not a good choice
for people who know nothing about programming at all to begin with.
--
Jon Bell <jtbell@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
[for beginner's Usenet info, see http://web.presby.edu/~jtbell/usenet/ ]
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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". 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 413
*************************************