[6402] in Perl-Users-Digest
Perl-Users Digest, Issue: 27 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 27 22:17:23 1997
Date: Thu, 27 Feb 97 19:00:21 -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 Thu, 27 Feb 1997 Volume: 8 Number: 27
Today's topics:
Re: A eval() or substitution question (Mike Stok)
expect:autoexpect::Comm.pl:?? <mdsmith@qualcomm.com>
Re: FILE LOCKING (David DeSimone)
Re: File Locking (David DeSimone)
Re: File Locking (Abigail)
Re: Generating a randomly sorted list of integers (Abigail)
Help: "! File contains no data" prompt (Keith Warner Colvin)
Re: help: Server error (Curt Bousquet)
Re: how long before I can put down the books? <brett@speedy.speakeasy.org>
Re: How to spam - legitimately (Lee)
Howto use open2() (Raman Garg)
Re: need help <billc@tibinc.com>
Re: newbie question:manipulating strings <jstrick@mindspring.com>
Newsflash: Progressive Networks' RealMedia Conference <pnetwork@sbexpos.com>
Re: Optimizing nested loops (Andrew M. Langmead)
Re: Perl and win95 <mdsmith@qualcomm.com>
Re: Perl as a shared library? <brett@speedy.speakeasy.org>
Perl geomtetry <ira@rta.nsw.gov.au>
Re: Perl Munitions T-Shirt <brett@speedy.speakeasy.org>
Regular Expressions problem please help! (Leonhard Brenner {13031} 7149 [ ])
Re: sometimes > not greater than? <oshmis1@pacbell.net>
Substituting a bunch of strings (Michael Schuerig)
Re: Unix Commands in Perl Script (Jagadeesh Venugopal)
Re: Windows95 (Andrew M. Langmead)
Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 Feb 1997 23:18:41 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: A eval() or substitution question
Message-Id: <5f54oh$jc6@news-central.tiac.net>
In article <3315CC88.647F@pms110.pms.ford.com>,
Mike Conley <mconley@pms110.pms.ford.com> wrote:
>How can I get variable substitution to happen in an input string?
>
>This simple example shows the problem. Is there a solution?
Yes, you're expecting perl to do multiple substitution passes on an
interpolation on the string, try:
#!/usr/local/bin/perl -w
$prefix="/usr/local";
$var1 = "$prefix/bin"; # OK, prints /usr/local/bin
print "1. ", $var1, "\n";
$input = '$prefix/bin';
print "2. ", $input, "\n"; # OK, prints $prefix/bin
$code = '$junk = "' . $input . '"';
print "evaluating: ", $code, "\n"; # get perl to do substitution
eval $code;
print $@ if $@;
print "3. $junk\n";
__END__
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@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: Thu, 27 Feb 1997 17:11:08 -0800
From: Michael Smith <mdsmith@qualcomm.com>
Subject: expect:autoexpect::Comm.pl:??
Message-Id: <331630AC.6CE8@qualcomm.com>
Is anyone working on (or is there already) the equivalent of autoexpect
for Comm.pl? If there isn't, does someone have a good idea as to how
one might make an equivalent? I'm interested in perhaps doing this if
it doesn't already exist.
Thanks,
-- Mike
------------------------------
Date: 27 Feb 1997 17:57:07 -0600
From: fox@convex.com (David DeSimone)
Subject: Re: FILE LOCKING
Message-Id: <5f570j$i4k@mikey.convex.com>
In <01bc2455$75ba6060$1d94e5cf@default> "Neil Edmondson" <neiled@enteract.com> writes:
> Although the following code will do what I want (that is I can live
> with the risk). There's a big hole re: locking. What strategies
> exist to deal with the possibility that someone else may grab the file
> and screw with it in between reading and writing?
As you've written your program, you have NO assurance that anyone will
leave the file alone. Specifically, you open and close the file twice.
Even if you assume that all programs that touch this file will perform
advisory locking upon it, you still have no assurance.
> open (SESSION, "<" . $session_file); # Open the file for rea
> flock (SESSION, $exclusive_lock); # and lock it for exclu
> $session_ID = <SESSION>; #
> flock (SESSION, $remove_lock); # Give the file back
> close (SESSION);
>
> $session_ID++; # Bump the session coun
>
> open (SESSION, ">" . $session_file); # Open the file for wri
> flock (SESSION, $exclusive_lock); # and lock it for exclu
> print SESSION $session_ID; # and rewrite
> flock (SESSION, $remove_lock); # Give the file back
> close (SESSION);
In this example, if there were two processes both competing for this
file, the first one might read the session ID, then relinquish the file,
and the other program could then grab it and get the SAME session ID!!
Because you did not keep the lock before updating the file.
Here is some code that I use for this type of activity:
> open (SESSION, "+<$session_file");
> flock (SESSION, $exclusive_lock);
> $session_ID = <SESSION>;
> $session_ID++;
> seek(SESSION, 0, 0);
> truncate(SESSION, 0);
> print SESSION $session_ID;
> close (SESSION);
This allows the file to be updated without any other (cooperating)
process trashing the file or even attempting to use its contents while
the state is in flux.
--
David DeSimone | "There is no reason for any individual to have a
fox@convex.hp.com | computer in their home." -- Ken Olson, President of
If I said it, it | DEC, World Future Society Convention, 1977
must be my opinion | PGP: 5B 47 34 9F 3B 9A B0 0D AB A6 15 F1 BB BE 8C 44
------------------------------
Date: 27 Feb 1997 18:06:01 -0600
From: fox@convex.com (David DeSimone)
Subject: Re: File Locking
Message-Id: <5f57h9$ifv@mikey.convex.com>
In <sasrmd.857062729@sas.com> sasrmd@unx.sas.com (Bob Dixon) writes:
> On my system +< fails if the file doesn't already exist and +>
> overwrites the file if it does (which I don't want).
>
> What I did was:
>
> open(FILE, "+<filename") || open("+>filename") || die "etc";
>
> I'm interested in criticism/comments on the above, since I'm
> relatively new to perl.
I think it an inherently bad idea to depend upon locking a file which
may not necessarily exist. The reason is that you cannot keep the
process atomic.
If you had two competing processes running the above code, process A
might attempt to open the file with "+<", and find that it does not
exist. Meanwhile, process B might do exactly the same thing, before
process A has had a chance to execute its next statement. Therefore,
both processes will then proceed to create a file, and one of them will
overwrite the file that the other created.
Hmm, when I initially started to write this, I thought that both each
process would then end up with a file descriptor pointing to different
files (one of which is a "lost" file). Thinking some more on it,
perhaps it is the case that if process A ends up creating the file,
process B will then simply re-open that file and both will be ready to
write it (after some suitable locking, of course). If that is the case,
then I really can't see a problem with the above scheme.
Can anyone help me clarify this issue?
--
David DeSimone | "There is no reason for any individual to have a
fox@convex.hp.com | computer in their home." -- Ken Olson, President of
If I said it, it | DEC, World Future Society Convention, 1977
must be my opinion | PGP: 5B 47 34 9F 3B 9A B0 0D AB A6 15 F1 BB BE 8C 44
------------------------------
Date: Fri, 28 Feb 1997 01:21:29 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: File Locking
Message-Id: <E6AH3t.DH6@nonexistent.com>
On 27 Feb 1997 17:37:07 GMT, Nathan V. Patwardhan wrote in comp.lang.perl.misc:
++ Bob Dixon (sasrmd@unx.sas.com) wrote:
++
++ : On my system +< fails if the file doesn't already exist and +>
++ : overwrites the file if it does (which I don't want). What I did was:
++
++ Right. From the Perl docs, you'll note that +< will fail if the file
++ does not exist. +> will create a new file in read/write.
++
++ : open(FILE, "+<filename") || open("+>filename") || die "etc";
++
++ You might try something like:
++
++ $filename = 'filename';
++ if(-e "$filename") {
++ ### open r/w
++ } else {
++ ### open c/r/w
++ }
++
Isn't that dangerous? Another process can create the file
right after your if, but before you open it.
How about:
-e $file or system "touch $file" and die "Oops: " . $? >> 8;
open FILE, "+< $file" or die "Oops: $!";
At most you do a relative harmless 'touch $file'.
Abigail
------------------------------
Date: Fri, 28 Feb 1997 01:56:50 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: Generating a randomly sorted list of integers
Message-Id: <E6AIqq.JxB@nonexistent.com>
On 27 Feb 1997 17:23:46 GMT, Jan Schipmolder wrote in comp.lang.perl.misc:
++ spammers@must.die.com wrote:
++ : >"I'm writing this on my Timex Sinclair, with only 2K of memory..." ;-)
++ :
++ : I was surprised how little memory I had available when I ported some
++ : scripts from Unix to MacPerl. I "randomize" /usr/dict/words or whatever
++
++ Here is a faster way to pick a random word from /usr/dict/words:
++
++ - use stat to find the length of the file
++ - go to a random offset from the beginning
++ - read one line
++ - this line is probably not a full line, since you went to a random spot
++ in the file
++ - read one more line
++ - this line is a full line from the file; it's also "random"
++ - since /usr/dict/words has one word per line, you now have a random word
++ - repeat if the second read gave you end-of-file
++
It might be "random", it certainly isn't fair.
- the first word will never be picked.
- a word following a large word has a larger chance of being picked that
a word following a small word.
Abigail
------------------------------
Date: Thu, 27 Feb 1997 15:52:09 -1000
From: colvin@aloha.net (Keith Warner Colvin)
Subject: Help: "! File contains no data" prompt
Message-Id: <colvin-2702971552090001@hawaii-64.u.aloha.net>
Aloha from Hawai'i,
My .cgi is running fine, yet when I access the file "...page=number.shtml&cart__id"
I get this response:
"! File contains no data"
here is where it is:
http://hele.com/cgibin/html_web_store.cgi?page=number.shtml&cart_id=
Any suggestions from those who know more?
------------------------------
Date: Thu, 27 Feb 97 23:08:54 GMT
From: no@spam.please (Curt Bousquet)
Subject: Re: help: Server error
Message-Id: <5f5469$haq@thrush.sover.net>
In article <colvin-2702971145270001@hawaii-26.u.aloha.net>, colvin@aloha.net (Keith Warner Colvin) wrote:
The error message you are getting is a generic message generated by the server
when it can't sucessfully run the script. This can be cause by so many
different problems with the script that it is impossible to say what is wrong
just from the information you posted.
Right off the bat I would check these things that might cause the above error:
1) Make sure the file permissions are set correctly so the server has
access to and permision to run the script. Scripts should have at least read
and write permissions set on for the owner, group and possibly the world
(depending on what group your web server runs in). To set the permissions
correctly type;
chmod 755 scriptname.pl
at the command line.
2) Make sure your script does not contain any syntax errors by running
it on the command line. For better debuging run it with the -c switch, like
this;
perl -c scriptname.pl
If there is a syntax error the compiler will tell you what line it is
on.
3) Make sure the script got transfered to the server as a ASCII file
NOT a binary file. A binary transfer while FTPing the script to the server
will mess up the end-of-line characters...
>When I try to run my cgi this is what I get:
>
><HEAD><TITLE>Server Error</TITLE></HEAD>
><BODY> ...<SNIP>...
>
>This is where it is at:
>http://hele.com/cgibin/html_web_store.cgi?page=number.shtml&cart_id=
>
>How do I fix this server error and use the cgi the way I want it.
>
>Malama Pono....
+++++++++++++++++++++++++++
Curt Bousquet
http://www.webrover.com/ia/
$Email = (scanline\@+sover.net =~ s/+//g);
------------------------------
Date: 27 Feb 1997 14:46:27 -0800
From: Brett McCormick <brett@speedy.speakeasy.org>
Subject: Re: how long before I can put down the books?
Message-Id: <7v20a1j29o.fsf@speedy.speakeasy.org>
neilb@zetnet.co.uk (Neil S. Briscoe) writes:
> Still, I do now know a hell of a lot more about how the regex engine works
> than I did before Sunday. I can think of about 300 scripts that could
> probably be sped up considerably ... if only I had the time.
Is that info on the net anywhere? I don't have the new camel book but
would love to know!
------------------------------
Date: Thu, 27 Feb 1997 22:23:09 GMT
From: DeathToSpam@dev.null.com (Lee)
Subject: Re: How to spam - legitimately
Message-Id: <331608ff.1771930@news.earthlink.net>
The reason english is growing is due to its ready acceptance of words
from other languages. Here in the US, pizza, tacos, etc. are
considered a part of the language, but they didn't originate here<s>.
stijnvd@cwi.nl (Stijn van Dongen) wrote:
@>-->---Since there are many people on Usenet whose native tongue
(like mine :)
@>-->---is not English, probably the use of English on Usenet will be
affected
@>-->---by this. Are you willing to accept that, or do you want the
English
@>-->---language only to be bended in such a way that it sounds nice
to you,
@>-->---or some representative bunch of native speakers? --
disregarding for
@>-->---the time being the wide range of national and local English
varieties.
@>-->---It is rather interesting: while many languages are
experiencing
@>-->---Anglicist influences, they may even effect English itself in
this process.
@>-->---And it's always slightly more painful if this affects syntax
than if
@>-->---it affects the lexicon only :)
@>-->---On the other hand, it is always nice to learn from a native
speaker.
@>-->---It's the difference between viewing language development as a
process
@>-->---of aeons, and buying something in the grocery store (well,
make that
@>-->---a fancy warehouse).
@>-->---
@>-->--- Hope this helps :)
@>-->---
@>-->--- Stijn
@>-->--- stijnvd@cwi.nl
@>-->---
--Lee
Internet/Intranet Counsulting and Design:
http://www.designwest.com
Nurses' Call:
http://www.nurse.org/Nurses_Call/
------------------------------
Date: 28 Feb 1997 00:28:01 GMT
From: rgarg@rgarg-sun.us.oracle.com (Raman Garg)
Subject: Howto use open2()
Message-Id: <5f58qh$md7@inet-nntp-gw-1.us.oracle.com>
Hi,
I am trying to use the function open2 for opening both
STDIN & STDOUT of "rup" program for writing.
I need to pass a host list to "rup" & get the output but "rup"
starts executing & broadcasting on the network without waiting
for the STDIN .( That's what "rup" does when run w/o arguments).
How do I get "rup" to operate on my input host list using open2
or otherwise?
Please reply by email also.
Thx,
--
-------------------------------------------------------------------
Raman Garg Phone: (415)506-6044
Oracle Corporation Internet: rgarg@us.oracle.com
--------------------------------------------------------------------
Disclaimer: The opinions expressed above do not necessarily represent
those of my employer Oracle Corporation ( or for that matter my own :-)
------------------------------
Date: Thu, 27 Feb 1997 18:04:31 -0500
From: Bill Cowan <billc@tibinc.com>
To: yncera@ids2.idsonline.com
Subject: Re: need help
Message-Id: <331612FF.6F5C@tibinc.com>
yncera@ids2.idsonline.com wrote:
>
> If I put $Imput=<> it will wait there until I hit any keys follow by
> the enter key. How can I get only just one key without having to use
> the enter key. I am using Perl 5.
> Julio
Check out the getc() function.
-- Bill
-----------------------------------------------------------------------
Bill Cowan <billc@tibinc.com> Voice:919-490-0034 Fax:919-490-0143
Tiburon, Inc./3333 Durham-Chapel Hill Blvd Suite E-100/Durham, NC 27707
------------------------------
Date: Thu, 27 Feb 1997 19:21:24 -0500
From: John Strickler <jstrick@mindspring.com>
To: Shockwave Rider <shockwave.rider@worldnet.att.net>
Subject: Re: newbie question:manipulating strings
Message-Id: <33162504.3CE0072A@mindspring.com>
Or just:
$/ = undef; # make <> read til EOF
$_ = <>; # read entire file into $_ in one go
print join("\n",m/(.{20})/sg),"\n"; # print out 20-byte chunks one per
line
or, if you want to use them individually,
@chunks = m/(.{20})/sg; # each element of @chunks now contains a
20-byte chunk
Shockwave Rider wrote:
> $long_string="hjjuhasdfgjkhasdfkjghouiegzxkdv09e4568624545";
> $num=10;
>
> while ($long_string) {
> print ">$long_string\n";
> $long_string=~ s/(^.{0,$num})//;
> print ":$1\n";
> }
>
> >I want to take a very long one line string and break it up into lines of
> >20 characters each.
> >I've been able to do it using a very long and complicated looping process,
> >but I'm sure
> >there is a more efficient way.
> >
> >any input would be appreciated.
> >
> >thanks
> >-jon
> >
--
John Strickler -- Perl/UNIX/C Trainer, Consultant
Jeffersonian Consortium Voice: 919-682-3401
HTTP://WWW.JCINC.COM Facsimile: 919-682-3369
------------------------------
Date: Thu, 27 Feb 1997 13:16:36 -0800
From: "pnetwork@sbexpos.com" <pnetwork@sbexpos.com>
Subject: Newsflash: Progressive Networks' RealMedia Conference
Message-Id: <3315F9B4.157@sbexpos.com>
Newsflash: Marc Andreessen and Rob Glaser to deliver keynotes at the
RealMedia Conference
Netscape founder Marc Andreessen and Progressive Networks founder Rob
Glaser will each deliver keynote addresses at the RealMedia Conference
March 3-4 at the Hyatt Regency, San Francisco Airport. Glaser will speak
at 9:00 a.m. on March 3 and Andreessen will speak at 9:00 a.m. on March
4.
As a part of the RealMedia Conference, on the evening of March 3,
Atlantic Records recording artist Poe will headline a private concert
which will also be carried live over the Internet at
http://www.liveconcerts.com.
"The RealMedia Conference offers developers a training ground to learn
how to utilize this technology to create extraordinary applications and
content," said Rob Glaser, chairman and CEO, Progressive Networks.
"RealMedia gives developers the freedom to create compelling content and
gives end users the opportunity to experience multiple media types
including animation, audio and video, all in real time."
This is your last chance to register for the RealMedia Conference!
www.real.com/realdeveloper/conference/index.html
Sessions will help attendees learn how to create open standards-based
multimedia applications that utilize multiple data-types, such as audio,
animation, video and streaming text.
The registration fee is $695 and covers access to all keynote speeches,
exhibits, technology sessions and the hands-on computer lab as well as a
ticket to the private concert headlined by Atlantic Records recording
artist Poe. Continental breakfast and lunch each day of the conference
also are included.
Last Chance! Space is limited, so register today.
To register for the conference, call 1-800-765-3705, or register at
http://www.real.com/realdeveloper/conference/index.html.
What: Progressive Networks' RealMedia Conference
Where: Hyatt Regency San Francisco Airport
When: March 3-4, 1997
To Register:
visithttp://www.realaudio.com/realdeveloper/conference/index.html
or call 800-765-3705 (US) or 415-372-6705 (Int'l)
------------------------------
Date: Fri, 28 Feb 1997 00:56:24 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Optimizing nested loops
Message-Id: <E6AFy0.9IE@world.std.com>
alcornd@conterra.com (Doug Alcorn) writes:
>I have a script I am writing. It works, but it is slow IMO. I am new
>to perl, and am unexperienced at optimizing it. I would appreciate
>any pointers in how I can improve it.
This is the type of problem that screams for using a perl hash data
structure. Extract the "grade" section of the part number when reading
the data file and make that the key to the hash. For the value, have a
list of the parts that have the same grade. When looping through the
bill of materials, do one hash lookup on the grade, and retrieve the
list of matching parts. Then you can print out just those
parts. Something like this:
use integer; # probably doesn't do much since there is no math.
($bom_name, $part_num_name) = @ARGV;
open (PART_NUM_FILE, $part_num_name) or die "$0: Cannot open " .
"$part_num_name for read.\n";
while (<PART_NUM_FILE>) {
chomp;
($part_grade) = m/.{6}_(\d{4})\./; # can this be changed to substr($_,6,4)
# Add this part number to the
push @{$grade{$part_grade}}, $_;
}
close PART_NUM_FILE;
open (BOM_FILE, $bom_name) or die "$0: Cannot open $bom_name for read.\n";
while (<BOM_FILE>) {
($bom_grade, $bom_remainder) = split /~/, $_, 2;
foreach $part( @{$grade{$bom_grade}} ) {
print $part, $bom_remainder;
}
}
--
Andrew Langmead
------------------------------
Date: Thu, 27 Feb 1997 15:01:49 -0800
From: Michael Smith <mdsmith@qualcomm.com>
Subject: Re: Perl and win95
Message-Id: <3316125D.4DF0@qualcomm.com>
An addendum to this is that you don't need to worry about a web server
if you make it a Perl question.
Can I test cgi scripts without a WWW server?
Yes -- if you use CGI.pm. Check out CPAN for it. Well documented, and
well written.
-- Mike
Nathan V. Patwardhan wrote:
>
> Bas van Reek (basvreek@channels.nl) wrote:
> : I'm looking for a webserver that
> : makes it possible to run perl scrips
> : on a win95 machine.
>
> Ah, another server question disguised as a Perl question. :-)
> Perl != CGI. CGI is not a language.
>
> Your question would be properly answered in the www servers newsgroups,
> like comp.infosystems.www.servers.misc. You might also do a yahoo
> (or whatever) search for www servers, where you'll find a host of
> good PC-www products.
>
> HTH!
>
> --
> Nathan V. Patwardhan
> nvp@shore.net
> "Lane, I've been in high school for
> seven years. I'm no dummy"
> --Charles Demar from _Better Off Dead_
------------------------------
Date: 27 Feb 1997 14:49:51 -0800
From: Brett McCormick <brett@speedy.speakeasy.org>
Subject: Re: Perl as a shared library?
Message-Id: <7vzpwphnjk.fsf@speedy.speakeasy.org>
aml@world.std.com (Andrew M. Langmead) writes:
>
> Marius Kjeldahl <marius@funcom.com> writes:
>
> 5.003 is able to be built with libperl.a as a shared library. The
> Configure script didn't ask if you wanted it though, so you had to
> edit config.sh by hand.
Does anyone know how this can be done? I have many C programs linked
with perl, and would like to decrease the disk usage.. (they're very,
very, big)...
--brett
------------------------------
Date: Fri, 28 Feb 1997 12:40:33 +1100
From: Ira <ira@rta.nsw.gov.au>
Subject: Perl geomtetry
Message-Id: <33163791.41C6@rta.nsw.gov.au>
Does anyone have a Perl utility or code chunk that deals with 2d polygon
intersection?
I need a program that simply finds out if two polygons intersect. That's
all.
Help appreciated.
--
Ira Waxberg
Roads & Traffic Authority, NSW Australia
------------------------------
Date: 27 Feb 1997 15:18:14 -0800
From: Brett McCormick <brett@speedy.speakeasy.org>
Subject: Re: Perl Munitions T-Shirt
Message-Id: <7vybc9hm89.fsf@speedy.speakeasy.org>
d1temp@dtek.chalmers.se (Michael Tempsch) writes:
>
> In article <Pine.LNX.3.95.970224152240.396A-100000@neko.binary9.net>,
> "Nicholas J. Leon" <nicholas@binary9.net> writes:
> >
> >I hope this question is MISC enough for here. But could anyone point me
> >in the direction of a vendor that sells the Perl Munitions T-shirt? I'm in
> >the US, so export restrictions aren't a factor here.
>
> Take a look at http://www.dcs.ex.ac.uk/~aba/shirt/shirt.html
> Points to both US and non-US sources
I was unable to find any information at the 'Wepin Store' linked off
the page (the us supplier)... Any more info would be great, thanks!
--brett
>
> /Michael
> --
> | Linux: Turn on...Tune in...Fork out... |
> | Michael Tempsch, member of Ballistic Wizards, TIP#088, TDGP#20 |
> | d1temp@dtek.chalmers.se | [d1temp@hotmail.com] | [d1temp@bigfoot.com] |
> | Cell.Phone:+46 705487554 URL:http://www.dtek.chalmers.se/~d1temp |
------------------------------
Date: 27 Feb 1997 17:22:49 -0500
From: lab@slpabu.msd.ray.com (Leonhard Brenner {13031} 7149 [ ])
Subject: Regular Expressions problem please help!
Message-Id: <uqd7mjt7uti.fsf@slpabu.msd.ray.com>
I have a script that I am writing to search through a list of
files replacing:
<!--Generic_javascript-->
This will be replaced!
<!--Generic_javascript-->
with:
<!--Generic_javascript-->
Just some junk;
<!--Generic_javascript-->
$srcmarker is created alright but substitution does not work.
A have provided all files needed try this script. I have already
writen a working version loops and matching but I thought this
would be cleaner.
Thanks in advance Lenny Brenner<lab@caesun.msd.ray.com>
Generic.pl:
$hooks{'Generic_javascript'} = 'Generic_javascript.html';
$done = $found = 0;
foreach $FILE(@ARGV){
if ($FILE ne "Generic.pl"){
open OLDFILE, $FILE;
$file = join /\n/, <OLDFILE>;
foreach $src(keys(%hooks)){
$cmd = 'cat '.$hooks{$src};
$dst = `$cmd`;
$srcmarker = '<!--'.$src.'-->';
###Problem###
$file =~ s/($srcmarker).*($srcmarker)/$1$dst$2/;
}
print $file;
close OLDFILE;
}
}
main.html:
<HTML>
<HEAD><TITLE>##Sa_PROGRAM## ACTION ITEMS</TITLE></HEAD>
<BODY BACKGROUND="/backgrounds/chalk.gif">
##Sa_Header##
<!--Generic_javascript-->
This will be replaced!
<!--Generic_javascript-->
</HTML>
Generic_javascript.html:
Just some junk;
Command:
perl Generic.pl main.html > main.html.new
------------------------------
Date: Thu, 27 Feb 1997 17:26:50 -0800
From: Marty McDowell <oshmis1@pacbell.net>
Subject: Re: sometimes > not greater than?
Message-Id: <3316345A.1B95@pacbell.net>
Michael Sadd wrote:
>
> Nothing here surprised me. What you are seeing is that
> your machine has finite precision to represent floating point numbers.
> In some cases, what you think might be 5 will be represented as
> 5.000000...1, giving the false true values you noted.
>
> It is a general rule of numerical programming that your results
> should not be dependent on what a test does when a parameter
> is supposed to be exactly some number.
>
> Mike
>
> --
> | Michael Sadd | Cornell Univerisity |
> | Department of Physics and | Ithaca, NY 14850 |
> | Lab of Atomic and Solid State Physics | www.msc.cornell.edu/~sadd/ |
Ok, so even though I printed out the variable and it said '5', and
yes I have seen when perl prints 5.000000000001, its not really 5.
How would I do the comparison?
------------------------------
Date: Thu, 27 Feb 1997 23:20:16 +0100
From: uzs90z@uni-bonn.de (Michael Schuerig)
Subject: Substituting a bunch of strings
Message-Id: <19970227232016148303@rhrz-ts3-p4.rhrz.uni-bonn.de>
I've written a script that does replacements of multiple strings on a
directory sub-tree. The strings are read into a hash from a file (yes,
it should be an array...). Currently the script iterates over the hash
for each line in each file. And that's obviously not very efficient.
Is there a better and more "idiomatic" way to do the same?
Michael
---
Michael Schuerig I am the sum total of the
mailto:uzs90z@uni-bonn.de parts I control directly.
http://www.uni-bonn.de/~uzs90z/ -Daniel C. Dennett
------------------------------
Date: 27 Feb 1997 23:43:32 GMT
From: jvenu@ctp.com (Jagadeesh Venugopal)
Subject: Re: Unix Commands in Perl Script
Message-Id: <5f5674$dj@concorde.ctp.com>
In article <857074272.2942@dejanews.com> jimrsmith@unn.unisys.com writes:
>Okay, before I get the RTFM and RTFFaq's, I did that already.
>I am a brand new perl person, with some ksh backround, and I am just
>not comprehending the docs.
>How do I issue this command string from perl?
>echo $msg1 | /usr/local/pager -cfg_dir $cfg -user $who
>or this one:
>echo $datestamp : $msg1 > $errorlog
>
Can you post the code which you have tried to write so far? If you are
looking to start still please look at the Camel book, 2d edition, page
341-346, (for using pipes) and page 138, 404(for environment variables.)
Jag
--
/\/\ |Jagadeesh K. Venugopal, jvenu@ctp.com |http://w3.ctp.com/~jvenu
/ /_.\|Cambridge Technology Partners, Inc. |http://www.ccs.neu.edu/home/jkvg
\ /./|304 Vassar St. Cambridge, MA 02139 |
\/\/ |Phone: 617.374.2028 FAX: 617.374.8300 +
------------------------------
Date: Thu, 27 Feb 1997 23:48:46 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Windows95
Message-Id: <E6ACtA.KGr@world.std.com>
stampes@xilinx.com (Jeff Stampes) writes:
>there is no perl for DOS...
As another poster mentioned, there is a perl 4 for ms-dos.
Also, for perl 5, what is frequently called the OS/2 port
<http://www.perl.com/CPAN/ports/os2/> will also work under MS-DOS. (It
uses the EMX extender, and there are versions of the extender for
MS-DOS, OS/2, Window 3.1, and Win32.)
There are setup instructions for MS-DOS in
<http://www.cs.ruu.nl/~piet/perl5dos.html>
--
Andrew Langmead
------------------------------
Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Jan 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.
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 27
************************************