[8447] in Perl-Users-Digest
Perl-Users Digest, Issue: 2064 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 10 12:19:44 1998
Date: Tue, 10 Mar 98 09:00:27 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 10 Mar 1998 Volume: 8 Number: 2064
Today's topics:
"newbie" problem with "reverse" <stackhou@elk.cray.com>
Re: "newbie" problem with "reverse" <placej@ctcdist.com>
Re: Are There Any Snazzy Perl Editors for Windows? <joneil@cks.ssd.k12.wa.us>
Re: Automating Visual C++ Builds with Perl (Jamie O'Shaughnessy)
Re: c.l.p.mod and TPI <merlyn@stonehenge.com>
c.l.p.moderated, TPI, and c.l.p.announce <merlyn@stonehenge.com>
deleting an element <info@baywebdesigns.com>
Re: deleting an element (Mike Stok)
Re: deleting an element <horowitz@ulb.ac.be>
Re: Help: avoiding eval() on a grep() function. schwern@starmedia.net
Re: how to abort sendmail process in perl (123) <chasecreek.systemhouse@usa.net>
How to read text files that contains variables? <horowitz@ulb.ac.be>
Re: How to read text files that contains variables? (Mike Stok)
Re: lowercase $lower = lc("aBcDe"); Blows UP!! schwern@starmedia.net
Re: nslookup? (Clinton Pierce)
Re: nslookup? (I R A Aggie)
Re: Perl and Distributed and Parallel Processing Questi <rkturner@us.ibm.com>
Re: Problem with "goto" in Perl schwern@starmedia.net
Re: redirecting input AND output of a called program in (Clinton Pierce)
Re: redirecting input AND output of a called program in (John Klassa)
Re: RegEx Quiz Question <chasecreek.systemhouse@usa.net>
Re: replacing/removing a escape secquence (Mike Stok)
Using kill -1 from perl 5.003 program on AIX4.1.5 <beggs@gfms.bt.co.uk>
writing back to a file which is being read from <shankeyp@charlestoncounty.org>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 10 Mar 1998 09:51:54 -0600
From: Mark P Stackhouse <stackhou@elk.cray.com>
Subject: "newbie" problem with "reverse"
Message-Id: <3505619A.3F78@elk.cray.com>
I am trying to reverse the order of data in a file. I can open a test
file, write the data into an array and then reverse the data into
another array. However, when I print the data to STDOUT, the data
appears to be off by one line. Why?
I'm also have trouble writing the reversed data back to file. I have
included the code I have so far. Can anyone see my problem?
#!/usr/bin/perl -w
#
# Perl script written by Mark Stackhouse to reverse the order of a file
#
# 03/10/98
#
print "\n\n";
print "This program will reverse the order of a file\n\n";
print "Enter the name of the file to be reversed... ";
chop ($file_name=<STDIN>);
print "\n\n"; # skip 2 lines
open (INPUT_FILE,"$file_name") || die "Could not open file\n";
@data = <INPUT_FILE>;
close (INPUT_FILE);
@reversed_data=reverse (@data);
print "This is the original data...\n"; #Why do I need a "new line"
here?
print "@data";
print "This is the reversed data..."; # but it isn't required here?
print "@reversed_data";
#print "What name should be assigned to the file AFTER it has been
reversed... ";
#chop ($reversed_file=<STDIN>);
#open (OUTPUT_FILE,">$reversed_file") || die "Could not open file\n";
#OUTPUT_FILE = @reversed_data;
#while (<OUTPUT_FILE> != eof)
# {
# print OUTPUT_FILE $reversed_file;
# }
#
#close (OUTPUT_FILE);
--
Mark Stackhouse
x64704
*********************************************************
*
* Senior Electrical-Mechanical Technician
* Homepage - http://wwwmfg.cray.com/~stackhou
* E-mail - stackhou@elk.cray.com
*
* Off site homepage - http://www.execpc.com/~stackhou
*
* Home E-mail - stackhou@execpc.com
*
* "The best things in life aren't things"
*
*********************************************************
------------------------------
Date: Tue, 10 Mar 1998 16:10:48 GMT
From: "John C. Place" <placej@ctcdist.com>
Subject: Re: "newbie" problem with "reverse"
Message-Id: <cCdN.45$QT.166309@ptah.visi.com>
Just a thought:
It looks like the data is turned around INCLUDING the newline. Suggestion
use chomp and put the line in yourself.
John
Mark P Stackhouse wrote in message <3505619A.3F78@elk.cray.com>...
>I am trying to reverse the order of data in a file. I can open a test
>file, write the data into an array and then reverse the data into
>another array. However, when I print the data to STDOUT, the data
>appears to be off by one line. Why?
>
>I'm also have trouble writing the reversed data back to file. I have
>included the code I have so far. Can anyone see my problem?
>
>#!/usr/bin/perl -w
>#
># Perl script written by Mark Stackhouse to reverse the order of a file
>#
># 03/10/98
>#
>print "\n\n";
>print "This program will reverse the order of a file\n\n";
>print "Enter the name of the file to be reversed... ";
>chop ($file_name=<STDIN>);
>print "\n\n"; # skip 2 lines
>open (INPUT_FILE,"$file_name") || die "Could not open file\n";
>@data = <INPUT_FILE>;
>close (INPUT_FILE);
>
>@reversed_data=reverse (@data);
>
>print "This is the original data...\n"; #Why do I need a "new line"
>here?
>print "@data";
>
>print "This is the reversed data..."; # but it isn't required here?
>print "@reversed_data";
>
>#print "What name should be assigned to the file AFTER it has been
>reversed... ";
>#chop ($reversed_file=<STDIN>);
>#open (OUTPUT_FILE,">$reversed_file") || die "Could not open file\n";
>
>#OUTPUT_FILE = @reversed_data;
>
>#while (<OUTPUT_FILE> != eof)
># {
># print OUTPUT_FILE $reversed_file;
># }
>#
>#close (OUTPUT_FILE);
>
>--
> Mark Stackhouse
> x64704
>
> *********************************************************
> *
> * Senior Electrical-Mechanical Technician
> * Homepage - http://wwwmfg.cray.com/~stackhou
> * E-mail - stackhou@elk.cray.com
> *
> * Off site homepage - http://www.execpc.com/~stackhou
> *
> * Home E-mail - stackhou@execpc.com
> *
> * "The best things in life aren't things"
> *
> *********************************************************
------------------------------
Date: Tue, 10 Mar 1998 08:15:29 -0800
From: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
To: Keith Turner <rkturner@us.ibm.com>
Subject: Re: Are There Any Snazzy Perl Editors for Windows?
Message-Id: <35056721.4C8482FF@cks.ssd.k12.wa.us>
ED for Windows (http://www.getsoft.com) has earned a place in my heart.
Jerome "The Color Perlple" O'Neil
Keith Turner wrote:
> Are there any text editors for windows that can recognize perl syntax and
> color code and such?
------------------------------
Date: Tue, 10 Mar 1998 16:07:19 GMT
From: joshaugh@uk.oracle.com (Jamie O'Shaughnessy)
Subject: Re: Automating Visual C++ Builds with Perl
Message-Id: <35055c3c.884259047@newshost.us.oracle.com>
On 9 Mar 1998 23:14:31 GMT, dank@alumnae.caltech.edu (Daniel R. Kegel) wrote:
>I'm trying to figure out how to script my Visual C 5.0 biulds.
>I used to use Makefiles, but Visual C 5.0 has made that nearly impossible.
>According to Steve Hardy
>( http://search.dejanews.com/getdoc.xp?AN=321715463 ),
>Perl is the way to go
>
>Well, it's a bit hard to figure out from scratch. Here's
>my first try at doing anything in msdev with Perl.
>I can't ever figure out how to open a workspace, much less
>build a project.
>
>Can anyone point out where I'm going wrong, or post some example Perl script
>to do this kind of thing?
>
>Thanks!
>
>- Dan
>
># Perl script to test scripting of MSDEV / Visual C++ 5.0
># Use Perl-Win32 from http://www.activestate.com/software/Perl_for_Win32.htm
># to run this script.
># dank@alumni.caltech.edu
>
>use OLE;
>print "Creating MSDEV object\n";
>$msdev = CreateObject OLE 'MSDEV.Application'
> or die "Couldn't create new instance of MSDEV App!!";
>
># Show the app (otherwise, it's hard to believe it really invoked msdev!)
>$msdev->{'Visible'} = 1;
>
># Print the app's name. This works.
>print "App name: ". $msdev->Name . "\n";
>
># This doesn't work - you can't get count this way.
>#print "There are ". scalar($msdev->Projects)." projects.\n";
>
># This does work.
>@projects = $msdev->Projects;
>print "There are ". scalar(@projects)." projects.\n";
>
># This iterates, but ...
>foreach ($msdev->Projects) {
> # Broken. Prints out a blank name.
> print "Project name is ". $_->Name . "\n";
> # Broken. Prints out a blank type.
> print "Project type is ". $_->Type . "\n";
>}
>
># I can't figure out how to build a project.
># ???
>
>print "Hit ENTER\n";
>$x = <>;
>
># Quit the app. This works.
>print "Calling Quit method\n";
>$msdev->Quit();
>print "Done\n";
We currently use perl to manage our automated builds, but we do it my
maintaining "exported" makefiles. We've also written a number of libaries to
parse these makefiles and do any specialy stuff we needed. (It's quite specific
to our development environment so I can't give you example code). This worked
great with MSVC4 but as of 5 we need to maintain this separate exported
makefile, which is ugly.
I had a quick look at the OLE automation of msdev, but like you I couldn't find
out how to do this. Either the doc is very poor, or the functionality is near
useless (then again it could be me :)
If you find a way I'd love to hear.
Jamie
___________________________________________________________________________
Jamie O'Shaughnessy Work: joshaugh @ uk.oracle.com
Oracle C++ Object Layer Generator Team
______________________________________________________ __ __ _ __ . __
Opinions expressed here are my own and not those of... (__)|-</-\(__ |__ -_
------------------------------
Date: 10 Mar 1998 09:34:04 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: chip@pobox.com
Subject: Re: c.l.p.mod and TPI
Message-Id: <8cn2eysdxf.fsf@gadget.cscaper.com>
>>>>> "Chip" == Chip Salzenberg <chip@mail.atlantic.net> writes:
Chip> You miss the point. As you know, TPI can override the no-commercial
Chip> safeguards. What I am explaining is that commercial postings related
Chip> to the activities of TPI's board members will *not* necessarily be the
Chip> only ones that TPI will post. For example, "buy this book" posts
Chip> would likely be acceptable, even if the given book was not published
Chip> by O'Reilly or (co-)written by a TPI board member.
In fact, if it's a commercial activity (book, class, conference) that
*I* have a stake in, I'm *required* by the bylaws of TPI to "disclose
and abstain" on that vote. So, the majority of the board could *not*
vote on an action regarding TPC 2.0 (for example), because we're all
involved. (Hmm, interesting problem, just thought of that. :-) And, a
posting about the Camel book would certainly require that Tim, Larry,
Tom, and me all abstain, leaving it up to Jon and Sharon to approve
that class of posts.
--
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: 10 Mar 1998 09:52:05 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: "Eric D. Friedman" <friedman@uci.edu>
Subject: c.l.p.moderated, TPI, and c.l.p.announce
Message-Id: <8ciupmsd3e.fsf_-_@gadget.cscaper.com>
>>>>> "Eric" == Eric D Friedman <friedman@uci.edu> writes:
Eric> A couple of important points here:
Eric> 1) TPI may be non-profit, but it exists, in part, to circulate
Eric> information about the revenue-generating activities of its members
Eric> (conferences, publications (books, the journal), and training). As it
Eric> stands, the charter allows the TPI board unfettered and unparalleled
Eric> access to consumers of such services, while excluding anyone else
Eric> who might like to offer something similar w/o paying TPI dues.
Not at all. In another post, I describe the "disclose and abstain"
requirements of the non-profit status for TPI. I cannot require that
TPI promote Stonehenge trainings, for example. It has to be accepted
by a majority of the other board members, with my vote a necessary
abstention. Just like the ORA books can't necessarily get a favored
status from the board... since many of the board members are also ORA
writers, and therefore would have to abstain appropriately.
Eric> Just to be clear: I like the books and the journal, and I'm sure
Eric> all TPI folks are excellent trainers, but if something better
Eric> comes along that isn't affiliated with TPI, I'd like it to be
Eric> just as easy to hear about that something as about TPI services.
If it's commercial, it's almost certainly not going to be in comp.*
anyway (Usenet is non-commercial to begin with). Go find the
websites. They're out there. The postings to be approved by the TPI
board for "commercial" announcements will most likely be just
conference related (call-for-papers, final announcement) and new
products available (one-time postings for books etc.). You're not
going to see weekly amazon.com postings with "This week in the store
we have How-to Teach Yourself CGI and Perl for the Web in 3 days
Unleashed, special edition for $5 off!" I can assure you that I'd
vote that down, even if it was my own books! :-)
Eric> As to Tom's specific involvement: he, his two co-authors, and his
Eric> publisher (who *obviously* has a commercial stake in promoting
Eric> the "non-profit" TPI-endorsed Perl Conference & O'Reilly books)
Eric> form a majority of the TPI board. I'd be very surprised if any of
Eric> these folks voted against posting something that would be in
Eric> their financial best interests.
As I said, we cannot vote for or against it. It has to be decided by
the remaining board members that have no financial stake in the matter.
Eric> Imagine that Dave Till (just to pick on somebody), his publisher, and a
Eric> couple of other SAMS-advocates got majority control of TPI's board.
Same thing there. By the by-laws of TPI, they'd be required to
abstain from voting on actions for which *they* benefit.
Eric> Would you really want unmoderated "commercials" (that's a quote)
Eric> advocating TYP in 21 days/minutes/seconds?
Wouldn't happen.
Eric> To be perfectly frank, I don't see why TPI has to have this
Eric> special dispensation. Surely comp.lang.perl.announce is a better
Eric> forum for announcements, commercial and otherwise.
Wrong. CLPA has a necessary non-commercial charter.
The approved charter says "comp.lang.perl.announce will be a
low-volume, moderated group for announcements of new releases of perl
or its extensions (oraperl, sybperl, etc.) and periodic postings
related to perl."
I don't see anything in there that permits conference or book
announcements.
Eric> 2) If TPI is to have special status, the distinction Chip describes
Eric> should be enforced by including language in the charter that
Eric> specifically forbids members of TPI's board from simultaneously serving
Eric> as moderators for c.l.p.mod.
I get it up to here, and I might even agree with you...
Eric> Otherwise, you'll be setting the unfortunate precedent of
Eric> allowing a person (or persons) with an interest in one
Eric> commercial product to overrule the circulation of news about
Eric> another.
... but you lost me here. clp.mod-erators will have a strict
non-commercial charter. However, if the TPI board approves, a
commercial posting may be posted. Such commercial posting can only be
voted on by the people that *don't* have an interest in the post!
There is never a path by which a commercial posting of any kind can be
ramrodded through the system by the people that would benefit from it.
What exactly is your concern?
--
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, 10 Mar 1998 16:22:19 GMT
From: Bayweb Designs <info@baywebdesigns.com>
Subject: deleting an element
Message-Id: <350568C3.5C3F5ADB@baywebdesigns.com>
--
I need to delete a line, $match, out of an array. Suppose my array was:
@a = ("one","two","three","four","five");
$match =3;
I have to get element number 3 out of the array. Can you give me some
example code?
------------------------------------------------------
George Cyriac Bayweb Designs
http://www.baywebdesigns.com
info@baywebdesigns.com
------------------------------------------------------
------------------------------
Date: 10 Mar 1998 16:32:12 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: deleting an element
Message-Id: <6e3puc$mvr@news-central.tiac.net>
In article <350568C3.5C3F5ADB@baywebdesigns.com>,
Bayweb Designs <info@baywebdesigns.com> wrote:
>--
>I need to delete a line, $match, out of an array. Suppose my array was:
>@a = ("one","two","three","four","five");
>$match =3;
>I have to get element number 3 out of the array. Can you give me some
>example code?
You should look at splice which is documented in the perlfunc man page.
splice can do pretty much any insertion or removal of contiguous elements
in an array.
For example, in the debugger, rememnering that array indices start at 0 by
default
DB<1> @a = ("one","two","three","four","five")
DB<2> $match =3
DB<3> @removed = splice @a, $match, 1
DB<4> X removed
@removed = (
0 'four'
)
DB<5> X a
@a = (
0 'one'
1 'two'
2 'three'
3 'five'
)
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: 10 Mar 1998 17:45:12 +0100
From: Horowitz Joel <horowitz@ulb.ac.be>
Subject: Re: deleting an element
Message-Id: <wk6u396336v.fsf@orca.i-have-a-misconfigured-system-so-shoot-me>
Hye,
> I need to delete a line, $match, out of an array. Suppose my array was:
> @a = ("one","two","three","four","five");
> $match =3;
> I have to get element number 3 out of the array. Can you give me some
> example code?
@a = ("one","two","three","four","five");
$match =3;
print "@a\n"; gives you "one two three four five"
print "@a[$match-1]\n"; gives you "three"
$size=@a; gives you 5
@a=(@a[0..$match-2],@a[$match..$size-1]);
print "@a"; gives you "one two four five"
Ciao
/\
==== .----/ \----. ==== Joel Horowitz <horowitz@ulb.ac.be> ======
\ /
.--\ (o)(o) /__. ULB - Dept. de Mathematiques, C.P. 218
\ () / Campus PLAINE - 50, Bd. du Triomphe
> (C_) < 1050 Bruxelles - Belgique
/___\____/___\
==== /| |\ ===== http://homepages.ulb.ac.be/~horowitz ======
/ \
------------------------------
Date: Tue, 10 Mar 1998 10:45:35 -0600
From: schwern@starmedia.net
Subject: Re: Help: avoiding eval() on a grep() function.
Message-Id: <6e3ql3$nft$1@nnrp1.dejanews.com>
In article <EpKL82.15D@world.std.com>,
aml@world.std.com (Andrew M. Langmead) wrote:
>
> schwern@starmedia.net writes:
>
> >$pattern = join '&&', map { "m/$_/" } @Pattern;
> >$matchSub = eval "sub { $pattern }";
>
> >@matches = grep {&$matchSub} @Array;
>
> >This avoids doing the eval at each iteration of the grep.
>
> Subroutine dereferencing and calling is fairly expensive too, and
> should probably also be avoided inside of grep. Trading an eval for a
> sub de-reference probably isn't that big of a win.
Problem is... you need it. You can't do "grep { m/$STR1/ && m/$STR2/ }
@array" because we don't know how many $STR's there will be in this case. In
the original problem, @Pattern contains an unknown number of patterns. And
eval of some sort is necessary to build the list of pattern matches from the
@pattern.
However, regarding the Benchmark. I ran it (why didn't you give any results)
and did get some interesting numbers...
Benchmark: timing 10000 iterations of loop_eval, one_eval, sub_match...
loop_eval: 0 secs ( 0.01 usr 0.00 sys = 0.01 cpu)
(warning: too few iterations for a reliable count)
one_eval: 4 secs ( 4.34 usr 0.00 sys = 4.34 cpu)
sub_match: 5 secs ( 4.63 usr 0.01 sys = 4.64 cpu)
I have no idea what that's all about.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Tue, 10 Mar 1998 16:45:52 GMT
From: Sneex <chasecreek.systemhouse@usa.net>
Subject: Re: how to abort sendmail process in perl (123)
Message-Id: <35056CF9.1D1977A4@usa.net>
The problem you are experiencing is 'sendmail' related
not Perl-related; please try a sendmail NG :-)
Your filehandle is 'talking' to sendmail directly,
so you will need to get sendmail to cough up
the hairball so it won't send it.
HTH,
Bill
Nick Halloway wrote:
> I'm working on modifying a program which opens a sendmail process that's
> attached to a filehandle. The program writes out a mail message to the
> filehandle, then when the filehandle is closed, the mail is sent.
>
> Is it possible to abort this process after it's started, so that the
> mail isn't sent? Would clearing out the filehandle somehow do this?
> I tried
>
> truncate (FILEHANDLE, 0);
>
> but that didn't work.
>
> Thanks much.
------------------------------
Date: 10 Mar 1998 17:20:15 +0100
From: Horowitz Joel <horowitz@ulb.ac.be>
Subject: How to read text files that contains variables?
Message-Id: <wk6d8fumsao.fsf@orca.i-have-a-misconfigured-system-so-shoot-me>
Hye,
I'd like very much to be able to open a text file like this:
=======
...
Dear <=name=>,
your email address is <=email=>
...
=======
And replace every occurrence of <=...=> by the value of the variable
inside. I tried
<CODE> $name="John"; $email="john\@john.com";
<CODE> while(<FILE>) { s/<=(.*?)=>/$1/; print; }
which gave
<OUTPUT> Dear name,
<OUTPUT> your email address is email
so I thought: why not try
<CODE> $name="John"; $email="john\@john.com";
<CODE> while(<FILE>) { s/<=(.*?)=>/$$1/; print; }
^^^
which gave
<OUTPUT> Dear 190671,
<OUTPUT> your email address is 190671
How should I do to get what I want, i.e.
<OUTPUT> Dear John,
<OUTPUT> your email address is john@john.com
I could solve the problem by using associative arrays (like
$var{'name'}, etc...), but it's longer to type, and more complicated
to maintain... Any idea?
Joel Horowitz
/\
==== .----/ \----. ==== Joel Horowitz <horowitz@ulb.ac.be> ======
\ /
.--\ (o)(o) /__. ULB - Dept. de Mathematiques, C.P. 218
\ () / Campus PLAINE - 50, Bd. du Triomphe
> (C_) < 1050 Bruxelles - Belgique
/___\____/___\
==== /| |\ ===== http://homepages.ulb.ac.be/~horowitz ======
/ \
------------------------------
Date: 10 Mar 1998 16:46:03 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: How to read text files that contains variables?
Message-Id: <6e3qob$mvr@news-central.tiac.net>
In article <wk6d8fumsao.fsf@orca.i-have-a-misconfigured-system-so-shoot-me>,
Horowitz Joel <horowitz@ulb.ac.be> wrote:
>Hye,
>I'd like very much to be able to open a text file like this:
>
>=======
>...
>Dear <=name=>,
>your email address is <=email=>
>...
>=======
>
>And replace every occurrence of <=...=> by the value of the variable
>inside. I tried
><CODE> $name="John"; $email="john\@john.com";
><CODE> while(<FILE>) { s/<=(.*?)=>/$$1/; print; }
> ^^^
>which gave
>
><OUTPUT> Dear 190671,
><OUTPUT> your email address is 190671
That's 'cos $$ is perl's process ID, you might have meant to do:
s/<=(.*?)=>/${$1}/g;
which uses $1 as a soft or symbolic reference.
>How should I do to get what I want, i.e.
>
><OUTPUT> Dear John,
><OUTPUT> your email address is john@john.com
If you're feeling like re-using someone else's work then CPAN has
Text::Template - This module defines a "template" as a chunk of text with
cute little Perl expressions embedded in it. You can use this module to
replace the expressions with their values.
according to ftp://ftp.iguide.com/pub/mirrors/packages/perl/CPAN/CPAN.html
In general I prefer solutions which use some container (e.g. a hash
mapping symbols to their replacement) as it's less prone to accidentally
substituting some random variable if there is a typo in the template.
Another thing to think about is the form names you let through, it might
be worthwhile insurance to say something like
s/<=([a-zA-Z_]\w*)=>/.../;
to limit what are considered "valid" <= ... => tags for substitution.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: Tue, 10 Mar 1998 10:36:19 -0600
From: schwern@starmedia.net
To: christian@sur-tech.com
Subject: Re: lowercase $lower = lc("aBcDe"); Blows UP!!
Message-Id: <6e3q4e$mr5$1@nnrp2.dejanews.com>
In article <Christian-ya023580000903981041480001@nntp.best.com>,
christian@sur-tech.com wrote:
> Hi All,
> Lost here.. i'm new to perl.. so far most all in the SAMS book on perl-5
has
> worked well.. i have version 5 running on freebsd.. 3.0 122597.. just before
> the vm changes..
DING DING DING! FreeBSD is notorious for sticking with Perl4. The game, is
afoot!
> and it seems to work well, i had a line in there like so:
> $sub = substr ($string,0,3);
>
> finally tried a basic line like
> $lower = lc("aBcDe");
> this line is directly out of the book!! and if i put it anyplace in my prog,
> it blows up!?.. error output just trying to run the prog looks like below..
>
> "lc" may clash with future reserved word at ././item line 35syntax error in
> file ././item at line 35
> , next 2 tokens "lc("
Elementry, my dear Watson. You're using Perl4, you ninny! "next 2 tokens" is
a dead giveaway. Check to make sure your #!/path/to/perl is in fact pointing
to perl5 and not perl4. "/path/to/perl -v" should tell you what's up.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 10 Mar 1998 15:52:00 GMT
From: cpierce1@cp500.fsic.ford.com (Clinton Pierce)
To: Jim Murrell <lingjen@ra.isis.unc.edu>
Subject: Re: nslookup?
Message-Id: <6e3nj0$a7n7@eccws1.dearborn.ford.com>
*************************************************************************
************************** FREE RANDAL **********************************
*************************************************************************
In article <Pine.SOL.3.96.980310094407.25647A-100000@ra.isis.unc.edu>,
Jim Murrell <lingjen@ra.isis.unc.edu> writes:
>I have been trying to write a short perl script
>that takes an IP number and essentially does
>an "nslookup". I would prefer not using the
>system call to do but tried gethostbyaddr
>without too much success. Does anyone have
>an example of some perl code that does this?
>
>Thanks,
> Ling Jen
>
----------------------------------------------------------------------
QUICK SEARCH WITH DEJANEWS (www.dejanews.com) HAS TURNED UP
300 Matches for search: gethostbyaddr
in comp.lang.perl.misc
WITH MANY RESPONSES HAVING CODE SAMPLES. YOU DID NOT DO
THOROUGH RESEARCH BEFORE POSTING THIS QUESTION, BY EITHER LURKING
OR SEARCHING DEJANEWS EVEN LIGHTLY.
----------------------------------------------------------------------
The documentation for gethostbyaddr can be found in:
The Blue Camel (functions)
The Blue Camel (Chap 6, Social Engineering, Sockets w/lots
of working code samples)
Your system manpages gethostbyaddr(3N)
*************************************************************************
************************** FREE RANDAL **********************************
*************************************************************************
--
+------------------------------------------------------------------------+
| Clinton A. Pierce | "If you rush a Miracle Man, | http://www. |
| cpierce1@ford.com | you get rotten miracles" | dcicorp.com/ |
| fubar@ameritech.net |--Miracle Max, The Princess Bride| ~clintp |
+------------------------------------------------------------------------+
GCSd-s+:+a-C++UALIS++++P+++L++E---t++X+b+++DI++++G++e+>++h----r+++y+++>y*
------------------------------
Date: Tue, 10 Mar 1998 11:13:14 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: nslookup?
Message-Id: <fl_aggie-1003981113140001@aggie.coaps.fsu.edu>
In article <Pine.SOL.3.96.980310094407.25647A-100000@ra.isis.unc.edu>, Jim
Murrell <lingjen@ra.isis.unc.edu> wrote:
+ I have been trying to write a short perl script
+ that takes an IP number and essentially does
+ an "nslookup". I would prefer not using the
+ system call to do but tried gethostbyaddr
+ without too much success. Does anyone have
+ an example of some perl code that does this?
Yes, I grabbed this off the net:
#!/usr/bin/perl
#usage:
#$ address2name 199.232.46.114
$bobo = pack("C4", (shift =~ /(\d+).(\d+).(\d+).(\d+)/));
($name, $aliases, $addrtype, $length, @addrs) = gethostbyaddr($bobo, 2);
print "Name: $name\n";
print "Aliases: $aliases\n";
print "Address type: $addrtype\n";
print "Length: $length\n";
print 'Addresses: ';
foreach (@addrs) { print join('.', unpack('C4', $_)); }
print "\n";
---
I don't understand it, I just use it...
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: Tue, 10 Mar 1998 09:42:03 -0600
From: "Keith Turner" <rkturner@us.ibm.com>
Subject: Re: Perl and Distributed and Parallel Processing Question
Message-Id: <6e3mvv$19e2$1@ausnews.austin.ibm.com>
Lynch Man wrote in message <3504c961.0@news.cyberenet.net>...
>I am researching Perl v5.0 for a Computer Language Theory and Design Class
>project. I am searching for information concerning Perl and it's ability
>and support of distributed and parallel processing. Basically, I am
looking
>for these topics:
>
> - Multiple Processes
> - Semaphores
> - Monitors
> - Rendezvous
> - Synchronization
> - Message Passing
>
>If anyone knows of any books or web pages, or they themselves can provide
>any information on these subjects it would be greatly appreciated.
>
>Thanks,
>Peter Foley
>foleyp1@alpha.lasalle.edu
>
>
Try Perl and PVM..... for a message passing module.
http://www.oasis.leo.org/perl/exts/net/Pvm.dsc.html
Also release 5.005 might be multithreaded... which would mean
Synchronization I suppose.
http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html
look in the FAQ and search for thread.
Perl allready has semaphores, for shared memory, if it is built on a Sys V
system I think, but not sure I am more used to BSD and NT platforms.. And
for multiple processes perl supports the fork() call, but maybe not on NT.
------------------------------
Date: Tue, 10 Mar 1998 10:22:24 -0600
From: schwern@starmedia.net
Subject: Re: Problem with "goto" in Perl
Message-Id: <6e3p9k$mif$1@nnrp1.dejanews.com>
In article <EpKq32.EDy@world.std.com>,
aml@world.std.com (Andrew M. Langmead) wrote:
>
> Zenin <zenin@best.com> writes:
>
> >Andrew M. Langmead <aml@world.std.com> wrote:
> > >snip<
> >: The statement "goto LABEL" has its uses (maybe less so than in other
> >: languages, but there are uses.)
>
> > Show me one, please. [stuff deleted]
Okay... even though I'm the one who was snarling about the satanic virtues of
goto's earlier, that was mostly bravado to scare off an inexperienced
programmer (who truely has no business messing with goto).
>From _Code Complete_ Chapter 16.1 "The Argument for gotos"
"The goto is useful in a routine that allocates resources, performs operations
on those resources, and then deallocates the resources. With a goto, you can
clean up in one section of code. The goto reduces the likelihood of your
forgetting to deallocate the resources in each place you detect an error."
This kinda falls under the AUTOLOAD style goto &subroutine, and the "extreme
error recovery" case.
Knuth's "Structured Programming with go to Statements" 1974 _Classics in
Software Engineering_ edited by Edward Yourdon, basically its an article with
a horde of examples made more efficient by eliminating gotos, and then a whole
'nother horde of examples made more efficient by adding gotos. :) How
relevant any of these examples are to Perl5, I have no idea. I don't have the
book handy.
One use I saw was in an error recovery for a one-shot script (which,
admitidly, isn't the greatest source for good programming style.) Which went
something like this...
use Memoize; # Cache function calls. Tip to \mjd. :)
LABEL;
#
# A few hundred lines of linear code...
#
if( $CertainErrorCondition ) {
#...recover from the error...
#...reevaluate the program inputs, then...
goto LABEL; # Start over, but hang onto all the work we've done.
}
#
# Lots more code...
#
Now, granted... if the program was properly designed in the first place, this
goto wouldn't be necessary. But it was a one-shot script and an extra
requirement was added in at the last moment (doncha love how those one-shot
scripts always turn into all-day projects?) requiring this little hack. Now,
there are other possiblities. He could have wrapped the program in a labeled
block and done a next LABEL or redo LABEL (wait... can you do that in a
non-loop block?), but would that really have been any different from the
goto? No. The use of Memoize for effeciency purposes means that rerunning
the program would incur a heavy penalty (exec $0, @newArgs; or something) due
to loss of cached function calls.
The goto was well commented with the above reasoning (and an apology).
Anyone see a good gotoless fix for that (aside from redesigning the whole
program?)
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 10 Mar 1998 15:37:35 GMT
From: cpierce1@cp500.fsic.ford.com (Clinton Pierce)
To: Christof Ameye <ameyec@sebb.bel.alcatel.be>
Subject: Re: redirecting input AND output of a called program in perl
Message-Id: <6e3mnv$a7n4@eccws1.dearborn.ford.com>
*************************************************************************
************************** FREE RANDAL **********************************
*************************************************************************
In article <35054868.6C5F@sebb.bel.alcatel.be>,
Christof Ameye <ameyec@sebb.bel.alcatel.be> writes:
>In perl you can easily redirect input OR output
>
>open(FILEO,"command |"); #for getting output
>open(FILEI,"| command"); #for giving input
>
>but you can't do :
>
>open(FILEIO,"| command |"); #for in AND output
>
>But that's just what I need ...
>Any idea how to do this easily ?
>
>(with pipes ?? how do you do that ? maybe give me link with more info ?)
^^^^^^^^^^^^^
You should EARN these
---------------------------------------------------------------------
QUICK SEARCH WITH DEJENEWS (www.dejanews.com) HAS TURNED UP
90 Matches for search: "open reading writing pipe"
in comp.lang.perl.misc
WITH MOST RESPONSES HAVING CORRECT ANSWERS. YOU DID NOT DO
THOROUGH RESEARCH BEFORE POSTING THIS QUESTION, BY EITHER LURKING
OR SEARCHING DEJANEWS EVEN LIGHTLY.
---------------------------------------------------------------------
This is covered in the documentation that was shipped with perl.
Try:
perldoc perlipc
What your interested in is called "Inter-Process Communications", covered
very thoroughly in the perlipc documentation, and in the Blue Camel
Chapter 6, under "Bidirectional Communication". READ IT THOROUGHLY,
otherwise you'll be posting another FAQ to the group in a couple of
days 'cause your processes have deadlocked.
*************************************************************************
************************** FREE RANDAL **********************************
*************************************************************************
--
+------------------------------------------------------------------------+
| Clinton A. Pierce | "If you rush a Miracle Man, | http://www. |
| cpierce1@ford.com | you get rotten miracles" | dcicorp.com/ |
| fubar@ameritech.net |--Miracle Max, The Princess Bride| ~clintp |
+------------------------------------------------------------------------+
GCSd-s+:+a-C++UALIS++++P+++L++E---t++X+b+++DI++++G++e+>++h----r+++y+++>y*
------------------------------
Date: 10 Mar 1998 16:15:21 GMT
From: klassa@aursgh.aur.alcatel.com (John Klassa)
Subject: Re: redirecting input AND output of a called program in perl
Message-Id: <6e3oup$rjb$1@aurwww.aur.alcatel.com>
On Tue, 10 Mar 1998 15:04:24 +0100, Christof Ameye wrote:
->but you can't do :
->open(FILEIO,"| command |"); #for in AND output
->But that's just what I need ...
->Any idea how to do this easily ?
You read perlfaq8:
...How can I open a pipe both to and from a command?
John
--
John Klassa / Alcatel Telecom / Raleigh, NC, USA <><
------------------------------
Date: Tue, 10 Mar 1998 16:40:44 GMT
From: Sneex <chasecreek.systemhouse@usa.net>
Subject: Re: RegEx Quiz Question
Message-Id: <35056BC6.F518DC61@usa.net>
I hope my news poster is posting again :-)
Anyways, given the below, how can you
control it so that only between 1 to 3 digits per
octet is returned?
Thx,
Bill
PS - My apologies to all I pestered
via e-mail, I will keep my thoughts to myself :-)
Bill Jones wrote:
> ($client,$host) = /(\d+\.\d+\.\d+\.\d+).+ > (\d+\.\d+\.\d+\.\d+)/
> if /P \d+:\d+\((\d+)\)/ && $1 > 0;
>
> The above is from Lincoln Stein's 'sniffer'.
>
> Would someone please help me understand it
> a little better?
>
> Thx,
> Bill :-)
------------------------------
Date: 10 Mar 1998 15:53:48 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: replacing/removing a escape secquence
Message-Id: <6e3nmc$mvr@news-central.tiac.net>
In article <35055E44.A6ABAF3F@charlestoncounty.org>,
Peter Shankey <shankeyp@charlestoncounty.org> wrote:
>I have a file which has been moved to a unix system from a dos system.
>The file contains a ^M or I should say a "ESC M". I know it a escape
>sequence because I see it in vi but not with a cat command.
>
>to get rid of it I have tried the follow with no success:
>
>stuff
>while (<CU>) {
>s/^[M//;
>print CUtemp $_;
>}
That's a control M, and you can say something like
s/\cM//;
to get rid of control M characters. This is documented in the perlre
manual page.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: Tue, 10 Mar 1998 16:54:37 +0000
From: Sue Beggs <beggs@gfms.bt.co.uk>
Subject: Using kill -1 from perl 5.003 program on AIX4.1.5
Message-Id: <3505704D.31B8@gfms.bt.co.uk>
I have a perl 5.003 program which updates the access.conf file with
users allowed to access the system, I then write to STDOUT a message to
tell the user that the file has been updated successfully.
To pick up the changes to the access.conf file so that the user can
login I interrupt the http daemon with cat
/usr/local/etc/httpd/logs/httpd.pid then a kill (1, $pid).
The problem is that the kill interrupts the daemon before the success
message has been printed out. All the user sees is a pop-up with
Document contains no data when the program has run successfully.
I have set $| = 1 to flush the buffers but it still doesn't work. Has
anybody used this successfully?
thanks
Sue Beggs
------------------------------
Date: Tue, 10 Mar 1998 11:39:41 -0500
From: Peter Shankey <shankeyp@charlestoncounty.org>
Subject: writing back to a file which is being read from
Message-Id: <35056CCC.BB22BFC1@charlestoncounty.org>
I need to read one line at a time in a file (temp) each line may or may
not need to be changed then I need to write back to the same file
replacing what I have changed. I know I need to move the file pointer
back one line and overwrite what I just changed. I figure it has
something to do with the seek command. Is there a easy way to do this??
thanks
pete
------------------------------
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 2064
**************************************