[7358] in Perl-Users-Digest
Perl-Users Digest, Issue: 983 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 5 16:27:22 1997
Date: Fri, 5 Sep 97 13:00:23 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 5 Sep 1997 Volume: 8 Number: 983
Today's topics:
"reget" with Net::FTP? <Brett.W.Denner@lmtas.lmco.com>
</.*?> vs. </[^>]*> <kshaw@plight.lbin.com>
finding/storing/removing a substring (Dustin Puryear)
Re: finding/storing/removing a substring <tycage@infi.net>
Re: here docs vs qq (Terry Michael Fletcher - PCD ~)
Re: How do I break up a line <petri.backstrom@icl.fi>
Re: how do I redirect the output of an existing perl sc (brian d foy)
Re: How does split find its argument? (Ilya Zakharevich)
Re: installing perl <hovnania@atc.boeing.com>
Re: Is Perl for Win32 really as brain damaged as it see (Ronald L. Parker)
Re: Is Perl for Win32 really as brain damaged as it see (Todd Bradfute)
Re: Is this a permissions problem <petri.backstrom@icl.fi>
Re: Learning perl (Ronald L. Parker)
Load a module only if needed? (Scott Grosch)
LWP::Simple malloc error <redmonds@acf2.nyu.edu>
Re: printing in the same place (Charles DeRykus)
Re: Problems compiling Perl <hovnania@atc.boeing.com>
spath: a command to do file path substitutions <pkohn@alw.nih.gov>
Re: stat on win95 (Alex Krohn)
unpack (Andrew D. Arenson)
Win95 Com Port Programming? <frank_a1@sfov1.verifone.com>
Windows NT is new to me...Please help (Mike Carville)
Windows NT wrong address above (Mike Carville)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 05 Sep 1997 14:14:59 -0500
From: Brett Denner <Brett.W.Denner@lmtas.lmco.com>
Subject: "reget" with Net::FTP?
Message-Id: <34105A33.2781@lmtas.lmco.com>
Is it possible to do a "reget" command with Net::FTP?
My IRIX ftp has a reget command that does the following (excerpted from
the
IRIX ftp man page):
reget remote-file [ local-file ]
Reget acts like get, except that if local-file exists and is
smaller than remote-file, local-file is presumed to be a
partially transferred copy of remote-file and the transfer is
continued from the apparent point of failure. This command is
useful when transferring very large files over networks that are
prone to dropping connections.
Is it currently possible to do this with Net::FTP? If not, is there any
reason why this could not be added to Net::FTP in the near future?
Thanks,
Brett
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Brett W. Denner Lockheed Martin TAS
Brett.W.Denner@lmtas.lmco.com P.O. Box
748
(817) 935-1144 (voice) Fort Worth, TX 76101
(817) 935-1212 (fax) MZ 9333
------------------------------
Date: 05 Sep 1997 11:44:33 -0700
From: kendall shaw <kshaw@plight.lbin.com>
Subject: </.*?> vs. </[^>]*>
Message-Id: <52vi0f38j2.fsf@plight.lbin.com>
Duhhh. How come </.*?> doesn't do what I thought it did?
I'm using perl 5.004 on solaris x86 2.4.
------------------------------
Date: Fri, 05 Sep 1997 18:20:50 GMT
From: dpuryear@usa.net (Dustin Puryear)
Subject: finding/storing/removing a substring
Message-Id: <34104700.159128765@news.intersurf.com>
Hi. I'm having a few problems in storing/removing substrings from a
comma-delimited string. Basically:
"string1,string2,string3,string5"
should be parsed into:
buf[0] = string1
buf[1] = string2
buf[2] = string3
buf[3] = string4
Now, it seems to me the best way to do this is to use a regex that
finds a substring separated by comma's. I then create a backward
reference to the substring, store it, and then remove it from the
original string.
Unfortunately, my solution fails in two scenarios. One: there is
only one substring within the string. Since there is no comma, the
substring is not found. Two: the substring is the last substring.
Failure two is really just Failure one reincarnated. Since the last
substring is the only remaining substring in the string (I have
removed the leading substrings), there are no comma's to mark it.
I'm sure there is a simple, elegant solution. Right now I have
fudged the loop to work correctly (kinda), but it's messy.
$i = 0;
do
{
$str =~ /(^.+?,)/; # create back-ref to the first "string,"
$buf[$i] = $1; # store the back-ref'd string
$str =~ s/$buf[$i]//; # remove the back-ref'd string from $str
$buf[$i] =~ s/[,]//; # remove the trailing ',' from $buf[$i]
$i++;
} while ($buf[$i-1]);
$str =~ /(.*)/; # get the last (or only) "string" from $str
$buf[$i-1] = $1; # store in last slot (skipped over in loop)
------------------------------
Date: Fri, 05 Sep 1997 14:40:25 -0400
From: Ty Cage Warren <tycage@infi.net>
Subject: Re: finding/storing/removing a substring
Message-Id: <34105219.216F0B6F@infi.net>
Dustin Puryear wrote:
>
> Hi. I'm having a few problems in storing/removing substrings from a
> comma-delimited string. Basically:
>
> "string1,string2,string3,string5"
>
> should be parsed into:
>
> buf[0] = string1
> buf[1] = string2
> buf[2] = string3
> buf[3] = string4
>
> Now, it seems to me the best way to do this is to use a regex that
> finds a substring separated by comma's. I then create a backward
> reference to the substring, store it, and then remove it from the
> original string.
> Unfortunately, my solution fails in two scenarios. One: there is
> only one substring within the string. Since there is no comma, the
> substring is not found. Two: the substring is the last substring.
> Failure two is really just Failure one reincarnated. Since the last
> substring is the only remaining substring in the string (I have
> removed the leading substrings), there are no comma's to mark it.
> I'm sure there is a simple, elegant solution. Right now I have
> fudged the loop to work correctly (kinda), but it's messy.
>
> $i = 0;
> do
> {
> $str =~ /(^.+?,)/; # create back-ref to the first "string,"
> $buf[$i] = $1; # store the back-ref'd string
> $str =~ s/$buf[$i]//; # remove the back-ref'd string from $str
> $buf[$i] =~ s/[,]//; # remove the trailing ',' from $buf[$i]
>
> $i++;
> } while ($buf[$i-1]);
> $str =~ /(.*)/; # get the last (or only) "string" from $str
> $buf[$i-1] = $1; # store in last slot (skipped over in loop)
How about
@buf = split(/,/,$str);
+---+
Ty Cage Warren tycage@infi.net
Systems Engineer InfiNet
Homepage: http://tazer.engrs.infi.net/~tycage
PGP Public Key: http://tazer.engrs.infi.net/~tycage/pgpkey.html
PGP Fingerprint: FF C1 28 CA 80 B5 31 78 B1 24 2E 8C AB DA FB D2
------------->Never invoke anything bigger than your head.<-------------
------------------------------
Date: 5 Sep 1997 17:21:33 GMT
From: tfletche@pcocd2.intel.com (Terry Michael Fletcher - PCD ~)
Subject: Re: here docs vs qq
Message-Id: <5upf2t$6t$1@news.fm.intel.com>
David Turley (dturley@rocketmail.com) so eloquently and verbosely pontificated:
> When returning a block of text to STDOUT is there any diference
> between
> using:
> print <<HERE;
> some text
> HERE
>
> or
>
> print qq!
> some text
> qq!;
the main difference is that your first example should print some
text, while the second example will print "qq" at the end :)
seriously though, with the HERE document, the quoted text starts
*after* the newline on the line it is declared on, while the qq
method you used *contains* that newline on the end of your line.
another difference is that the HERE must be on a line by itself,
and at the beginning of a line, while the qq's trailing delimiter
can be anywhere. lastly, you must escape any occurence of a "!" in
the qq method. if you are indented deeply in some code, you might
not want to use a HERE document. those are the differences i can
think of.
> I've gotten in the habit of using qq, but notice that many hackers
> seem to
> prefer <<HERE. If someone could point out any subtle (or not so
> subtle)
> reasons for using one over the other, I'd appreciate it.
oh, another difference is that apparently, people should use "qq"
if they dont want to be called a "hacker" :-)
hope that helped.
--
#!/usr/local/bin/perl -w
print "J" ."u". # -- Terry Fletcher
"s" ."t". " A", "n" # tfletche@pcocd2.intel.com
. "o" ,""."". "the", "r ","P". # Views expressed....not
"e"."rl" ." Ha", "c",'' ."" ."". # INTeL's....yadda yadda
"" , "k". "e" ."r" ;# yadda....
------------------------------
Date: Tue, 02 Sep 1997 00:39:06 +0300
From: Petri Backstrom <petri.backstrom@icl.fi>
Subject: Re: How do I break up a line
Message-Id: <340B35FA.630F@icl.fi>
Mike Rambour wrote:
>
> from a textarea in a html form. I have a form with a textarea in it
> and I writing the output to a file, that I later read into a HTML
> page that unfortunately has a PRE in it. The end result is that my
> output is all messed up, if a user presses the return key it all works
> but it they just type in the textarea it ends up as one long line.
>
> What I am trying to do is split the line into multiple lines at 70
> chars or less, but I also need to break up words. I have it working
> at <70 but it splits words.
Look up the Text::Wrap module on CPAN (the Comprehensive
Perl Archive Network):
http://www.perl.com/CPAN/
Or check the ./lib directory of your Perl installation
(it very likely is there already).
regards,
...petri.backstrom@icl.fi
ICL Data Oy
Finland
------------------------------
Date: Fri, 05 Sep 1997 14:26:21 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: how do I redirect the output of an existing perl script
Message-Id: <comdog-ya02408000R0509971426210001@news.panix.com>
In article <5upg2n$ro6$1@ha1.rdc1.sdca.home.com>, "Peter Tiemann" <peter@preview.org> wrote:
>I'd like to redirect the standard output of a perl function that I call.
simply open a file and print to it:
if ( open FILE, "> file_name" )
{
print FILE $stuff;
}
else
{
#do something about the error (perhaps recover?)
die "$0: $!\n";
}
>(Right now it writes on the screen = in a web page in my particular case)
remember that if you are running this as part of a CGI script, then
you might have to do some acrobatics to ensure that your script has
permission to write to the file.
>I would like to have that function write to a file to be able to process the
>output.
good luck :)
--
brian d foy <comdog@computerdog.com>
------------------------------
Date: 5 Sep 1997 19:25:20 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: How does split find its argument?
Message-Id: <5upmb1$b2o@agate.berkeley.edu>
In article <Pine.GSO.3.96.970905071506.15349L-100000@julie.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
> On 5 Sep 1997, Jahwan Kim wrote, concerning spliting on a listref instead
> of a pattern:
>
> > Question again: How does perl treat this anonymous array reference in
> > this case? Convert it to string? What happens, I think, is undocumented
> > (and doesn't need to be documented).
>
> I think it's converting it to a string, but I'd have to do some pretty
> tricky stuff to be sure.
a) It is (semi)documented that pattern of split may be a string. Thus
it may be [1], which *is* a string (as any perl data)
print[1];
b) To find out what happens, give -Dr argument (per Perl docs) to your
perl. (This requires a -DDEBUGGING perl.)
Ilya
------------------------------
Date: Fri, 5 Sep 1997 17:42:57 GMT
From: Paul Hovnanian <hovnania@atc.boeing.com>
To: eglamkowski@mathematica-mpr.com
Subject: Re: installing perl
Message-Id: <341044A1.22699018@atc.boeing.com>
the count wrote:
>
> Paul Hovnanian wrote:
> > the count wrote:
> > > We just got a new server and I am trying to install perl but the
> > > configure script is complaining that I don't have a working C compiler
> > > (which is silly, cause I've been compiling lots of C programs for the
> > > new system and they all work fine...)
[snip]
>
> I believe it is ANSI compliant. I've gotten past the above error
> (I had to manually go through the Configure script and add
> #include <stdlib.h> everywhere it was running a C program that used
> the exit() function). Now I have another problem - it fails to find
> a lot of the standard C functions:
It looks like your compiler/libraries/header files may not have been
installed
properly (missing some links, or be in weird places).
Check the following:
1) Make sure all the apropriate library symbolic links exist
(i.e /lib/libc.so -> /lib/libc.so.#.#.# ).
2) All the appropriate library paths are in /etc/ld.so.conf (or whatever
ldconfig
uses) and run ldconfig.
3) snoop around in Configure and find out which environment variable it
uses to
get library paths ( LD_LIBRARY_PATH ? ). Setting this manually might
help
Configure find this stuff.
--
Paul Hovnanian hovnania@atc.boeing.com
------------------------------------------------------------------------
Misers are tough to live with, but they make great ancestors.
Opinions the sole property of the above, available for a nominal fee.
------------------------------
Date: Fri, 05 Sep 1997 18:07:47 GMT
From: ron@farmworks.com (Ronald L. Parker)
Subject: Re: Is Perl for Win32 really as brain damaged as it seems?
Message-Id: <34114a1f.2961001@news.supernews.com>
On Fri, 05 Sep 1997 11:58:04 -0400, Brian Yoder
<beyoder@raleigh.ibm.com> wrote:
>For me, de-selecting a few options on the McAfee Virus Scanner
>stopped the a: drive access. Particularly the options related to
>scanning drives upon access.
Ditto. (Gurusamy, if you're still reading this, I'm the one who said
it also happens in your build. Looks like it's not your problem.)
--
Ron Parker
Software Engineer
Farm Works Software Come see us at http://www.farmworks.com
For PGP public key see http://www.farmworks.com/Ron_Parker_PGP_key.txt
------------------------------
Date: Fri, 05 Sep 97 17:48:28 GMT
From: bradfute@chromatic.com (Todd Bradfute)
Subject: Re: Is Perl for Win32 really as brain damaged as it seems?
Message-Id: <5upgld$29q1@cronkite.chromatic.com>
In article <340dc7fc.15344624@news.primenet.com>, klander@primenet wrote:
>
>On 3 Sep 1997 17:31:37 GMT, jdm@thetics.europa.com (Jessica) wrote:
>
>>
>>I'm attempting to write a script to run an external command for every
>>file in a directory tree under Win95 and WinNT and presents the results.
>>
>>I tried using backticks to execute the command and it would run the
>>command correctly and return the correct output to my script, but for
>>no apparent reason, _it would access a:\ every time the external command
>>was executed_. The external command doesn't reference a:\ and nothing
>>in my path or environment references a:\. This made the drive grind
>>noisily throughout the entire operation and was rather irritating to
>>listen to. just the command print `dir c:\`; by itself accesses my
>>floppy drive for no reason. This happens with both builds 110 and 307
>>and when I mentioned it to a coworker, he claimed to have seen this
>>problem before also.
>>
>
>Hmm...never heard of that one. I just ran this little test script and
>it works fine. See if it causes the problem your talking about. If
>so, you may have a problem with your installation. I'm running
>WinNT.40 and perl5.003_07 (build 307).
>
>#!/usr/local/bin/perl -w
>
>@ls = <*>;
>
>foreach $filename (@ls) {
> $outp = `type $filename` if (! -B $filename);
> print "$outp" if ($outp);
>}
>
>exit;
>
>If this doesn't cause the problem, let's see an example of one that
>does.
>
>For what it's worth, I also ran
>
>perl -e "print `dir c:\\ `"
>
>and it ran without accessing a:\.
I've been having this problem for a while now. I presumed this was all part of
the grand Microsoft plan to increase its profits by driving down the
productivity of every other company which develops software.
But alas, I have just found that if I turn off my McAfee VirusShield (3.0.2)
this behavior goes away. Does the originator of this thread
(jdm@thetics.europa.com (Jessica)?) have McAfee VirusShield on their system?
-TAB
------------------------------
Date: Tue, 02 Sep 1997 00:50:44 +0300
From: Petri Backstrom <petri.backstrom@icl.fi>
Subject: Re: Is this a permissions problem
Message-Id: <340B38B4.6EBA@icl.fi>
Mark Worsdall wrote:
>
> Hi, first let me say my perl books are ordered and on there way, in the
> meantime can I have a little bit of help.
>
> I have a script to read a given file passed by our server (for test
> purposes I am using the variable $visitorshome to store the name and
> path of the file to be read) and out it to the mail program. i.e. I am
> attempting to mail web pages to myself.
>
> Now I have got the mail part working a treat, I just can't get the file
> read in and then out to the mail program. When I first wrote the script
> and tested locally it seemed to work and worte the web page to a file I
> opened under the handle MAIL.
>
> But it is not working when on the server, no errors a reported when ran
> but when run with the -w I get:-
>
> Read on closed filehandle <HTML> at ./jd.pl line 138.
>
> Which I guess means that it failed to open the file, but did it fail to
> open as it did not have access to open it?
Most likely so, but you'd know for sure, if you
Perl tell you. E.g.:
open (HTML, "<$visitorshome") or
die "cannot open $visitorshome: $!";
Anyway, remember that usually the web server runs as
a nonprivileged user, or a specific user account, and
whatever that account is, it must have proper access
to whatever files the program being run as a CGI
script needs to read or write.
You'd probably benefit from reading what's posted on
http://reference.perl.com/query.cgi?cgi
regards,
...petri.backstrom@icl.fi
ICL Data Oy
Finland
------------------------------
Date: Fri, 05 Sep 1997 18:02:54 GMT
From: ron@farmworks.com (Ronald L. Parker)
Subject: Re: Learning perl
Message-Id: <34104917.2696905@news.supernews.com>
On Fri, 05 Sep 1997 14:51:39 GMT, I wrote:
>If you prefer dead trees, look no further than the subject line of
>your post. Learning Perl, affectionately known as the Llama book for
>the picture on the cover, is your best bet. It's written by Randal
>Schwartz and published by O'Reilly and Associates, and is available at
>any good bookstore (carrying O'Reilly books is the definition of a
>good bookstore) See http://www.ora.com for more.
And, as I was very gently reminded, also written by Tom Christiansen.
Sorry, Tom.
--
Ron Parker
Software Engineer
Farm Works Software Come see us at http://www.farmworks.com
For PGP public key see http://www.farmworks.com/Ron_Parker_PGP_key.txt
------------------------------
Date: 5 Sep 1997 17:48:47 GMT
From: grosch@ichips.intel.com (Scott Grosch)
Subject: Load a module only if needed?
Message-Id: <5upglv$iu9@news.or.intel.com>
I have a perl module (orgchart.pm) that defined a function requiring the
methods defined in another module (directory.pm). However, that function won't
be used by 99% of the scripts that 'use orgchart'.
How do I set things up so that orgchart.pm only does the 'use directory' if
someone calls that specific function?
------------------------------
Date: Fri, 05 Sep 1997 10:14:54 -0400
From: Sean Redmond <redmonds@acf2.nyu.edu>
Subject: LWP::Simple malloc error
Message-Id: <341013DC.59624791@acf2.nyu.edu>
I'm having trouble retrieving a page with LWP::Simple (source of the
page is at the end of this message). The following lines (using Perl
5.004_02 on Win95):
use LWP::Simple;
getprint(
"http://www.ahip.getty.edu/cgi-bin/aka/multwais.pl?wais://192.215.101.7:210/Avery2.src/9632985%20734%20/wais/data/Avery/av.dash7^TEXT^ovid%2A^/aka/aka_form_pub.html^/aka/images/ahiplogo.gif^http://www.gii.getty.edu/"
);
Result in this output:
<HEAD><TITLE>Searching the Getty Databases</TITLE></HEAD>
<body bgcolor="#ffffff">
<A HREF=""><IMG align=left border=no
SRC="/aka/images/new_search.gif"></A><p>
<A HREF="http://www.gii.getty.edu"><img border=no
src="/aka/images/ahiplogo.gif"></a>
<p><hr><b>Keywords: </b><br><b>Database: </b><hr><p>Error on reading
file. Malloc ran out of memory in an ANY<PRE></PRE>
I haven't had this problem with other pages, just ones on this site. Is
it a problem with LWP, Windows95, or this page?
Source of the page I'm trying to retrieve:
<HEAD><TITLE>Searching the Getty Databases</TITLE></HEAD>
<body bgcolor="#ffffff">
<A HREF="/aka/aka_form_pub.html"><IMG align=left border=no
SRC="/aka/images/new_search.gif"></A><p>
<A HREF="http://www.gii.getty.edu/"><img border=no
src="/aka/images/ahiplogo.gif"></a>
<p><hr><b>Keywords: ovid*</b><br><b>Database: Avery Index to
Architectural Periodicals</b><hr><p><PRE>TITLE : Di alcuni
temi <b>ovid</b>iani nel piano nobile del
Palazzo Capodiferro: iconografia e significato
AUTHOR(S) : Ciofetta, Simona
| Vicini, Maria Lucrezia
ILLUS. : ill., photos.
LANGUAGE : Italian
JOURNAL : Bollettino d'arte: 1991 Nov.-Dec., v.76, n.70,
p.105-119
ISSN : 0391-9854.
NOTE(S) : Includes bibliographical references.
SUBJECT(S) : Iconography--Renaissance
| Mythology--Symbolic aspects
| Mural painting and decoration--Renaissance--Italy--
Rome--Palazzo Capodiferro
AVERY CALL : N4 B61
ID : RLINNYCA93-V4697
</PRE>
--
Sean Redmond
New York University
redmonds@acf2.nyu.edu
Homepage: http://www.nyu.edu/classes/latin2/
Recent Ovidian Bibliography (1990-):
http://www.nyu.edu/classes/latin2/ovidbib.html
------------------------------
Date: Fri, 5 Sep 1997 16:55:00 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: printing in the same place
Message-Id: <EG1oBq.DEC@bcstec.ca.boeing.com>
In article <5up9s4$rht@crchh327.rich.bnr.ca>,
Intesab N. Siddiqui <intesab@bnr.ca> wrote:
>
>
>i would like to know how to print in the same place...
>
>i mean, with the following code (where my_print can
>manipulate the line and column)
>
>my_print (1);
>my_print (2);
>my_print (3);
>
>the output should be (at the same line and column):
>1 (after the first call)
>2 (after the second call)
>3 (after the third call)
>
>at the end the user would see 3, and 1 and 2 would not be visible,
>since they were over-written with 3...
>
Use the backspace, e.g., my_print("\b2"), etc.
HTH,
--
Charles DeRykus
------------------------------
Date: Fri, 5 Sep 1997 17:48:12 GMT
From: Paul Hovnanian <hovnania@atc.boeing.com>
Subject: Re: Problems compiling Perl
Message-Id: <341045DC.68A37359@atc.boeing.com>
Jeremy Finke wrote:
>
> Hello-
>
> I am having problems compiling Perl for my machine. It is a SCO 3.4v4.2
> running on a 486/66. I am using all of the default values for the 'sco'
> hint. I had been using a precompiled version that I downloaded
> somewhere, but i could not get this to work with any modules. I also
> had problems installing the modules.
Go through Configure again and when it starts asking about data types,
check each one against the appropriate man page (or better yet, in the
associated include (.h) file. It looks like Configure did not guess at
these values correctly.
[snip]
> pp_sys.c
> /usr/include/utime.h(46) : warning C4028: parameter 2 declaration
> different
> pp_sys.c(710) : error C2079: 'timebuf' uses undefined struct/union
> 'timeval'
> pp_sys.c(711) : warning C4049: 'initializing' : indirection to different
> types
> pp_sys.c(762) : error C2224: left of '.tv_sec' must have struct/union
> type
> pp_sys.c(763) : error C2224: left of '.tv_sec' must have struct/union
> type
> pp_sys.c(764) : error C2224: left of '.tv_usec' must have struct/union
> type
> pp_sys.c(822) : error C2224: left of '.tv_sec' must have struct/union
> type
> pp_sys.c(823) : error C2224: left of '.tv_usec' must have struct/union
> type
> *** Error code 6
>
> I am not running gcc. I am using the c compiler that came with the
> system. I really do not have the room to install gcc, i do not think.
> Any hints and/or help would be greatly apprecitated! TIA!
Make sure your C cmpiler is ANSI, although I believe the Configure test
will choke on this if its not.
--
Paul Hovnanian hovnania@atc.boeing.com
------------------------------------------------------------------------
Misers are tough to live with, but they make great ancestors.
Opinions the sole property of the above, available for a nominal fee.
------------------------------
Date: Fri, 05 Sep 1997 15:04:59 -0400
From: Philip Kohn <pkohn@alw.nih.gov>
Subject: spath: a command to do file path substitutions
Message-Id: <341057DB.6B49@alw.nih.gov>
I learned it in May and have since written >10,000 lines
of perl scripts, and I love it. I don't bother with shell
scripting anymore (thank God!).
Anyway, I wrote a perl command that I have found useful
so I thought I'd share it with you.
It is called spath (and can be linked to the name mpath to do
path matching instead of substitution).
Spath takes a unix command as its first argument and a
list of substitution regular expression as its last argument
(optional arguments inbetween are given to the unix command
as options). It will then run the command on all paths that match
any of the subsitutions with the original matching path and the
substituted path as arguments. Most often I use this with
mv, ln, cp and echo. Spath will create directories as needed to
make the last argument to the unix command valid
(there is a subroutine that does this).
So, here is the script:
#! /usr/local/bin/perl
#
# mpath, spath: match or substitute paths into unix command by regular
expressions
#
# Usage:
# mpath <unix command> [-] [<command options>...] '<match regular
expressions>'
# spath <unix command> [-] [<command options>...] '<substitutions
regular expressions>'
#
# mpath will run "<unix command> [<command options>...] <matched path>"
# for each file path that matchs one or more of the <match regular
expressions>.
# The first character of <match regular expressions> serves as a
delimiter
# between patterns to be matched.
#
# spath will run "<unix command> [<command options>...] <matched path>
<substituted path>"
# for each file path that matchs one or more of the <match regular
expressions>.
# The first character of <substitutions regular expressions> serves as a
delimiter.
# <substitutions regular expressions> consists of delimited triples:
# <match regular expression> <delimiter> <substitute regular
expression> <delimiter> <options>
# Where <options> is one of:
# g = substitute all occurrences of <match regular expression> in path
(default is first only)
# i = match in a case-insensitive manner
#
#
# For spath, directories are automatically generated as needed to
# create the destination file.
# To test things out without doing anything, use echo as <unix command>.
#
#
# examples:
#
# To reverse file_name to name_file:
# spath mv '/(.*)_(.*)/$2_$1/'
# To put files dir_name into separate directories dir/name:
# spath mv '|(.*)_(.*)|$1/$2|'
# To remove the first xxx in all files paths:
# spath mv '/xxx//'
# To remove all the underbars from all file paths:
# spath mv ';_;;g'
#
# Written by Philip Kohn, May, 1997
# Extensively modified in June, 1997
#
# Things to do:
# add options:
# r - recursive (default, otherwise use -prune option of find)
# f - regular files only (-type f)
# d - directories only (-type d)
# o - query before each command (like -ok)
# t - use tr command to translate characters
# more generally, allow any command to modify file paths
# v - just print commands without executing them
#
# speedups:
# change regex expressions to glob expressions for -name in file
#
# bugs:
# delimiters that are regex special chars don't work because of
split()
#
# the following are to allow this to run setuid
$ENV{'PATH'} =
'/bin:/usr/bin:/usr/local/bin:/usr/openwin/bin:/usr/sbin:/usr/ucb:/scsi3/data1/bin';
$ENV{'SHELL'} = '/scsi3/data1/bin/pkohn_sh' if $ENV{'SHELL'} ne '';
$ENV{'IFS'} = '' if $ENV{'IFS'} ne '';
if ($#ARGV < 1) {
printf("Usage: $0 <cmd> [-] [<args>] <path patterns (regular
expressions)>\n");
exit;
}
# figure out if this is mpath or spath by
# looking at the path to this file
$me = $0;
# strip off any leading directories in path
$me =~ s|^.*/||;
# if we are spath then there are 3 delimited parts to each
search/replace/mode in last argument
# otherwise for mpath the last argument is just a list of single regex
matching patterns
if ($me eq "mpath") {
$mpath = 1;
$inc = 1;
} else {
$mpath = 0;
$inc = 3;
}
# if the first command line argument is "-" then use a pipe input to get
the list of file
# names instead of starting up a find command process.
if ($ARGV[1] eq "-") {
$pipe = 1;
$i = 2;
} else {
$pipe = 0;
$i = 1;
}
# build a unix command line for system() in @cmd
# first fill in the command name
$cmd[0] = $ARGV[0];
# put any arguments before the last one as command arguments
for($j=1; $i<$#ARGV; $i++) {
$cmd[$j++] = $ARGV[$i];
}
# if the command is "ln" use the "-s" option to create a symbolic
# link (you may want to comment this out of your os doesn't support
# symbolic links!!)
if ($cmd[0] eq "ln") {
$cmd[$j++] = "-s";
}
# remember where to start putting in file path arguments
$first_path = $j;
# get last argument (list of regular expressions)
$patterns = $ARGV[$#ARGV];
# first character of patterns is delimiter
$delim = substr($patterns, 0, 1);
@pats = split($delim, $patterns, 1000);
if ($#pats < $inc - 1) {
print("last argument `$patterns' must have at least $inc delimited
patterns\n");
print("delim = $delim, patterns = $patterns, npats = $#pats, pats =
@pats\n");
exit;
}
# Accumulate a list of the directory paths that need to be searched
# in @paths. These are passed on to the find command.
@paths = ();
# Build a list of perl s or m commands (for spath or mpath) in @scmds.
for($i=1; $i<=$#pats; $i += $inc) {
$srch = $pats[$i];
if ($mpath) {
$scmds[$i] = "m" . $delim . $srch . $delim;
} else {
$repl = $pats[$i+1];
$opt = $pats[$i+2];
$scmds[$i/3] = "s" . $delim . $srch . $delim . $repl . $delim . $opt;
#print "scmd[$i/3] = $scmds[$i/3]\n";
}
# pull out first part of search path before any regex stuff (put in
[]'s)
$srch =~ s|^(/?)(([^/*.{}()?\$]*/)*).*$|$1$2|;
# print("srch = $srch\n");
if ($srch eq "") {
$srch = ".";
}
# look to see if this search path is already in @paths
$found = 0;
for($j=0; $j<=$#paths; $j++) {
if ($srch eq $paths[$j]) {
$found = 1;
break;
}
}
# if not found, add it to the end
if (! $found) {
$paths[$#paths + 1] = $srch;
}
}
if ($pipe) {
$glob = "STDIN";
} else {
open(PIPE, "find @paths -follow -print |" . "tr -s ' \t\r\f'
'\\012\\012\\012\\012' |");
$glob = "PIPE";
}
# loop over all the paths that come in from find (or the pipe).
while(<$glob>) {
chop;
$oldpath = $_;
# remove initial ./ from path
$oldpath =~ s|^\./||;
$newpath = $oldpath;
# try each m or s command on the path, set $found if one works.
$found = 0;
for($i=0; $i<=$#scmds; $i++) {
if (eval("\$newpath =~ " . $scmds[$i]) > 0) {
$found = 1;
}
}
# if no m or s command succeeded, then skip this path
if (! $found) {
next;
}
# add this path to the unix command line in @cmd
$cmd[$first_path] = $oldpath;
# if we are doing spath, add the substituted path to the command
if (! $mpath) {
$cmd[$first_path+1] = $newpath;
# check to see if the new path requires any directories to be created
if (&create_path($newpath)) {
next;
}
}
# print the command and then attempt to execute it
print("@cmd\n");
if (system(@cmd) != 0) {
print("@cmd -- command failed\n");
}
}
# attempt to create all the directories required to make a path valid
sub create_path {
$final_path = $_[0];
$path = $final_path;
$path =~ s|^([^/]*/).*|$1|;
while($path ne $final_path) {
if (! -d $path) {
$! = 0;
print("mkdir $path\n");
if ($cmd[0] ne "echo") {
mkdir($path, 0777);
if ($! != 0) {
print("Error creating directory `$path': $!\n");
return(1);
}
}
}
$next_path = $final_path;
$next_path =~ s|^(${path}[^/]*/).*|$1|;
$path = $next_path;
}
return(0);
}
----------------------------------------------------
"Make things as simple as possible, but no simpler."
----------------------------------------------------
Philip Kohn
pkohn@alw.nih.gov
301-496-8304
Hello perl world,
I learned perl in May and have since written nearly 10,000 lines
of scripts, and I love it! I don't bother with shell
scripting anymore (thank God!).
Anyway, I wrote a perl command that I have found useful
so I thought I'd share it.
It is called spath (and can be linked to the name mpath to do
path matching instead of substitution).
Spath takes a unix command as its first argument and a
list of substitution regular expression as its last argument
(optional arguments inbetween are given to the unix command
as options). It will then run the command on all paths that match
any of the subsitutions with the original matching path and the
substituted path as arguments. Most often I use this with
mv, ln, cp and echo. Spath will create directories as needed to
make the last argument to the unix command valid
(there is a subroutine that does this).
So, here is the script:
#! /usr/local/bin/perl
#
# mpath, spath: match or substitute paths into unix command by regular
expressions
#
# Usage:
# mpath <unix command> [-] [<command options>...] '<match regular
expressions>'
# spath <unix command> [-] [<command options>...] '<substitutions
regular expressions>'
#
# mpath will run "<unix command> [<command options>...] <matched path>"
# for each file path that matchs one or more of the <match regular
expressions>.
# The first character of <match regular expressions> serves as a
delimiter
# between patterns to be matched.
#
# spath will run "<unix command> [<command options>...] <matched path>
<substituted path>"
# for each file path that matchs one or more of the <match regular
expressions>.
# The first character of <substitutions regular expressions> serves as a
delimiter.
# <substitutions regular expressions> consists of delimited triples:
# <match regular expression> <delimiter> <substitute regular
expression> <delimiter> <options>
# Where <options> is one of:
# g = substitute all occurrences of <match regular expression> in path
(default is first only)
# i = match in a case-insensitive manner
#
#
# For spath, directories are automatically generated as needed to
# create the destination file.
# To test things out without doing anything, use echo as <unix command>.
#
#
# examples:
#
# To reverse file_name to name_file:
# spath mv '/(.*)_(.*)/$2_$1/'
# To put files dir_name into separate directories dir/name:
# spath mv '|(.*)_(.*)|$1/$2|'
# To remove the first xxx in all files paths:
# spath mv '/xxx//'
# To remove all the underbars from all file paths:
# spath mv ';_;;g'
#
# Written by Philip Kohn, May, 1997
# Extensively modified in June, 1997
#
# Things to do:
# add options:
# r - recursive (default, otherwise use -prune option of find)
# f - regular files only (-type f)
# d - directories only (-type d)
# o - query before each command (like -ok)
# t - use tr command to translate characters
# more generally, allow any command to modify file paths
# v - just print commands without executing them
#
# speedups:
# change regex expressions to glob expressions for -name in file
#
# bugs:
# delimiters that are regex special chars don't work because of
split()
#
# the following are to allow this to run setuid
$ENV{'PATH'} =
'/bin:/usr/bin:/usr/local/bin:/usr/openwin/bin:/usr/sbin:/usr/ucb:/scsi3/data1/bin';
$ENV{'SHELL'} = '/scsi3/data1/bin/pkohn_sh' if $ENV{'SHELL'} ne '';
$ENV{'IFS'} = '' if $ENV{'IFS'} ne '';
if ($#ARGV < 1) {
printf("Usage: $0 <cmd> [-] [<args>] <path patterns (regular
expressions)>\n");
exit;
}
# figure out if this is mpath or spath by
# looking at the path to this file
$me = $0;
# strip off any leading directories in path
$me =~ s|^.*/||;
# if we are spath then there are 3 delimited parts to each
search/replace/mode in last argument
# otherwise for mpath the last argument is just a list of single regex
matching patterns
if ($me eq "mpath") {
$mpath = 1;
$inc = 1;
} else {
$mpath = 0;
$inc = 3;
}
# if the first command line argument is "-" then use a pipe input to get
the list of file
# names instead of starting up a find command process.
if ($ARGV[1] eq "-") {
$pipe = 1;
$i = 2;
} else {
$pipe = 0;
$i = 1;
}
# build a unix command line for system() in @cmd
# first fill in the command name
$cmd[0] = $ARGV[0];
# put any arguments before the last one as command arguments
for($j=1; $i<$#ARGV; $i++) {
$cmd[$j++] = $ARGV[$i];
}
# if the command is "ln" use the "-s" option to create a symbolic
# link (you may want to comment this out of your os doesn't support
# symbolic links!!)
if ($cmd[0] eq "ln") {
$cmd[$j++] = "-s";
}
# remember where to start putting in file path arguments
$first_path = $j;
# get last argument (list of regular expressions)
$patterns = $ARGV[$#ARGV];
# first character of patterns is delimiter
$delim = substr($patterns, 0, 1);
@pats = split($delim, $patterns, 1000);
if ($#pats < $inc - 1) {
print("last argument `$patterns' must have at least $inc delimited
patterns\n");
print("delim = $delim, patterns = $patterns, npats = $#pats, pats =
@pats\n");
exit;
}
# Accumulate a list of the directory paths that need to be searched
# in @paths. These are passed on to the find command.
@paths = ();
# Build a list of perl s or m commands (for spath or mpath) in @scmds.
for($i=1; $i<=$#pats; $i += $inc) {
$srch = $pats[$i];
if ($mpath) {
$scmds[$i] = "m" . $delim . $srch . $delim;
} else {
$repl = $pats[$i+1];
$opt = $pats[$i+2];
$scmds[$i/3] = "s" . $delim . $srch . $delim . $repl . $delim . $opt;
#print "scmd[$i/3] = $scmds[$i/3]\n";
}
# pull out first part of search path before any regex stuff (put in
[]'s)
$srch =~ s|^(/?)(([^/*.{}()?\$]*/)*).*$|$1$2|;
# print("srch = $srch\n");
if ($srch eq "") {
$srch = ".";
}
# look to see if this search path is already in @paths
$found = 0;
for($j=0; $j<=$#paths; $j++) {
if ($srch eq $paths[$j]) {
$found = 1;
break;
}
}
# if not found, add it to the end
if (! $found) {
$paths[$#paths + 1] = $srch;
}
}
if ($pipe) {
$glob = "STDIN";
} else {
open(PIPE, "find @paths -follow -print |" . "tr -s ' \t\r\f'
'\\012\\012\\012\\012' |");
$glob = "PIPE";
}
# loop over all the paths that come in from find (or the pipe).
while(<$glob>) {
chop;
$oldpath = $_;
# remove initial ./ from path
$oldpath =~ s|^\./||;
$newpath = $oldpath;
# try each m or s command on the path, set $found if one works.
$found = 0;
for($i=0; $i<=$#scmds; $i++) {
if (eval("\$newpath =~ " . $scmds[$i]) > 0) {
$found = 1;
}
}
# if no m or s command succeeded, then skip this path
if (! $found) {
next;
}
# add this path to the unix command line in @cmd
$cmd[$first_path] = $oldpath;
# if we are doing spath, add the substituted path to the command
if (! $mpath) {
$cmd[$first_path+1] = $newpath;
# check to see if the new path requires any directories to be created
if (&create_path($newpath)) {
next;
}
}
# print the command and then attempt to execute it
print("@cmd\n");
if (system(@cmd) != 0) {
print("@cmd -- command failed\n");
}
}
# attempt to create all the directories required to make a path valid
sub create_path {
$final_path = $_[0];
$path = $final_path;
$path =~ s|^([^/]*/).*|$1|;
while($path ne $final_path) {
if (! -d $path) {
$! = 0;
print("mkdir $path\n");
if ($cmd[0] ne "echo") {
mkdir($path, 0777);
if ($! != 0) {
print("Error creating directory `$path': $!\n");
return(1);
}
}
}
$next_path = $final_path;
$next_path =~ s|^(${path}[^/]*/).*|$1|;
$path = $next_path;
}
return(0);
}
----------------------------------------------------
"Make things as simple as possible, but no simpler."
----------------------------------------------------
Philip Kohn
pkohn@alw.nih.gov
301-496-8304
------------------------------
Date: Fri, 05 Sep 1997 18:18:48 GMT
From: alex@gossamer-threads.com (Alex Krohn)
Subject: Re: stat on win95
Message-Id: <34104ce0.162716720@news.supernews.com>
Oops.. You're right. I was checking $file and not $path/$file.
Thanks for the help!
Alex
On Thu, 4 Sep 1997 19:33:02 -0700, Tom Phoenix <rootbeer@teleport.com>
wrote:
>On Thu, 4 Sep 1997, Alex Krohn wrote:
>
>> Does stat work with Perl for Win32?
>
>Oughta. :-)
>
>> I've got a list of files from readdir, but only the "." and ".."
>> entries seem to give back anything for stat. The rest seem to return
>> empty arrays..
>>
>> Am I doing something wrong?
>
>Probably. :-) If you're asking perl for the stats on 'foobar.txt', how
>can it know that you mean the file 'foobar.txt' in the directory you used
>during readdir? If you don't specify otherwise, of course, it looks in the
>current directory. Hope this helps!
>
>--
>Tom Phoenix http://www.teleport.com/~rootbeer/
>rootbeer@teleport.com PGP Skribu al mi per Esperanto!
>Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
> Ask me about Perl trainings!
>
------------------------------
Date: 05 Sep 1997 14:14:16 -0500
From: arenson@hen.imgen.bcm.tmc.edu (Andrew D. Arenson)
Subject: unpack
Message-Id: <wqvi0fk1yv.fsf@hen.imgen.bcm.tmc.edu>
What happens if you try to unpack something which isn't as
big as you think it is?
Let's say you do:
$newvalue = unpack("L",$value,0,4)
but $value only actually has 2 bytes of data. I think I'm seeing that
this causes memory problems in other psuedo-random places in one's script.
Andy
--
Andrew D. Arenson | http://gc.bcm.tmc.edu:8088/cgi-bin/andy/andy
Baylor College of Medicine | arenson@bcm.tmc.edu (713) H 520-7392
Genome Sequencing Center, Molecular & Human Genetics Dept. | W 798-4689
One Baylor Plaza, Room S903, Houston, TX 77030 | F 798-5386
------------------------------
Date: Fri, 05 Sep 1997 08:15:02 -0700
From: "Frank R. Anderson" <frank_a1@sfov1.verifone.com>
Subject: Win95 Com Port Programming?
Message-Id: <341021F6.6C50@sfov1.verifone.com>
I'm trying to run data over the PC Com ports at different port settings.
Below is the sample code to run a string wraparound. I've connected
a terminal with a null modem cable to the Com2 port. Output does work
with the system call: "echo $str >com2" but it is very slow. I also
tried loading FOSSIL but this did not help anything. I'm using Win95.
Any Suggestions? Does this work with NT? Does Perl for Win95 have
a library module for the PC UARTs?
Thanks, Frank Anderson
fander7036@aol.com
-------
#! /perl/bin/per -w
# com2tst.pl - a simple string echo program
system( "mode COM2: 96,n,8,1,n" );
open( COM, "+>COM2" ) || die "could not open COM2 $!\n";
while( <COM> ) {
print COM $_;
print STDOUT $_;
}
close( COM );
exit;
------------------------------
Date: 5 Sep 1997 18:28:00 GMT
From: carville@peganet.com (Mike Carville)
Subject: Windows NT is new to me...Please help
Message-Id: <5upivg$t1m$1@newsfep3.sprintmail.com>
Hi,
I became involved with writing a script for someone, and did not know until all
was done they are on Windows NT.
The scripts were written on Unix, and do work properly...
My question is...
what needs to be done to make these work on NT and...
Since the gentleman has just installed Perl into his system..Is there anything
he needs to do...
Thanks so much
Mike Carville
Free Cgi Scripts
Http://www.1-web-bazaar-plaza.com/help/cgi/
------------------------------
Date: 5 Sep 1997 18:32:46 GMT
From: carville@sprintmail.com (Mike Carville)
Subject: Windows NT wrong address above
Message-Id: <5upj8e$t1m$2@newsfep3.sprintmail.com>
Sorry for the double posting...above article has wrong email in it...
should be carville@sprintmail.com
Thanks
Hi,
I became involved with writing a script for someone, and did not know until all
was done they are on Windows NT.
The scripts were written on Unix, and do work properly...
My question is...
what needs to be done to make these work on NT and...
Since the gentleman has just installed Perl into his system..Is there anything
he needs to do...
Thanks so much
Mike Carville
Free Cgi Scripts
Http://www.1-web-bazaar-plaza.com/help/cgi/
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 983
*************************************