[19478] in Perl-Users-Digest
Perl-Users Digest, Issue: 1673 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 31 21:05:27 2001
Date: Fri, 31 Aug 2001 18:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <999306307-v10-i1673@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 31 Aug 2001 Volume: 10 Number: 1673
Today's topics:
Bug or silly mistake? (D. Stevenson)
Re: Bug or silly mistake? <vmurphy@Cisco.Com>
Re: Bug or silly mistake? (F. Xavier Noria)
Re: Bug or silly mistake? <cberry@cinenet.net>
Re: Bug or silly mistake? <jurgenex@hotmail.com>
Re: Calling sub funcs with scalar variables? (Charles DeRykus)
Re: Calling sub funcs with scalar variables? <uri@sysarch.com>
Re: Check for valid hex value <gnarinn@hotmail.com>
filetest (Newbie)
Re: filetest (Malcolm Dew-Jones)
Re: How to copy files in Perl and more <rsherman@ce.gatech.edu>
Re: How to copy files in Perl and more <krahnj@acm.org>
Re: How to copy files in Perl and more (Tad McClellan)
Re: How to copy files in Perl and more (Tad McClellan)
Re: multithreaded LWP <gnarinn@hotmail.com>
Re: Open 2 exes from Perl <kevin@vaildc.net>
Re: registration worries (Mr. Green)
Re: Running multiple procedures simultaneously (Newbie)
script to get varying strings into quotes (PM WONG)
Re: script to get varying strings into quotes <krahnj@acm.org>
Re: script to get varying strings into quotes <cberry@cinenet.net>
Re: script to get varying strings into quotes (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 31 Aug 2001 16:29:22 -0700
From: stevenson.20@nd.edu (D. Stevenson)
Subject: Bug or silly mistake?
Message-Id: <878e2749.0108311529.7b27da92@posting.google.com>
Please help! I can't figure out how to fix a problem. What it
finally came down to after stripping down my program is that the
following program seems to be telling me that "Inf" contains no
letters. Am I just being stupid, or could this be a bug? It looks
like the university where I work is using perl 5 or 5.6, I'm not sure.
It doesn't matter if I'm just being stupid; I just need to know.
Thanks.
-------
#!/usr/local/bin/perl
$variable = "Inf";
if ($variable != /a-zA-Z/) {
print "$variable does not have letters.\n";
}
------------------------------
Date: 31 Aug 2001 19:38:07 -0400
From: Vinny Murphy <vmurphy@Cisco.Com>
Subject: Re: Bug or silly mistake?
Message-Id: <m366b3reao.fsf@vpnrel.cisco.com>
stevenson.20@nd.edu (D. Stevenson) writes:
> Please help! I can't figure out how to fix a problem. What it
> finally came down to after stripping down my program is that the
> following program seems to be telling me that "Inf" contains no
> letters. Am I just being stupid, or could this be a bug? It looks
> like the university where I work is using perl 5 or 5.6, I'm not sure.
> It doesn't matter if I'm just being stupid; I just need to know.
> Thanks.
>
> -------
> #!/usr/local/bin/perl
>
> $variable = "Inf";
>
> if ($variable != /a-zA-Z/) {
> print "$variable does not have letters.\n";
> }
As Maxwell Smart would say: "Missed by that much..."
if ($variable !~ /[a-zA-Z]/ ) {
print "$variable does not have letters.\n";
}
else {
print "found something\n";
}
look at perldoc perlre and perldoc perlop for more details.
--
Vinny
------------------------------
Date: 31 Aug 2001 23:34:21 GMT
From: fxn@retemail.es (F. Xavier Noria)
Subject: Re: Bug or silly mistake?
Message-Id: <9mp6tt$2049s2@news1s.iddeo2.es>
On 31 Aug 2001 16:29:22 -0700, D. Stevenson <stevenson.20@nd.edu> wrote:
: Please help! I can't figure out how to fix a problem. What it
: finally came down to after stripping down my program is that the
: following program seems to be telling me that "Inf" contains no
: letters.
:
: -------
: #!/usr/local/bin/perl
:
: $variable = "Inf";
:
: if ($variable != /a-zA-Z/) {
: print "$variable does not have letters.\n";
: }
The operator should be !~.
-- fxn
------------------------------
Date: Fri, 31 Aug 2001 23:56:12 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: Bug or silly mistake?
Message-Id: <Xns910EAC4A2EBD0cberrycinenetnet1@207.126.101.92>
stevenson.20@nd.edu (D. Stevenson) wrote in
news:878e2749.0108311529.7b27da92@posting.google.com:
> Please help! I can't figure out how to fix a problem. What it
> finally came down to after stripping down my program
Good for you -- "isolate the problem" the first trick to learn in
effective debugging.
> is that the following program seems to be telling me that "Inf"
> contains no letters. Am I just being stupid, or could this be a bug?
When something this simple isn't working (as you expect it), you can be
pretty sure the problem is in your head, not perl. :) After all, a
problem that flagrantly obvious would have been encountered by every
perler in the world by now, right?
> It looks like the university where I work is using perl 5 or 5.6, I'm
> not sure.
Be sure...just execute 'perl -v' from the shell prompt. But it doesn't
matter, in this case.
> #!/usr/local/bin/perl
No -w, no 'use strict'. Let's try adding them and running your code:
> $variable = "Inf";
Made this
my $variable = "Inf";
to comply with strictness. Left all this the same:
> if ($variable != /a-zA-Z/) {
> print "$variable does not have letters.\n";
> }
And lo and behold, we get a warning. This is why you'll hear oldbies
telling newbies to enable warning and use strict, over and over, dozens of
times a day. It makes life easier on you and us. :) Here's the warning
text:
Use of uninitialized value in pattern match (m//) at foo line 7.
Line 7 is your pattern match. Now, clearly $variable is initialized, so
something weirder is amiss. Wait...what's that operator between $variable
and the pattern match? A simple inequality test, !=. So Perl is going to
run that pattern match against something, and compare the result of the
match (true or false) to the string in $variable. I'm sure you can see why
the test always fails, now.
So what *is* the match running against? In the absence of one of the
binding operators (=~ and !~), matches are done against $_ by default. Your
script never sets $_, so it's uninitialized, hence the error. When you
force it at gunpoint to act as a string to be matched against, it turns into
the zero-length string '', by the way, which is why your script manages to
lurch forward from there.
So, read up on the binding operators =~ and !~ in perlop, and also take a
stroll through perlre. I think the light will dawn. Good luck!
--
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake
------------------------------
Date: Fri, 31 Aug 2001 17:38:57 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Bug or silly mistake?
Message-Id: <3b902e23@news.microsoft.com>
"D. Stevenson" <stevenson.20@nd.edu> wrote in message
news:878e2749.0108311529.7b27da92@posting.google.com...
> if ($variable != /a-zA-Z/) {
You are matching against the literal string "a-zA-Z". This is probably not
what you mean.
If you want to match against a character class then say so by enclosing the
string in square brackets.
jue
------------------------------
Date: Fri, 31 Aug 2001 22:07:51 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Calling sub funcs with scalar variables?
Message-Id: <GIyDH3.K90@news.boeing.com>
In article <u9d75dbifs.fsf@wcl-l.bham.ac.uk>, <nobull@mail.com> wrote:
>demerphq@hotmail.com (Yves Orton) writes:
>...
>Symbolic method references are exempted from strict checking because
>there's no such thing as a hard method reference so if you're using
>method reference syntax at all you must have been deliberately using
>symbolic references.
>
>Symbolic method references are still eqaually dangerous from a
>security standpoint since $method can contain a package qualified name
>and there's no recursive check made of @Foo::Bar::ISA to ensure that
>the package specified in $method is really an ancestor of Foo::Bar.
>
>...
>
>If you want to use a package symbol table rather than a simple hash as
>your dispatch table I recommend:
>
>{ no strict 'refs'; "Foo::Bar::$method"->(); }
>
>Or:
>
>*{$Foo::Bar::{$method}}{CODE}->();
>
I've always been confused by 'use strict' semantics in such cases.
Why does the latter for instance pass strict when effectively an
unsafe runtime lookup occurs. If $method name is bogus, only the
error string changes:
use strict;
my $method = 'bogus';
{ no strict 'refs'; "Foo::Bar::$method"->(); }
Use of uninitialized value in string at ..
Undefined subroutine &main:: called at ..
versus:
my $method = 'bogus';
$Foo::Bar::{$method}}{CODE}->();
Use of uninitialized value in ref-to-glob cast at ..
Can't use string ("") as a symbol ref while "strict refs" in use at ..
Thanks for any enlightenment,
--
Charles DeRykus
------------------------------
Date: Fri, 31 Aug 2001 22:35:37 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Calling sub funcs with scalar variables?
Message-Id: <x7itf3hn7g.fsf@home.sysarch.com>
>>>>> "n" == nobull <nobull@mail.com> writes:
n> Uri Guttman <uri@sysarch.com> writes:
>> i wouldn't call that symbolic referencing.
n> That is because you consider "symbolic referencing" to be an
n> emmotionally charged term.
it should be. symbolic methods ARE NOT symbolic references.
n> So you appear to be saying the reason you "wouldn't call this symbolic
n> referencing" is because it "is a very useful technique" and you can't
n> bring yourself to say that symbolic referencing is ever a useful
n> technique.
also, since method lookup is defined to happen at run time. this is also
the reason methods can't have prototype support. you don't know when you
call a method which class will have it or if any will.
n> I recommend not using Foo::Bar->$method() unless the OO paradigm fits
n> for some other reason.
>>
>> i disagree.
n> Really? Any reason for that?
it is how you do polymorphism. you don't need an OO paradigm to want to
use it. as i said, stem doesn't have a special OO paradigm but it uses
polymorphism to call the best method for a given message object. i
create a method name and check if it exists with can and call it if it
does. you can only do that with $obj->$method(). i don't have to or want
to know the OO paradigm in the object, only that somehow it can handle a
dynamically created method name.
>> it is not for day to day OO but if you understand how to use it, it
>> is VERY powerful. many languages wish they could select methods at
>> run time.
n> I agree totally with the above statements. However I fail to see
n> their relevance here. I said if the OO paradigm fits then wear it.
n> What I also said was that you shouldn't use OO simply because it
n> allows you to use symbolic refs whilst pretending not to.
no, polymorphism is not symbolic references. you can do proper
workarounds for symrefs (typically hashes and dispatch tables) while
there is no simple other way to get polymorphism.
n> Of course, your above statement apply equally to subroutine symrefs
n> are also are not for day to day but if you understand how to use them,
n> they are VERY powerful.
nope, that can be done with hash and dispatch tables. method calls can't
be trivially simulated.
n> *{$Foo::Bar::{$method}}{CODE}->();
n> The second is actually an explicit dispach table call, except that
n> the dispatch table it uses happens to be a Perl symbol table, not a
n> simple hash.
and that is not a method call. it can be done with basic hashes so this
dangerous technique can be avoided.
dynamic method calls are are more a feature of the perl language and
symbolic references are more a feature of its syntax.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 31 Aug 2001 22:16:36 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Check for valid hex value
Message-Id: <999296196.283544935286045.gnarinn@hotmail.com>
In article <3B8FC30F.FA12F5F5@vitesse.com>,
Edward J. D'Avignon <davignon@vitesse.com> wrote:
>How can I check that a value entered is a valid hex value? The entry is
>up to 16 hex digits long and I need to ensure it only contains the
>characters 0123456789abcdf.
this looks like a good problem for a regexp.
see perldoc perlre
perldoc perlop
let us know if you have problems with it
gnari
------------------------------
Date: 31 Aug 2001 17:28:07 -0700
From: youradmirer@onebox.com (Newbie)
Subject: filetest
Message-Id: <582bc82b.0108311628.3187312@posting.google.com>
does a filetest in Perl actually take up any io access? or does it
just make a reference to an inode (in Unix) for infor? Thanks.
------------------------------
Date: 31 Aug 2001 17:42:36 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: filetest
Message-Id: <3b902efc@news.victoria.tc.ca>
Newbie (youradmirer@onebox.com) wrote:
: does a filetest in Perl actually take up any io access? or does it
: just make a reference to an inode (in Unix) for infor? Thanks.
(an inode is on disk so at some point "reference'ing" an inode requires
io).
I must assume that perl asks the os. Whether that leads to any io depends
on the os, and other factors, including what you mean by io.
Perl has one optimization mentioned in the pods (probably perlfunc.pod)
whereby determining file info multiple times just uses the same info from
an earlier call. I won't say which function(s?) where this occurs as I
would have to look them up to be sure I was correct, but reading stat and
-x would be a good place to start.
--
Want to access the command line of your CGI account? Need to debug your
installed CGI scripts? Transfer and edit files right from your browser?
What you need is "ispy.cgi" - visit http://nisoftware.com/ispy.cgi
------------------------------
Date: Fri, 31 Aug 2001 18:03:52 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: How to copy files in Perl and more
Message-Id: <3B8F8B38.93612@ce.gatech.edu>
Valentin 30IR976 wrote:
>
> How could I copy one file to a directory? I uses ActiveState Perl under
> NT
>
perldoc -f rename (works more like mv, really. does not work across
filesystems.)
or get the File::Copy module
or, like so:
open OLDFILE, "file.txt";
open NEWFILE, ">copy_of_file.txt";
while(<OLDFILE>){ print NEWFILE}
> And also another question...
>
> I would like to execute the command "dir" of NT, from my Perl program.
perldoc -f opendir
perldoc -f readdir
--
robert sherman
css, cee
georgia institute of technology
atlanta, ga, usa
------------------------------
Date: Fri, 31 Aug 2001 22:25:15 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How to copy files in Perl and more
Message-Id: <3B900F41.7BB07CC0@acm.org>
Valentin 30IR976 wrote:
>
> How could I copy one file to a directory? I uses ActiveState Perl under
> NT
perldoc File::Copy
> I have tried:
>
> $mydirectory="c:\midir";
Double quoted strings are interpolated. If you printed this variable you
would see what happens.
$ perl -le '$mydirectory="c:\midir"; print $mydirectory'
c:midir
The backslash is used for escaping characters you don't want
interpolated and representing special characters like newline (\n) and
horizontal tab (\t). Read the perlop manual page, specifically the
section on quote and quote-like operators.
Use either:
$mydirectory = "c:\\midir";
Or:
$mydirectory = 'c:\midir';
Or don't use backslashes at all:
$mydirectory = 'c:/midir';
> `copy myfile.txt $mydirectory`;
>
> and it doesnt work...
>
> Are there any other function like copy to copy files?
>
> And also another question...
>
> I would like to execute the command "dir" of NT, from my Perl program. I
> have written
>
> `dir`;
>
> but doesnt work.
>
> But if I write:
>
> $command=`dir`;
> print "$command";
>
> it works...
>
> Whats going on?
If the second example works then the first example also works. In the
first example you are sending the output of dir to your program but not
storing it anywhere. If you want the output to appear on the console use
system( 'dir' ); (Also get out of the habit of putting quotes around a
single variable.)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 31 Aug 2001 17:45:04 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to copy files in Perl and more
Message-Id: <slrn9p01b0.5af.tadmc@tadmc26.august.net>
Valentin 30IR976 <radiotito@yahoo.com> wrote:
>How could I copy one file to a directory? I uses ActiveState Perl under
>NT
>
>I have tried:
>
>$mydirectory="c:\midir";
Try adding this:
print "\$mydirectory is '$mydirectory'\n";
Then fix your quoting:
$mydirectory='c:\midir';
>`copy myfile.txt $mydirectory`;
>
>and it doesnt work...
Does it work when you type
copy myfile.txt c:midir
on the command line?
It won't work when perl tries to do the same thing either.
Perl is working fine, it is your program that has bugs.
>I would like to execute the command "dir" of NT, from my Perl program. I
>have written
>
>`dir`;
>
>but doesnt work.
Yes it does. "dir" *is* being run, but you are discarding its output.
>But if I write:
>
>$command=`dir`;
>print "$command";
>
>it works...
>
>Whats going on?
Now you are saving and then outputing "dir"s output.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 31 Aug 2001 18:18:06 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to copy files in Perl and more
Message-Id: <slrn9p038u.5cu.tadmc@tadmc26.august.net>
John W. Krahn <krahnj@acm.org> wrote:
>Valentin 30IR976 wrote:
>> $mydirectory="c:\midir";
>
>Double quoted strings are interpolated. If you printed this variable you
>would see what happens.
>Use either:
[snip]
>Or don't use backslashes at all:
>$mydirectory = 'c:/midir';
But this is destined for Windows' shell via backticks.
Can you use forward slashes in the M$ shell?
Forward slashes are OK for open() and filetests and whatnot,
but I don't think you can use them in backticks. 'Course I
wouldn't know, as I don't do Windows...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 31 Aug 2001 22:48:34 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: multithreaded LWP
Message-Id: <999298114.943357420619577.gnarinn@hotmail.com>
In article <Pine.LNX.4.33.0108311009190.30407-100000@schewanella.stanford.edu>,
Les Ander <citykid@nospam.edu> wrote:
>Hi,
>I have a question regarding threads. I have never used them, but
>I have a problem that needs me to use them.
>
>The problem is as follows:
>-------------------------
>I need to send about 6000 request to the
>server that takes about 3 minute to process every request. They give
>me an ID for every request, so I can retrieve the results within 24 hours.
>
>So this is what I want to do:
>----------------------------
>currently I am sending them one request at a time, parsing out the ID,
>waiting for 3 minutes and then retrieving the results with the ID, and
>then repeating this cycle. But this will take forever if I do this
>for 6000 requests. So instead I want to send them requests every about 15
>seconds or so, store the ID and then when all the requests are done, I
>will wait till the trafic is low before I request the results in batch or
>every 15 seconds. I think this would be lot more efficient.
i think the most effective way would be to maintain a queue, and limit
the number of requests being processed at a given time to some
maximum number. for example 20:
pseudocode:
send 20 initial requests, storing id in @id and timestamp for each in @ts;
$sent=20;
$got=0;
while ($got<6000) {
$try=$ts[$got]+3 minutes;
$success=0;
do {
sleep until time reaches $try;
$success=fetch($id[$got]);
$try=now+1 minute;
} while !$success;
do_whateveryouwantwith($id);
$got++;
if ($sent<5999) {
send request $sent, storing id and timestamp
$sent++;
}
}
the best number of items to keep queued depends on how much the
server gains from processing in parallell and how long it takes to
fetch the result in relation to the 3 minutes.
gnari
------------------------------
Date: Fri, 31 Aug 2001 18:08:21 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Open 2 exes from Perl
Message-Id: <310820011808218090%kevin@vaildc.net>
In article <5b5f48f5.0108310933.1b78a448@posting.google.com>, George K
<gkdata@cs.com> wrote:
> I am running Windoz 2000 and ActivePerl 5.6 (this is my work box - at
> home I run RH :)
>
> I am trying to do the following 2 things from one script:
> - change the current directory of my command window to another
> directory
> - open Win Notepad.exe
>
> The closest I've come is
> system ('c:\winnt\notepad.exe');
> system ('%SystemRoot%\system32\cmd.exe');
> wait();
>
> BUT I have many issues!
>
> The main problem is that while I can open Notepad I lose the command
> window- it freezes up with no cursor. It seems like it is waiting for
> Notepad to finish. As a matter of fact, when I close Notepad, the
> cursor reappears in the command window.
>
> So my question is : is it possible to call and run two seperate exe
> files from a single perl script? If so, could you point me to the
> proper docs so I can learn how? (I'd rather learn myself than have you
> GIVE me the answer.)
>
> Any ides would be greatly appreciated.
Look at the Win32::Process module, which is (I think) installed as part
of the ActiveState package by default.
--
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@vaildc.net | blazing high above your head.
. . . . . . . . . | But _in_ you is the presence that
. . . . . . . . . | will be, when all the stars are dead. (Rainer Maria Rilke)
------------------------------
Date: 31 Aug 2001 17:31:50 -0700
From: greenseaweed@aol.com (Mr. Green)
Subject: Re: registration worries
Message-Id: <5370f8aa.0108311631.3882923c@posting.google.com>
mjd@plover.com (Mark Jason Dominus) wrote in message news:<3b8fc2a2.2b51$38c@news.op.net>...
> In article <5370f8aa.0108310608.e48069d@posting.google.com>,
> Mr. Green <greenseaweed@aol.com> wrote:
> >Very helpful. Thanks. But I wonder if it would be more efficient to
> >ditch the random method and simply count the total number of files in
> >the directory and then let the file name be the total number plus one.
>
> You mean you want the total number plus one thousand.
>
> On average the efficiency is the same.
>
> I left in the random generation because I thought you might have had a
> reason for putting it in, that you actually *wanted* random filenames.
Sorry. I'm rather new to Perl and this list. Your comments were very helpful.
------------------------------
Date: 31 Aug 2001 18:02:52 -0700
From: youradmirer@onebox.com (Newbie)
Subject: Re: Running multiple procedures simultaneously
Message-Id: <582bc82b.0108311702.45ad0b37@posting.google.com>
You can use threads, but threading architecture hasn't been
standardized yet. If you wish to use them at your own risk, download
Thread module from CPAN. Since you'd like to access global variables,
threads seem to be the easiest way to do.
If you're on SysV, you can use shared memory as global variables. If
not, then you have to use some sort of database or files to share
information among processes forked by parent process. Piping might
help as well.
"Adam Kirby" <akirby@wharton.upenn.edu> wrote in message news:<9modfp$43s$1@netnews.upenn.edu>...
> I have a program which basically runs 5 searches (seperate procedures) one
> right after the other. I'd like to speed the program up considerably by
> running these searches at the same time. How would I go about doing this.
> Since they're in the same program, can I use fork? These procedures do
> access global variables.
>
> Thanks in advance!
>
> Adam Kirby
------------------------------
Date: 28 Aug 2001 05:45:35 GMT
From: s11976@net2.hkbu.edu.hk (PM WONG)
Subject: script to get varying strings into quotes
Message-Id: <9mfb5v$lbc$1@net44p.hkbu.edu.hk>
Any simple script to edit a file to modify a line
which starts with a known word:
so that it is changed from
known-word varying string of words with spaces in them
to
known-word "varying string of words with spaces in them"
------------------------------
Date: Fri, 31 Aug 2001 22:34:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: script to get varying strings into quotes
Message-Id: <3B901165.7F3074AE@acm.org>
PM WONG wrote:
>
> Any simple script to edit a file to modify a line
> which starts with a known word:
> so that it is changed from
>
> known-word varying string of words with spaces in them
>
> to
>
> known-word "varying string of words with spaces in them"
perl -pi -e's/^(known-word\s*)(.*)$/$1"$2"/' yourfile.txt
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 31 Aug 2001 22:36:49 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: script to get varying strings into quotes
Message-Id: <Xns910E9ED47541Ecberrycinenetnet1@207.126.101.92>
s11976@net2.hkbu.edu.hk (PM WONG) wrote in news:9mfb5v$lbc$1
@net44p.hkbu.edu.hk:
> Any simple script to edit a file to modify a line
> which starts with a known word:
> so that it is changed from
>
> known-word varying string of words with spaces in them
> to
> known-word "varying string of words with spaces in them"
Easy to do from the command line
perl -pi.bak -e 's/^(known-word\s+)(.*)/$1"$2"/' your-file-here
The original file will be saved as your-file-here.bak .
--
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake
------------------------------
Date: Fri, 31 Aug 2001 18:20:28 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: script to get varying strings into quotes
Message-Id: <slrn9p03dc.5cu.tadmc@tadmc26.august.net>
PM WONG <s11976@net2.hkbu.edu.hk> wrote:
>Any simple script to edit a file to modify a line
>which starts with a known word:
>so that it is changed from
>
>known-word varying string of words with spaces in them
>
>to
>
>known-word "varying string of words with spaces in them"
----------------------
#!/usr/bin/perl -w
use strict;
$_ = "known-word varying string of words with spaces in them\n";
s/(known-word\s+)(.*)/$1"$2"/;
print;
----------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.
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 V10 Issue 1673
***************************************