[11208] in Perl-Users-Digest
Perl-Users Digest, Issue: 4808 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 2 16:07:23 1999
Date: Tue, 2 Feb 99 13:00:22 -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, 2 Feb 1999 Volume: 8 Number: 4808
Today's topics:
Re: are regular expression rationaly designed ? (Tad McClellan)
Re: are regular expression rationaly designed ? <kenhirsch@myself.com>
Calling perl from C code on NT (sjm)
Re: Changing drives with ActiveState Perl on NT <jeff@vpservices.com>
Re: Check if a file is open dturley@pobox.com
Re: code to recurse directories dturley@pobox.com
Re: Counting child processes? <usenet-replies@rocketmail.com>
finding path to perl executable mlevine@reshape.com
Re: flock not working (Charles DeRykus)
Re: grep and a variable <ebohlman@netcom.com>
Re: grep and a variable <berg98@us.ibm.com>
Re: i may be stupid <jon@jonstuff.force9.co.uk>
Re: Is there an Interactive Debugger for Perl? (Tad McClellan)
Re: newbie having trouble with concatination (Tad McClellan)
Re: perform a su - [user] in perl <cdkaiser@delete.these.four.words.concentric.net>
Re: Perl Criticism topmind@technologist.com
Question about File::Find <gbc1@axe.humboldt.edu>
Re: Question about File::Find <ebohlman@netcom.com>
Re: Request for negative value list indexes (Matthew Bafford)
shell command in perl <mgcook@ic.delcoelect.com>
Re: Soft reference question (Thanks!) (Lou Hevly)
STDOUT redirect on NT <pcs@aw.sgi.com>
Re: substituting keywords in a string (Tad McClellan)
UNIX 'tail' command in Perl?? <psmith01@mindspring.com>
Re: UNIX 'tail' command in Perl?? <uri@ibnets.com>
Re: UNIX 'tail' command in Perl?? <psmith01@mindspring.com>
Re: Visual Perl? (Bart Lateur)
Re: Visual Perl? <design@raincloud-studios.com>
Re: web load testing code (Randy Kobes)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 2 Feb 1999 13:25:42 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: are regular expression rationaly designed ?
Message-Id: <mfj797.cq4.ln@magna.metronet.com>
olivier_pelletier@my-dejanews.com wrote:
: I would like to know if there is a theory hidden behind regular expression
: matching ?
Yes there is.
The broad name for the study of such things is "Formal Methods".
The primary parts of Formal Methods that apply to regexen are
"Regular Grammar" and "Finite State (Automata|Machine)"
(aka: FSA, DFA, NFA...).
: Could anyone point me out a link to a document explaining this
: theory if it exists ?
I don't know of any off hand, but you should be able to
glean some useful search engine terms from the above.
Or get a textbook that mentions any of:
Formal Methods
Formal Languages/Grammars
Parsing/Compiling
The most famous book on such things is probably the "Dragon Book",
so named because of the picture on the cover.
The title is something like "Compilers: Principles, Tools and
Techniques" by Aho, Sehti, Ullman
: In particular can any pattern be matched by a regular
: expression ?
No. (assuming you really meant to ask: "can any grammar
be matched by a regular expression").
Only Regular Grammars can be matched by a regular expression.
Regular grammars are the simplest of the four levels of
grammars in the Chomsky hierarchy.
You need a technique more powerful than regular expressions
to part the more powerful grammars.
(Patterns cannot be matched by regular expressions. You have
your terminology messed up. Strings (actual sequence of
characters) are matched by a pattern or regular expression.
)
Note that regular expressions in Perl are not equivalent
to Regular Expressions in the literature, since they have
memory (back references) and thus violate the formal
definition of Regular Expression.
To get the most "bang for the buck" in regards to understanding
the insides of pattern matching, concentrate on state machines.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 2 Feb 1999 14:42:56 -0500
From: "Ken Hirsch" <kenhirsch@myself.com>
Subject: Re: are regular expression rationaly designed ?
Message-Id: <797k96$ct2$1@oak.prod.itd.earthlink.net>
Ilya Zakharevich wrote:
[...]
>Since Perl's RExen can do anything now (well, between 5.005 and
>5.005_53 they could do *many* things), if the pattern is decidable,
>they can do it. They cannot recognize a correct C program which loops
>forever. ;-)
>
>Ilya
Oh yeah, how about:
if (/\Qmain(){while(1);}/) {
print "This program loops forever!\n";
}
;-) back at ya!
Ken Hirsch
(With the slightly serious point that theory says you cannot always
recognize programs that loop forever, not that you can never recognize
them.)
------------------------------
Date: 2 Feb 1999 11:40:11 -0800
From: sjm@halcyon.com (sjm)
Subject: Calling perl from C code on NT
Message-Id: <797kar$ntm$1@halcyon.com>
Hello, all,
I've got ActiveState build 509. From what I see in the FAQs,
ActiveState's version is appears to be the "blessed" Win32 version, at
least for binary distributions.
I am looking at building perl into a C program that will have to run on
at least 3 Unix flavors and also NT. The Unix part is well documented
and easily accomplished by this Unix-slanted scribe.
On NT, however, even after 2 hours of trolling around perl.com and
activestate.com, it is not obvious to me which is the "right"(tm) way to
build a basic example. Which libraries to link in?
perlcapi.lib?
perlcore.lib?
perlcrt.lib?
perlez.lib?
All? Some?
Would it just be better to compile the source myself? (I was hoping not
to have to do this, but I will.)
Pointers to more accurate docs appreciated...
--
-- Steve McCarthy Author RightOn 2.4 for Windows
sjm@halcyon.com The Power Mouse Utility
http://www.halcyon.com/sjm/righton.html
Current wind and temp at my house: http://www.halcyon.com/sjm/wx/latest.html
------------------------------
Date: Tue, 02 Feb 1999 11:30:01 -0800
From: Jeff Zucker <jeff@vpservices.com>
To: Phil Tomson <ptkwt@user2.teleport.com>
Subject: Re: Changing drives with ActiveState Perl on NT
Message-Id: <36B75239.17F74651@vpservices.com>
[emailed and posted]
Phil Tomson wrote:
> We're starting a perl script on drive C: (for example) and at
> some later time we want to move the current working directory
> to a networked drive, drive F:, for example, and perform some
> operations there.
Let's say you start a script in c:\temp and that f:\utils is your
current working directory on drive f:.
# [start script] # current working directory is c:\temp\
chdir('f:') || die $!; # current working directory is f:\utils\
chdir('/') || die $!; # current working directory is f:\
# [exit script] # current working directory is c:\temp\
HTH
--
Jeff Zucker \/ mailto:jeff@vpservices.com
Co-coordinator -<>- http://www.unicef.org/voy/
UNICEF Voices of Youth /\ http://www.vpservices.com/jeff/
------------------------------
Date: Tue, 02 Feb 1999 19:55:07 GMT
From: dturley@pobox.com
Subject: Re: Check if a file is open
Message-Id: <797l6m$meb$1@nnrp1.dejanews.com>
In article <36b5bbe0@csnews>,
tchrist@mox.perl.com (Tom Christiansen) wrote:
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc,
> "Dan Albertsson" <dan@albertsson.com> writes:
> :PS. Can someone recomend reading of locking techniques in multiuser
> :environments.
>
> Normally, you just use flock(). The Perl Cookbook shows many examples
> of using this, as well as an example of using fcntl and another that uses
> stateful directory-based locking.
these sections and the one on opening files alone are worth the "price of
admission."
--
____________________________________
David Turley
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 02 Feb 1999 20:04:57 GMT
From: dturley@pobox.com
Subject: Re: code to recurse directories
Message-Id: <797lp2$muu$1@nnrp1.dejanews.com>
In article <m3emobz2ha.fsf@joshua.panix.com>,
Jonathan Feinberg <jdf@pobox.com> wrote:
> grynberg@hotmail.com (sysop) writes:
>
> > Hi. I am trying to write a program to print all the files on my hard
> > drive, with their complete paths. I was wondering if anyone has
> > anything like this.
>
> Sure, File::Find makes this a snap.
After looking at my already well-worn "Perl Cookbook", I'm thinking, perhaps
there should be an addition to the "read the faq" reply. How about "rtcb"?
--
____________________________________
David Turley
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 02 Feb 1999 13:58:17 -0500
From: Debbie Whitten <usenet-replies@rocketmail.com>
Subject: Re: Counting child processes?
Message-Id: <36B74AC9.433CF835@rocketmail.com>
Here's what I've done in the past:
At the beginning of my script I defined:
$num_children = 40; # define the max no. of children
$SIG{CHLD} = 'handler'; # run the handler sub to
# prevent zombies when a
# child exits
(I hope tabs come out OK)
Now, in the body of the program I had this:
$forked = 0;
$forks_returned = 0;
# The while loop will execute while there are more than 40
# children running, thus preventing more children from being
# uh, born ;-)
while (($forked - $forks_returned) > $num_children) { };
$pid = fork();
if (defined ($pid)) {
# forked a new child, increment counter
$forked++;
}
if ($pid == 0) {
# child code goes here
exit(0); # end of child
}
The handler sub looks like this:
sub handler {
local ($sig) = @_;
wait;
$forks_returned++;
$SIG{CHLD} = 'handler';
}
Now if only I could get my head around flock!!!
Hope this helps,
Deb
rupert@no.spam.leeds.ac.uk wrote:
> > Hello all, I'm in need of some good ideas. What I want to do is to
> > have a forking server count its subprocesses (for load control
> > reasons).
>
> I am needing to do the same thing for the same reason and I cannot
> seem to get it right.
>
> Perhaps the problem is one of zombies accumulating because multiple
> child processes need reaping when you receive SIGCHLD.
------------------------------
Date: Tue, 02 Feb 1999 19:52:05 GMT
From: mlevine@reshape.com
Subject: finding path to perl executable
Message-Id: <797l10$m48$1@nnrp1.dejanews.com>
Can anyone tell me how to find the path to the perl executable I am running?
IE, from inside script foo, I'd like to be able to find out that it was run
from /usr/local/bin/perl.
Thanks!
- Margie
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 2 Feb 1999 20:19:34 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: flock not working
Message-Id: <F6Jn4M.79B@news.boeing.com>
In article <36B730EC.37909F1@rocketmail.com>,
Debbie Whitten <usenet-replies@rocketmail.com> wrote:
>I've read the book, and I am trying to implement flock. Why can't I
>understand this? Am I missing something? Here is the script I wrote to
>test flock'ing. I am trying to get an exclusive lock on a file. I run
>the script and the file is supposed to stay locked until I type a u.
>
>While the file is locked, I run the script a 2nd time. I expect the 2nd
>script to wait - the file should be locked. But it does not wait - it
>goes ahead and 'locks' the file in exclusive mode. Shouldn't this be
>impossible?
>
>#!/usr/local/bin/perl -w
>use FileHandle;
>$| = 1;
>$LOCK_SH = 1;
>$LOCK_EX = 2;
>$LOCK_NB = 3;
>$LOCK_UN = 4;
>open FH, ">> test.txt";
>FH->autoflush(1);
>print "Locking file.";
>while (($x = flock ("test.txt", $LOCK_EX))) { # supposedly wait
^^^^^^ ^^^^^^^^^^
until flock FILEHANDLE,OPERATION
hth,
--
Charles DeRykus
------------------------------
Date: Tue, 2 Feb 1999 20:19:11 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: grep and a variable
Message-Id: <ebohlmanF6Jn3z.1xy@netcom.com>
jimbob4334@my-dejanews.com wrote:
: Can someone tell me how to use
: grep on the following?
: @date - is an array with many dates including 1-12-98
: $var="1-12-98";
: @match = grep(/\Q$var\E/, @date);
: $no_of_mathces = $#match;
: I get $no_of_matches = -1
That's correct, but your variable name is misleading. $#array is not the
number of elements in @array; it's the index of the last element in
@array. For zero-based arrays, the index of the last element will be one
less than the number of elements. So if you have no matches, there will
be 0 elements in the returned array, and one less than zero is -1.
Methinks a trip to your friendly neighborhood perldata (man page | HTML
page | .pod file) is in order for you.
------------------------------
Date: Tue, 02 Feb 1999 15:20:16 -0500
From: "Shawn A. Berg" <berg98@us.ibm.com>
Subject: Re: grep and a variable
Message-Id: <36B75E00.46F77F07@us.ibm.com>
You have a typo: $no_of_mathces = $#match;
jimbob4334@my-dejanews.com wrote:
> Can someone tell me how to use
> grep on the following?
> @date - is an array with many dates including 1-12-98
> $var="1-12-98";
> @match = grep(/\Q$var\E/, @date);
> $no_of_mathces = $#match;
>
> I get $no_of_matches = -1
>
> TIA,
>
> Jim
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 2 Feb 1999 20:18:41 -0000
From: "jon" <jon@jonstuff.force9.co.uk>
Subject: Re: i may be stupid
Message-Id: <c6Jt2.21154$%3.1542@wards>
it now works fine thanks again for the help
cheers
jon
------------------------------
Date: Tue, 2 Feb 1999 13:26:37 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Is there an Interactive Debugger for Perl?
Message-Id: <dhj797.cq4.ln@magna.metronet.com>
Ban Spam Now (no_spam@no_spam.com) wrote:
: I am learning Perl and am used to languages which have an interactive
: debugger. At the moment I'm putting print statements everywhere. Is there
: an Interactive Debugger for Perl, or a slicker way than using prints?
perldoc perldebug
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 2 Feb 1999 13:06:27 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: newbie having trouble with concatination
Message-Id: <jbi797.cq4.ln@magna.metronet.com>
Gavin Ian Andrew Kenny (eem3gk@ee.surrey.ac.uk) wrote:
: Part of the problem is that lines are longer than
: a single line.
That sentence is nonsense.
It contradicts the definition of line.
You must have meant:
"(records | fields | the parts I'm interested in) are
longer than a single line."
: So I wrote the following code to go through the file line by line
: and put all the lines I'm interested in, into a single string so I could
: then split it up
: and count things.
That code does not deal with multiple lines.
So I assume that it is inside of a loop that you are not
showing us.
: $line =~ /\s*(\S+.*)$/; # this gets rid of tab at the start and \n
: at # the end
If you write it in more idiomatic Perl it becomes so
self-documenting that comments become superfluous:
chomp $line; # so long trailing newline
$line =~ s/^\t//; # so long leading tab
: $clean_line = $1;
You don't need to copy it to a temp variable if you are going
to use it before any more pattern matches. You can just use
$1 directly in your join().
Of course, if you take my suggestions above, then $line
will contained the cleaned up line instead of $1.
: $port = join ' ',$port,$clean_line; # $port is an earlier line "cleaned"
: # in exaclty the same way.
The usual way to do concatenation in Perl is with the
concatenation operator :-)
$port = $port . " $line";
or, the same thing written in shorthand:
$port .= " $line";
: The trouble is, instead of the new $port being a concatenation of the
: two strings, it just overlays them one on top of the other and makes
: a right mess.
: can anyone point out where I'm going wrong
Hard to tell since you haven't shown us your loop, but I
expect you are forgetting to "clear" $port when you are
finished with it and before you start building up a new one.
Add
$port = '';
at the end of the loop.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 02 Feb 1999 12:29:00 PST
From: Cameron Kaiser <cdkaiser@delete.these.four.words.concentric.net>
Subject: Re: perform a su - [user] in perl
Message-Id: <797n6c$5k5@journal.concentric.net>
Jack Houghton <jehoughton@itd.ssb.com> writes:
>I have a perl script that is run as root. In this script I need to su to
>another user and stay as that user until the script completes. I
>basically do not want create any files owned by root. One soolution
>would be to run the script with su - [user] but that is not possible.
>This script is invoked by a parent process. I have looked at the
>dotsh.pl routine but this offers no more assistance. If I use system()
>the program simply changes to the user in the shell and closes the
>shell. This does me no good.
Investigate the $<, $>, $( and $) variables. They may do what you want, and
don't involve the expensive system() call.
--
Cameron Kaiser * cdkaiser.cris@com * powered by eight bits * operating on faith
-- supporting the Commodore 64/128: http://www.armory.com/~spectre/cwi/ --
head moderator comp.binaries.cbm * cbm special forces unit $ea31 (tincsf)
personal page http://calvin.ptloma.edu/~spectre/ * "when in doubt, take a pawn"
------------------------------
Date: Tue, 02 Feb 1999 19:55:50 GMT
From: topmind@technologist.com
Subject: Re: Perl Criticism
Message-Id: <797l80$mft$1@nnrp1.dejanews.com>
.
Reply to Sam Holden (2 msgs):
>> Name a language that passes variable length arrays and hashes around without
using pointers, the language would have to allow both pass by reference and
pass by value of course. <<
Are you talking about IMPLEMENTING them into the
language or using them?
Most languages pass explicit arrays by reference,
but pointer syntax is not needed. Example:
array a[*,*]
a[1,2] = "this"
mysub(a)
show a[1,2] // result: "that"
...
sub mysub(p)
p[1,2] = "that"
endsub
One does not have to use "\" operators to pass them.
>> Name an OO language that doesn't use pointers. <<
It may depend on one's definition of pointers, but Java
has no direct pointers. It is true that if you
assign an object reference to another, then you
have something similar to an address of the object
instead of its value, but one can never directly
access the memory address.
No "\" equiv. in Java.
(BTW, I am not a fan of OOP anyhow, so I don't
care about whether OO languages
use or need pointers or not.)
>> Name a language that uses by-reference semantics without using references. <<
I am not sure what you mean by "semantics".
>> Of course a little evidence
on your part for you statements would be a novel idea. <<
I am not the one who claimed they are necessary, so
I cannot provide the evidence. You would have to
tell me exactly what you use them for and I could
then show you an alternative.
>> References are useful in Perl because they enable the efficient construction
of dynamic data structures that make code more efficient and more readable. <<
Efficient perhaps, readable, no.
>> That way instead of having pages and pages of if elses, or cases you have
simple readable code that lets the data structure handle the special cases.
I think it's generally called encapsulation which most consider a good
thing. <<
I am not sure what you mean by "pages and pages of if elses".
An example would be nice.
>> I have asked simple things like this before and you haven't bothered
answering. <<
What do you mean "like this"? I have not purposely
ignored (not replied to) any request unless it was personal.
There were cases when I had no examples of bad production
Perl code to show you, but I stated that. (And why you
did not accept signitures as evidence I don't know.)
>> References are one of the most powerful constructs in procedural
programming. <<
Example?
>> You can
claim all you want that you don't need them but if you do you are simply
wrong. Take a graph for example, each node can have 0 or more edges which
lead to other nodes. If you didn't have references how would you point
to those other nodes? <<
Indexed Relational Tables! That is how. They also provide
auto-persistence, something RAM-oriented people struggle with.
Take this simple graph (view with a fixed-pitch font
such as Courier)
A ---- B
|-- C ----- F --- A [circular]
|-- D |-- G
|-- E
Here are at least two ways to represent graph and tree
structures with tables:
The first method has a finite branching limitation
that depends on the field-size of ChildrenList, but
it is simple to implement:
NodeID Value ChildrenList
A x B, C, D, E
C x F, G
F x A
B x
D x
E x
G x
NodeID would be indexed for fast traversals.
Note that this example is a directional graph.
The second method is more complex, but does not
have a branching limit (other than disk space):
LinkTable
NodeID Link
A B
A C
A D
A E
C F
C G
F A
NodeTable
NodeID Value
A x
B x
C x
etc...
Note that implementing this using SQL API's is not very
pleasant, but doable. That is why I am promoting
table-oriented languages that have more table-friendly
syntax.
Also, I don't think trees and graphs are the most
common use of "\" anyhow in Perl. My observation
is that they are mostly used to overcome the
1D array limitation and parameter passing
limitations of Perl. This observation is not at all
scientific nor thorough, so you are welcome to
challenge it.
It is not the fact that Perl has explicit pointers,
it is that they are overused because they appear
to compensate for weaknesses.
-tmind-
http://www.geocities.com/SiliconValley/Lab/6888/
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 02 Feb 1999 12:01:41 -0800
From: Greg Coit <gbc1@axe.humboldt.edu>
Subject: Question about File::Find
Message-Id: <36B759A5.4FC6CA10@axe.humboldt.edu>
Hello folks,
File::Find works great for me with one small glitch. While traversing
through directories, I have it print to a file the name of each
directory. No problem, except, the list is not in alpha order (or any
other order I can think of). The directory names are one word, no
numbers or spaces or underscores (I'm using Digital Unix 4.0d, Perl
5.00502, and a recent, but unknown version number, of File::Find). I've
looked in the documentation that came with File::Find, but no info
there. Is this a common problem? Any idea what causes it?
Thanks for any ideas and/or help,
Greg Coit
gbc1@axe.humboldt.edu
------------------------------
Date: Tue, 2 Feb 1999 20:22:45 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Question about File::Find
Message-Id: <ebohlmanF6Jn9x.2BD@netcom.com>
Greg Coit <gbc1@axe.humboldt.edu> wrote:
: File::Find works great for me with one small glitch. While traversing
: through directories, I have it print to a file the name of each
: directory. No problem, except, the list is not in alpha order (or any
: other order I can think of). The directory names are one word, no
: numbers or spaces or underscores (I'm using Digital Unix 4.0d, Perl
: 5.00502, and a recent, but unknown version number, of File::Find). I've
: looked in the documentation that came with File::Find, but no info
: there. Is this a common problem? Any idea what causes it?
The reason is that the filesystem doesn't actually store filenames in
alphabetical order, and File::Find simply does a bunch of readdir()'s to
get the filenames in whatever order the filesystem wants to give them out
in. Directory programs like ls sort the list of filenames they get from
the filesystem; if you need a sorted list you need to do the same thing.
------------------------------
Date: Tue, 02 Feb 1999 19:19:49 GMT
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Request for negative value list indexes
Message-Id: <slrn7bejnl.n3.dragons@Server.Network>
On Tue, 02 Feb 1999 14:23:53 GMT, droby@copyright.com <droby@copyright.com>
wrote:
-> In article <1dmi8rr.buk54m1olrdxmN@bay2-74.quincy.ziplink.net>,
-> rjk@linguist.dartmouth.edu (Ronald J Kimball) wrote:
-> > Bart Lateur <bart.lateur@skynet.be> wrote:
-> >
-> > > A) add an extra special variable, that acts as $#ary, but for the list
-> > > you're trying to take a slice off; for exampl $#. ; $#_ is already in
-> > > use for the array @_ .
-> >
-> > And $#. is already in use for the array @. . ;-)
-> >
->
-> Not on my my machine.
$#{.}
--Matthew
------------------------------
Date: Tue, 02 Feb 1999 09:23:25 -0800
From: "Micah G. Cook" <mgcook@ic.delcoelect.com>
Subject: shell command in perl
Message-Id: <36B7348D.69EB@ic.delcoelect.com>
I have a command that works great in my tcshell but will not work
in perl.
shell command = cat auto.users | egrep -e '/mgsmith$'
this will give me the
host:/local_user/mgsmith
line out of the file.
Now if i do this in perl
$name = mgsmith ;
how do i get
$map_loc = the shell command?
where $name is substituted where mgsmith resides.
Having problems with the 's and the $ which indicates end-of-line
in the shell
------------------------------
Date: Tue, 02 Feb 1999 19:55:42 GMT
From: lou@visca.com (Lou Hevly)
Subject: Re: Soft reference question (Thanks!)
Message-Id: <36b75820.850019@news.jet.es>
louie@visca.com (Louie) [Now lou@visca.com (Lou Hevly)] wrote:
My thanks to both Lary and Johnatan. I'd cobbled together the script
from a couple sources and now see what a mess it was (I suppose it
goes without saying I'm a beginner). It's a measure of how forgiving
Perl is that it worked at all. How 'bout this for a nice simple upload
script?
#!/usr/local/bin/perl -w
use strict;
use CGI;
my $q = new CGI;
my $file = $q->param('file');
my $upload_dir = '/www/upload';
(my $filename = $file) =~ s/^.*?([^\\\/]+)$/$1/;
my $upload_file = "$upload_dir/$filename";
open FILE, $file or die "Can't read $file: $!";
undef $/;
my $file_lines = <FILE>;
close FILE or die $!;
open (UPLOAD, ">$upload_file") or die "Can't create $upload_file: $!";
print UPLOAD $file_lines;
close UPLOAD or die $!;
exit;
Again, thanks for the pointers.
Lou Hevly
http://www.visca.com
------------------------------
Date: Tue, 02 Feb 1999 12:43:57 -0800
From: Peter Slaughter <pcs@aw.sgi.com>
Subject: STDOUT redirect on NT
Message-Id: <36B7638C.12C4ACBD@aw.sgi.com>
Is is possible to redirect STDOUT to a file on NT?
If I have the following one line program 'test.pl'
print "Something\n";
then I should be able to redirect output to a file with the
command
test.pl > out.txt
A zero line 'out.txt' file is created.
I'm using perl 5.003_07, NT 4.0.
Thanks
------------------------------
Date: Tue, 2 Feb 1999 12:44:26 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: substituting keywords in a string
Message-Id: <a2h797.cq4.ln@magna.metronet.com>
Jason Q. (pigs_can_fly@mindless.com) wrote:
: mgjv@comdyn.com.au (Martien Verbruggen) wrote:
: >Use \b in your regexp
: Like that?
: $string =~ s/\b($_)\b/<font color=darkred>$1<\/font>/gi;
Yes.
: if keywords included "font", "color" or "darkred", my problem would still be there, wouldn't it?
Yes.
If
1) you use the suggestion in one of the other followups
where you check for _all_ of the words with one s///g
and
2) there are no <font> tags in the data you are operating on
Then
Your problem is solved.
If 'font', 'color', etc is already in your data, then you
still have a (much harder) problem.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 02 Feb 1999 15:27:31 -0500
From: Peter Smith <psmith01@mindspring.com>
Subject: UNIX 'tail' command in Perl??
Message-Id: <36B75FB3.9594626@mindspring.com>
I have a 650MB text file with 162,000 recortds that I need to do
something with - I haven't yet been able to open with Access/Excel/etc.
Soooooo, I thought I might be able to chop it up using the tail
command. I don't have access to a UNIX box, however.
So I need an efficient tail command so I can chop off the last x
thousand records. How do I use Perl to get the last 10 records?
open(FILE,"<mybigfile");
seek(eof); //??
read backwards??
Thanks for any hints!
------------------------------
Date: 02 Feb 1999 15:32:47 -0500
From: Uri Guttman <uri@ibnets.com>
To: Peter Smith <psmith01@mindspring.com>
Subject: Re: UNIX 'tail' command in Perl??
Message-Id: <39aeywfswg.fsf@ibnets.com>
>>>>> "PS" == Peter Smith <psmith01@mindspring.com> writes:
PS> I have a 650MB text file with 162,000 recortds that I need to do
PS> something with - I haven't yet been able to open with
PS> Access/Excel/etc. Soooooo, I thought I might be able to chop it
PS> up using the tail command. I don't have access to a UNIX box,
PS> however.
PS> So I need an efficient tail command so I can chop off the last x
PS> thousand records. How do I use Perl to get the last 10 records?
PS> open(FILE,"<mybigfile"); seek(eof); //?? read backwards??
PS> Thanks for any hints!
i am publishing a module which reads a file backwards by line. it is
alpha/beta code but you can use it if you want. it is at
http://www.sysarch.com/perl/Backwards.pm
the name will probably change when it goes into cpan.
now a question for you, do you want to read the last lines or delete
them? my module is for reading them. you mention chop? why don't you
just read forward until you want to stop an write those records to
another file. or use the doubel loop recipe that tom c. has posted which
reads the file once and builds a list of line indexes. you then can find
line n, seek to it or truncate at that size.
hth,
uri
--
Uri Guttman Hacking Perl for Ironbridge Networks
uri@sysarch.com uri@ironbridgenetworks.com
------------------------------
Date: Tue, 02 Feb 1999 15:58:00 -0500
From: Peter Smith <psmith01@mindspring.com>
Subject: Re: UNIX 'tail' command in Perl??
Message-Id: <36B766D8.69686E1E@mindspring.com>
> i am publishing a module which reads a file backwards by line. it is
> alpha/beta code but you can use it if you want. it is at
> http://www.sysarch.com/perl/Backwards.pm
thanks, I'll check it out!
>
> the name will probably change when it goes into cpan.
>
> now a question for you, do you want to read the last lines or delete
> them? my module is for reading them. you mention chop? why don't you
> just read forward until you want to stop an write those records to
> another file. or use the doubel loop recipe that tom c. has posted which
> reads the file once and builds a list of line indexes. you then can find
> line n, seek to it or truncate at that size.
sorry, I wasn't too clear on that. actually, I wanted to read
backwards and chop, or some combo in between. I'm just looking for
the most efficient way to get the file into a usable format for
my biz folks. I'll check out tom c.'s recipe also...I also have a
program called Data Junction which may also help...
thanks again!
------------------------------
Date: Tue, 02 Feb 1999 19:46:54 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Visual Perl?
Message-Id: <36b755e5.577316@news.skynet.be>
Martien Verbruggen wrote:
>> Yeah, this reminds me of a popular program called GirlFriend 1.0. It
>> doesn't always know what you want either. But then again, I don't think
>> it is a Perl Script.
>
>I upgraded mine to Wife 1.0. Works a lot better :)
The problem is that the Wife module and the GirlFriend module don't work
too well together.
Bart.
------------------------------
Date: 2 Feb 1999 20:38:13 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: Visual Perl?
Message-Id: <797nnl$5rd@bgtnsc02.worldnet.att.net>
>>> Yeah, this reminds me of a popular program called GirlFriend
1.0. It
>>> doesn't always know what you want either. But then again, I
don't think
>>> it is a Perl Script.
>>
>>I upgraded mine to Wife 1.0. Works a lot better :)
>
>The problem is that the Wife module and the GirlFriend module
don't work
>too well together.
use Creative::lies;
------------------------------
Date: 2 Feb 1999 20:10:12 GMT
From: randy@theory.uwinnipeg.ca (Randy Kobes)
Subject: Re: web load testing code
Message-Id: <slrn7benfh.hic.randy@theory.uwinnipeg.ca>
On Tue, 02 Feb 1999 13:30:16 -0500, Tom Bates <ctbates@tva.gov> wrote:
>Is anyone aware of any published perl code or modules out there for load
>testing a web server?
Hi,
Issue 8 of the Perl Journal (www.tpj.com) had an article by
Lincoln Stein about torture testing web servers - the code described
in this article is available at this site.
--
Best regards,
Randy Kobes
Physics Department Phone: (204) 786-9399
University of Winnipeg Fax: (204) 774-4134
Winnipeg, Manitoba R3B 2E9 e-mail: randy@theory.uwinnipeg.ca
Canada http://theory.uwinnipeg.ca/
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 4808
**************************************