[7123] in Perl-Users-Digest
Perl-Users Digest, Issue: 748 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 20 10:07:18 1997
Date: Sun, 20 Jul 97 07:00:24 -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 Sun, 20 Jul 1997 Volume: 8 Number: 748
Today's topics:
How to s/TARGET_TEXT/&Subroutine;/gi; (Clay Shirky)
if ($var =~ '\\' ) { ... } <hate@spam.com>
Re: Inserting/deleting scalars into arrays? (Even Holen)
Re: Multiple Line Pattern Matching (Tad McClellan)
Re: Perl Compilers or convert to byte code <rootbeer@teleport.com>
Re: References and Objects (Jeff Stampes)
Simultaenous access of DBM files (Matthew P. Gordon)
Re: Source multiple line perl file <rootbeer@teleport.com>
Re: Testing shift for true or false (Clay Shirky)
Re: What happens when.... (Nathan V. Patwardhan)
Re: why am I trashing binary files with this? (Tad McClellan)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Jul 1997 20:41:24 -0400
From: clays@panix.com (Clay Shirky)
Subject: How to s/TARGET_TEXT/&Subroutine;/gi;
Message-Id: <5qrmrk$ira@panix2.panix.com>
I am running a search-and-replace function on an HTML file like so:
for (@File) {
if (/(TARGET_TEXT)/i) {
&sub_to_generate_unique_variable;
s/$1/$unique_variable/g;
}
}
This leaves me the non-HTML-ish assumption that subsequent occurences
of TARGET_TEXT are separated by at least one \n.
I would much rather do something like
$unique_variable = sub { BLOCK };
s/TARGET_TEXT/$unique_variable/gi;
if I could get each replacement, even with two on a single line, to
re-evaluate $unique_variable.
Alternatively, I could also
s/TARGET_TEXT/&sub_to_generate_unique_variable;/gi;
if the sub routine returns the value of the unique variable into the
replacement position, but I cannot get either of these methods to work.
TIA,
--
Clay Shirky
------------------------------
Date: 18 Jul 1997 21:38:52 GMT
From: "No Spam!" <hate@spam.com>
Subject: if ($var =~ '\\' ) { ... }
Message-Id: <01bc93c3$0bdb2bb0$221f7da3@gromit>
Don't laugh! Ok, you can laugh but just not too hard.
I'm trying to examine a $variable and see if it contains the \ character.
First I tried
if ($var =~ "\\") { ... }
and then
if ($var =~ '\\') { ... }
So I gave up on that and tried to check for the | too. Aaaagh! Same
results.
Then I tried all sorts of other dopey stuff that didn't work and finally
ended up posting here.
I have the Blue Camel book (thanks Larry, Tom and Randall!) and I suppose I
really need to get the Llama book too. Is there a blue one on the horizon
as my local B&N only seem to have the pink one.
Thanks. And if it is in the blue Camel book, can you point me to the right
page number? I'm sure I'm just missing something elementary.
Finally, how long does it take to get 'good' with Perl? I've been at it for
a few weeks and I feel like I'm just flailing around and not really getting
it. Is there a point where you just click or do you limp back to VB or
something?! Any other books I should read?
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I haven't posted my email address as I'm sick of mailbox clogging MAKE
MONEY FAST crap or "exotic" babes 4 you pseudo porn. I haven't posted to
USENET in months and the bloody stuff still flows in to my mailbox
up to 20 emails a day! So if you have a reply, please post it here.
I'm very sorry for any inconvenience but what else can I do?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 20 Jul 1997 01:05:30 GMT
From: evenh@ra.pvv.ntnu.no (Even Holen)
Subject: Re: Inserting/deleting scalars into arrays?
Message-Id: <slrn5t2p2q.2ue.evenh@ra.pvv.ntnu.no>
In article <m2afji1vff.fsf@azura.hks.se>, Christer Enfors wrote:
>I don't know very much about Perl (yet), but I'm thinking about making
>an ed/sed-like editor in Perl. So should I use an array to hold the
>file being edited (it'll be mostly small files), which each line in
>the file being a scalar in the array? And if so, is there an easy way
>to insert / delete scalars (lines) into/from an array?
It's kind of a though first time project... But I would suggest using a
continuous stream of characters. If you use a stream of characters it's
much easier to write fancy stuff to manipulate the stream across line
boundaries which otherwise may give you a lot of problem.
But to answer your question: Yes, you might insert/delete thingies from
an array. Look up splice for starters...
>On a different note, I've read some short tutorials on perl, but they
>weren't very extensive. And the man pages are more of a reference
>manual, and therefore hard to learn from for a newbie. So, could
>anyone direct me to a fairly extensive perl tutorial / doc / whatever,
>from which I can learn a bit more? I have a lot of programming
>experience in other languages, so I don't usually have a problem with
>these things. *cough cough*
The book most people like to refer to, with good reason, is the
"Programming Perl" book. This is a good book, and is all you need.
It is maybe a bit to concise if you were a newbie to programming, but
you deny being a newbie to programming in general...
Try this book, and be sure to get the 2nd edition.
(For those who might want a somewhat leaner start try "Learning Perl")
Both books are published by O'Reilly and are often referred to as the
llama and the camel due to the pictures on the cover.
Hope this helps!
Regards,
Even Holen
--
<>< Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/ :-)
------------------------------
Date: Sat, 19 Jul 1997 18:20:38 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Multiple Line Pattern Matching
Message-Id: <64irq5.iv2.ln@localhost>
Joseph June (jjune@miday.uchicago.edu) wrote:
: I'm pretty new with Perl so my question is going to be pretty basic... but
: I'm not sure how to do a pattern match on strings that are multiple
: lines...
: but is there a way to pattern match something like
: ;coin
: ;quarter
: ;dime
: and so on?
So, the only specification you gave us is that we generate a 'match'
for the above string?
I can do that ;-)
---------------
#! /usr/bin/perl -w
$_=' ;coin
;quarter
;dime';
if (/./) # this is silly, but it does answer the question.
{print "matched\n"} # consider asking a better question...
else
{print "No match\n"}
---------------
: Thank you for your help in advance!
The value of the help you get here is often in direct proportion to
the amount of thought given to phrasing the question ;-)
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Sat, 19 Jul 1997 20:35:54 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Anthony Catalano <apc@satellite.com>
Subject: Re: Perl Compilers or convert to byte code
Message-Id: <Pine.GSO.3.96.970719203424.5095L-100000@kelly.teleport.com>
On Sat, 19 Jul 1997, Anthony Catalano wrote:
> has anyone ever used or heard of a Perl5 byte code compiler??
Yes, there's something about that in the FAQ. Did you look before you
posted?
> just asking
Just answering. :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 19 Jul 1997 17:37:48 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Re: References and Objects
Message-Id: <5qqu1c$kch$1@neocad.com>
Zenin (zenin@best.com) wrote:
: push @{ $self->{eval_list}, [ $evaluation, $design ];
MIssing something here Zenin?
--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com
------------------------------
Date: 17 Jul 1997 20:26:28 GMT
From: mpgordon@phoenix.princeton.edu (Matthew P. Gordon)
Subject: Simultaenous access of DBM files
Message-Id: <5qlv5k$3m3$1@cnn.Princeton.EDU>
After having read the man pages for the DBM and NDBM
libraries, I'm somewhat confused, on a few different levels. A member
of our group wrote a couple of programs that store data in .dbmx files
using 'tie' and 'untie,' and allow another program to read that data
out while the first still has it open for writing. This appears to
work on their system, but not on ours. It seems to me that it
shouldn't work at all because, as the NDBM man page points out, there
is no way to reliably flush cached data; indeed, on our system, even
untie-ing the file does not appear to flush the cache, and the data
does not appear to be written to the file ever. Further, in a test
program I wrote, it doesn't even ever create the specified file! All
of these considerations, and a few others, prompt me to ask the
following questions:
1) _Learning Perl_ seems to imply that the explicit purpose of the
built-in perl DBM routines is for creating files; however, the NDBM
routines (tie/untie) do not even appear to neccesarily create the
files at all, or store the data in them. Is the purpose of the NDBM
routines to store the data in files? Or is to read the data from
files, and/or implement a hash table, only using the files as
neccesary? If it is the latter, how can I create files with this
data?
Or, am I totally in LaLa-Land, i.e., is it just that my code
isn't working properly, and should be doing all the things that I say
it isn't, and would, if I hadn't screwed it up in some fashion? This
would be odd, because the test progrm is very simple.
2) Is there any reason to believe that simultaneously writing to and
reading from a DBM file is reliable and should work in any consistent
fashion? Is there any way to flush data to a DBM file (even though
the man pages for NDBM say there isn't)?
! Matt Gordon /\ mpgordon@princeton.edu \/ http://www.princeton.edu/~mpgordon !
! "...`Cause I'm stranded all alone in the gas station of love !
! And I have to use the self service pumps." -"Weird" Al Yankovick !
--
! Matt Gordon /\ mpgordon@princeton.edu \/ http://www.princeton.edu/~mpgordon !
! "...`Cause I'm stranded all alone in the gas station of love !
! And I have to use the self service pumps." -"Weird" Al Yankovick !
------------------------------
Date: Sun, 20 Jul 1997 06:22:58 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Per Kistler <kistler@erdw.ethz.ch>
Subject: Re: Source multiple line perl file
Message-Id: <Pine.GSO.3.96.970720062204.5855F-100000@kelly.teleport.com>
On Sun, 20 Jul 1997, Per Kistler wrote:
> How would I source a perl file in the middle of a perl file
> if it contains multiple line commands?
I think you're looking for 'require'.
require 'my_library.pl';
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 19 Jul 1997 21:08:57 -0400
From: clays@panix.com (Clay Shirky)
Subject: Re: Testing shift for true or false
Message-Id: <5qrof9$k1r@panix2.panix.com>
In <33d0a394.2686216@news.one.net> over@the.net (dave) writes:
> sub ThisSub
> {
> while( $arg = shift ) {...}
> }
>terminated if one of the args was an empty string ("").
>I allowed empty strings by instead doing:
> while( defined( $arg = shift ) ) {...}
>Might there be a better way?
how about
while (@_) { $arg = shift; ... }
or
@ary = reverse @_;
foreach $arg (@ary) { ... }
--
Clay Shirky
------------------------------
Date: 19 Jul 1997 16:16:14 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: What happens when....
Message-Id: <5qqp8e$sqa@fridge-nf0.shore.net>
Dico Reyers (dico@peionline.com) wrote:
: What happens when two or more people try to write to a file that is
: already open (ie, another person is already writing to it?). Is there
: a way to stop this from happening?
You might get a major spanking if you don't use flock(), which should
have been documented in perlfunc.pod which was included with your Perl
distribution.
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: Sat, 19 Jul 1997 20:03:37 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: why am I trashing binary files with this?
Message-Id: <95orq5.hb3.ln@localhost>
Robert A. Fowler (Robert.A.Fowler@jpl.nasa.gov) wrote:
: I need to reprocess some ccMail import files. These are mostly text files, but
: they may contain binary data (attachments).
: I have files that may contain from 1 to 20 messages and I need to write them
: out to 1 message per file..
: When I run this program the files without binary data are just fine, however
: the ones that have attachments get a lot smaller.
see 'binmode' in the perlfunc man page if you happen to be using one
of the spawn of the Evil Empire as an "operating system".
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
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 748
*************************************