[18947] in Perl-Users-Digest
Perl-Users Digest, Issue: 1142 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 15 18:07:29 2001
Date: Fri, 15 Jun 2001 15:05:08 -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: <992642707-v10-i1142@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 15 Jun 2001 Volume: 10 Number: 1142
Today's topics:
A good place to find perl script examples (specifically <jcampbell@mediaone.net>
Access Sybase from PERL on NT <dbusby3@slb.com>
Re: Best way for batch renaming specific files (E.Chang)
can't handle strings with \ ??? brunck@silverplatter.com
Dynaloader mismatch, 5.005_03 / 5.6.0 <morgan@hahaha.org>
File handle question <hans@ti.com>
Re: File handle question (Craig Berry)
File::Find skips the leaf nodes in a directory tree? (jon chang)
How do I spawn an xterm executing another program and t (Keith)
How to Mach Word Only ? <yotamfr@inter.net.il>
Re: How to Mach Word Only ? (Malcolm Dew-Jones)
Re: How to Mach Word Only ? (E.Chang)
How to make GetOpt::Long do what I want (Paul Johnson)
Re: Memory Issues/File Slurping (Doug McGrath)
Re: Newbie Post : Flushing output for long scripts (isterin)
Re: Newbie Post : Flushing output for long scripts (Dave Hoover)
Perl question <esok@cosimo.gsfc.nasa.gov>
Re: Q: How to make a Perlscript Shareware? <admin@the-piper.net>
Re: special characters (Greg Bacon)
Re: special characters nobull@mail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 15 Jun 2001 19:12:07 GMT
From: "Jimmy Campbell" <jcampbell@mediaone.net>
Subject: A good place to find perl script examples (specifically: sockets)
Message-Id: <b6tW6.6497$ID2.1595544@typhoon.jacksonville.mediaone.net>
I want to write a perl script that implements a protocol which requires me
to connect to a socket, send it a string and then accept the output. Where
is a good place to find perl scripts that I can view that do similar tasks?
If any of you have any good suggestions for databases of example scripts I
can view (kind of like perlarchive.com but not necessarily full apps, just
chunks of code as tutorials) please let me know. I'm a newbie at perl and
would love to learn.
-Jimmy
------------------------------
Date: Fri, 15 Jun 2001 15:08:38 -0500
From: David Busby <dbusby3@slb.com>
Subject: Access Sybase from PERL on NT
Message-Id: <3B2A6B46.230A1369@slb.com>
Does anyone know how to access sybase from PERL running on NT with IIS.
I have tried several times but keep getting the error that for some
reason PERL can't load the sybperl::dblib or sybperl::ctlib dll files
from dynaloader.pm. If anyone has any suggestions please let me know.
Thanks in advance.
Please send email to dbusby@houston.geoquest.slb.com
------------------------------
Date: Fri, 15 Jun 2001 18:55:02 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Best way for batch renaming specific files
Message-Id: <Xns90C19835AACB3echangnetstormnet@207.106.93.86>
"Michael Segulja" <michael.segulja@kingwoodcable.net> wrote in
<3b2a407c$1_3@newsfeeds>:
> I have some files name filename.0001,
> filename.0002....filename.0450, etc. I want to rename these files
> to filename.0001.tif, filename.0002.tif....filename.0450.tif, but
> I'm not sure how.
[snip]
Assuming you want to rename only those that end with a four-digit
numeric extension,
rename $filename, "$filename.tif" if $filename =~ /(\.\d{4})$/;
--
EBC
------------------------------
Date: 15 Jun 2001 20:09:39 GMT
From: brunck@silverplatter.com
Subject: can't handle strings with \ ???
Message-Id: <9gdq23$5og$1@news.netmar.com>
I've got a problem where I have a double quoted string being passed to a
function, and the data in it is unfortunately delimited by a '\'. I can't
split
it up on that or use s/// on it because it's double-quoted, so when there's
this sort of data:
.. (hardback)\0-85649-756-9
apparently the \0 gets interpreted first before s/// tries its thing, so I'm
never able to
translate the backslashes into anything else such as '\\'.
Is there any way to get this string changed to a single-quoted string? Or
some way to translate these \ into something else while the string is still
double-quoted?
Thanks for any help.
----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
NewsOne.Net prohibits users from posting spam. If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net
------------------------------
Date: Fri, 15 Jun 2001 20:20:09 GMT
From: Morgan Fletcher <morgan@hahaha.org>
Subject: Dynaloader mismatch, 5.005_03 / 5.6.0
Message-Id: <jzssnh1zeax.fsf@bolt.sonic.net>
I have a perl5.005_03 script that calls another script with system(),
and that 2nd script is a perl5.6.0 script. The system() call returns
"DynaLoader object version 1.04 does not match $DynaLoader::VERSION
1.03 at /home/pack/nsPerl5.005_03/lib/sun4-solaris/DynaLoader.pm". If
I execute the command line from a shell (that's inside system()) it
runs fine. What am I doing wrong?
morgan
------------------------------
Date: Fri, 15 Jun 2001 14:03:27 -0500
From: "Hans Baartmans" <hans@ti.com>
Subject: File handle question
Message-Id: <9gdm60$e0a$1@tilde.csc.ti.com>
I am trying to read in a file. The file contains a set of lines that are
exactly the same, except for the first string. I would like to pull out the
first string of each line and write those strings to a new file.
I know this is an easy question, but I am not a good perl programmer. Might
as well say a bad one.
Thanks!
------------------------------
Date: Fri, 15 Jun 2001 20:24:55 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: File handle question
Message-Id: <tikrong3nodcfb@corp.supernews.com>
Hans Baartmans (hans@ti.com) wrote:
: I am trying to read in a file. The file contains a set of lines that are
: exactly the same, except for the first string. I would like to pull out the
: first string of each line and write those strings to a new file.
Each line *is* one string, if you're reading by lines. If you mean "get
the first sequence of non-whitespace and write it to a new file", here's a
command-line version:
perl -nle 'print /(\S+)/' infile >outfile
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Magick is the art and science of causing change in conformity
| with Will." - Aleister Crowley
------------------------------
Date: 15 Jun 2001 11:50:21 -0700
From: jonchang@my-deja.com (jon chang)
Subject: File::Find skips the leaf nodes in a directory tree?
Message-Id: <774e29f8.0106151050.6884b126@posting.google.com>
Hi,
I'm trying to write a small script that'd scan a directory recursively
and create a blank index.html in each subdirectory where no index.html,
index.htm, or index.cgi is found.
I found the following script skipping the leaf nodes of a directory. Any
help would be appreciated.
Also, is there a better way of doing things below in Perl, instead
of invoking system() call.
Regards.
#!/usr/local/bin/perl -w
use File::Find;
@ARGV = ('.') unless @ARGV;
find sub {
if ( !(-e 'index.cgi' || -e 'index.html' || -e 'index.htm') ) {
system("touch index.html; chown www:www index.html; chmod 644 index.html")
;
}
}, @ARGV;
------------------------------
Date: 15 Jun 2001 13:59:21 -0700
From: keith@aztek-eng.com (Keith)
Subject: How do I spawn an xterm executing another program and then interact with the executed program with Expect.pm
Message-Id: <8683bf68.0106151259.f0fac1c@posting.google.com>
This is what I want to do:
Run a perl script from one xterm that execs another xterm and then automates
the program running in the new xterm using Expect.pm module.
Expect normally works with programs that read from standard input or
/dev/tty and xterms don't read their input in this manner; therefore , I
believe something fancy has to be done with the IO::Pty module and the xterm
'-S' option to get the Perl program with Expect.pm and the external xterm
application communicating.
I am relatively proficient in perl with Expect.pm, but my understanding of pseudo
terminals, pty, tty, ... is limited. Can anyone help?
Thanks,
Keith
------------------------------
Date: Fri, 15 Jun 2001 22:09:18 +0200
From: "yotam" <yotamfr@inter.net.il>
Subject: How to Mach Word Only ?
Message-Id: <9gdmjh$3vo$1@news.inter.net.il>
suppose I have this file :
I like perllanguage
I like perl language
and I want to substitute only the 2nd line.
I need to recognize only the word and I don't want to use spaces
because it can be dash (-) or other no-word
I like perllanguage
I like English language
how can I do it with s/// command?
p.s
In vim it is very simple -> :%s/\<perl\>/English/g
what is the equivalent for \< \> in perl
thanks in advance Or.
------------------------------
Date: 15 Jun 2001 12:44:55 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: How to Mach Word Only ?
Message-Id: <3b2a65b7@news.victoria.tc.ca>
yotam (yotamfr@inter.net.il) wrote:
: suppose I have this file :
: I like perllanguage
: I like perl language
: and I want to substitute only the 2nd line.
: I need to recognize only the word and I don't want to use spaces
: because it can be dash (-) or other no-word
: I like perllanguage
: I like English language
: how can I do it with s/// command?
\b is the most likely bet
s/\bperl\b/English/
"perldoc perlre" will tell you more, there are others that may help (and I
usually look them up in perlre to confirm what I am using is correct
before I use it myself.)
--
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, 15 Jun 2001 19:54:21 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: How to Mach Word Only ?
Message-Id: <Xns90C1A2428BA81echangnetstormnet@207.106.93.86>
"yotam" <yotamfr@inter.net.il> wrote in
<9gdmjh$3vo$1@news.inter.net.il>:
> suppose I have this file :
>
> I like perllanguage
> I like perl language
>
> and I want to substitute only the 2nd line.
> I need to recognize only the word and I don't want to use spaces
> because it can be dash (-) or other no-word
>
> I like perllanguage
> I like English language
>
> how can I do it with s/// command?
>
\b is zero-width matching a word boundary.
s/\bperl\b/English/;
Word characters in Perl are alphanumeric characters plus underscore _.
See the documentation on regular expressions: perldoc perlre or
http://www.perldoc.com/perl5.6/pod/perlre.html
--
EBC
------------------------------
Date: 15 Jun 2001 13:06:41 -0700
From: pauljohn@ukans.edu (Paul Johnson)
Subject: How to make GetOpt::Long do what I want
Message-Id: <a99dddab.0106151206.612f87d2@posting.google.com>
I currently have a program that defines a hash of references to arrays,
and it works great
my %parameters = (
numPPL => [ 100 ],
aRebConstPOM => [0.1, 0.2],
vision => [1, 2, 3]
);
Now I want users to be able to pass the numbers through on the command line,
so I'm trying things like
my %parameters =();
GetOptions ("define=f@" => \%parameters) || die "Invalid arguments \n";
However, all I get is a ton of errors if I try to use that with:
$ perl newRunRB.pl --define numPPL=[100,101] --define vision=[1,2]
If you can help, thanks in advance!
Paul Johnson
Dept. of Political Science
University of Kansas
pauljohn@ukans.edu
------------------------------
Date: 15 Jun 2001 13:34:58 -0700
From: doug.mcgrath@us.telegyr.com (Doug McGrath)
Subject: Re: Memory Issues/File Slurping
Message-Id: <a4e10296.0106151234.6ea4cd66@posting.google.com>
> Firstly, the /o has no effect, since there are no interpolations in the
> matches. Second, you could probably benefit quite a bit by replacing
> the "if"s with "elsif"s if these are done in a loop. Third, have you
> considered using one [large] regex for parsing some parts? The /x
> option will help quite a bit here.
I wasn't sure about the /o; the documentation is a little murky as to
exactly when it has an effect. Thanks for explaining that so much more
clearly.
Most of the matches are NOT in a loop; I was using the \G assertion to
pick up the matches where the last one left off. It isn't a matter of
an either/or situation, but rather that each item is found in sequence
in the file.
I'll try the combination of a single regex; I'd found a couple of
cases where I'd written bad regex's that ended up matching a
multi-megabyte result, and the performance was abyssmal, of course. In
the case of the RCS file header, the structure is relatively fixed;
some items are optional, so I have to be careful to pick up everything
when it's there, but still work when they're not there (locks,
symbols, keyword expansions) and so on.
> Or else memory is leaking elsewhere. Are you sure that you either
> eliminate all references to $line or else assign undef or somesuch to
> it?
Yes, the only references are within the function that does the
processing. The performance section in Programming Perl recommended
against undef'ing because it causes memory fragmentation. Perhaps I
misread...?
> Just offhand, is this being used in mod_perl or somesuch? What kind of
> application is handling RCS files in such huge numbers? I would think
> that any single process would touch only a small number of files [and
> then exit], making memory leaks less important.
No, it's an application that processes all files in our RCS
repositories; we have about six large repositories with around 25,000
files each. These are integrity checks and reporting scripts that
process everything, not just a few files here and there.
Thanks for the suggestions; I'll give them a try.
Doug
------------------------------
Date: 15 Jun 2001 11:42:05 -0700
From: isterin@hotmail.com (isterin)
Subject: Re: Newbie Post : Flushing output for long scripts
Message-Id: <db67a7f3.0106151042.2f0666ef@posting.google.com>
If it won't work with IE than this is an IE specific and not perl
problem. IE probably caches the information before displaying on the
screen. I am sure you can reset this either through IE or the
registry.
Ilya Sterin
"Ben Holness" <bholness@nortelnetworks.com> wrote in message news:<9fg6uu$if$1@qnsgh006.europe.nortel.com>...
> Unfortunately neither of these options solve my problem.
>
> $|=1, which I had already tried, doesn't make any difference.
>
> CGI::Push documentation says that it won't work for IE, which is our
> corporate standard, so no-one uses netscape :(
>
> It's a real pain, because I have a perl script that reads a file, processes
> it, prints a line of text, then reads the next file and so on...
>
> The problem is that the user gets bored waiting, or I get a timeout before
> the script has finished, so it would be nice to be able to feed them a line
> at a time...
>
> Cheers,
>
> Ben
>
> "John Imrie" <07950232225@one2one.net> wrote in message
> news:3B174D66.87A211F8@one2one.net...
> >
> >
> > Stefan Weiss wrote:
> >
> > > Ben Holness <bholness@nortelnetworks.com> wrote:
> > >
> > > > I put this in a print statement, but that doesn't seem to get to the
> browser
> > > > until the whole script is finished, or the user presses stop. Is there
> any
> > > > way to force it out while the script is still running?
> > >
> > > Yes.
> > > $| = 1;
> > > see `perldoc perlvar`
> > >
> > > cheers,
> > > stefan
> >
> > Actualy that probably wont work either as a web browser does not have to
> display a
> > page untill it has it all.
> >
> > What you require is Server Push with a multipart document see the
> documentation
> > for CGI.pm
> >
------------------------------
Date: 15 Jun 2001 13:36:55 -0700
From: redsquirreldesign@yahoo.com (Dave Hoover)
Subject: Re: Newbie Post : Flushing output for long scripts
Message-Id: <812589bb.0106151236.40bd2d8c@posting.google.com>
Ben Holness wrote:
> I would like to give something to my users to show that it is actually
> running.
I'm assuming that this script is kicked off by a submit button. Have
the form action take the user to a static HTML page that displays,
"Script is running, please be patient." Then on that static HTML
page, have an automatic redirect to your perl script.
This method is a bit unconventional, but I think it will do what
you're looking for. I couldn't think of a way to do it in Perl, but
I'd bet there's some way to do it...probably more than one!
HTH
--
Dave Hoover
Red Squirrel Design
"Twice blessed is help unlooked for." --Tolkien
------------------------------
Date: Fri, 15 Jun 2001 14:50:40 -0400
From: Eric Sokolowsky <esok@cosimo.gsfc.nasa.gov>
Subject: Perl question
Message-Id: <Pine.SGI.4.33.0106151435520.142896-100000@cosimo.gsfc.nasa.gov>
I am rather new to perl programming, so if anyone could help me out with this
problem I would really appreciate it.
I am maintaining a script that takes some XML data and interprets it.
Here is a small sampling of the XML data that it is trying to interpret:
----- Begin snippet -----
<WMT_MS_Capabilities version="1.0.8">
<Capability>
<Request>
<GetMap>
<Format>image/gif</Format>
<Format>image/jpeg</Format>
<Format>image/png</Format>
<Format>image/tiff</Format>
<Format>image/ppm</Format>
<Format>application/x-cubestor-wkb</Format>
<Format>application/x-cubestor-gml.1</Format>
<Format>application/x-cubestor-gml.2</Format>
----- End snippet -----
I'm trying to figure out if a particular file format is specified (the CDATA
part of the <Format> tags near the bottom of the snippet. The parser used by
this script returns a hierarchical structure, so that I can directly access the
first file format in the following way:
$form = $document{'WMT_MS_Capabilities'}{'Capability'}{'Request'}{'GetMap'}{'_Format'}[0]{'CDATA'};
The _Format is used to indicate an array of all the Format tags. My question
is this: How do I loop through the different CDATA portions of the Format
tags? Or is there a way to search recursively through a selected subset
for the string I want? I have some perl books (Programming Perl 3rd ed.,
Perl cookbook, Learning perl, etc), but couldn't easily find information in
them about how to do this. I would especially welcome any pointers to places I
can learn more about how to access different parts of my structure. Thanks for
any help.
--
____ __ Eric Sokolowsky NASA Goddard Space Flight Center
/ __/__/_/__ Visualization Programmer Scientific Visualization Studio
/ __/ _/ / _/ esok@cosimo.gsfc.nasa.gov Code 935.0 Bldg 28 Rm S121
/___/_//_/__/ 301.286.3751 Greenbelt, MD 20771
------------------------------
Date: Fri, 15 Jun 2001 20:22:03 +0200
From: "Tom Klinger" <admin@the-piper.net>
Subject: Re: Q: How to make a Perlscript Shareware?
Message-Id: <992630096.235804@newsmaster-04.atnet.at>
Cameron Dorey <camerond@mail.uca.edu> schrieb in im Newsbeitrag:
3B28DC4C.984AA4A1@mail.uca.edu...
> Send out your code with a "do not function after xx/xx/xxxx" generated
> when the program is downloaded and buried in a module somewhere. Then
> when the user registers, send him/her the replacement module without the
> die code.
Hi,
this could be one way I may choose, but I still wonder how to write such a
piece of code which is first protecting your script with an expiration code
and second hide it in such a way that it will be worth to buy it than rather
try to onvest a couple of times and remove that pieces of code.
I still try to get some examplecodes but my search is, unfortunatly, not
very successful.
Anyway, thanks to all for your time.
Cheers, Tom
------------------------------
Date: Fri, 15 Jun 2001 18:12:03 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: special characters
Message-Id: <tikjvjj36lu70a@corp.supernews.com>
In article <3B2A4B18.11E1C8CF@uclink.berkeley.edu>,
Gordon Vrdoljak <vrdoljak@uclink.berkeley.edu> wrote:
: I was working on a program to read in materials from a text file,
: generate a form, and then with a seperate cgi script, attach prices to
: the materials. I spent an hour figuring out that if I have '()'
: characters in the material file, it won't match (ie $variable =~
: /^$searchvar/; won't work if I have ()'s in $variable).
:
: I was wondering what other special characters I should watch out for
: or exclude, or if there are any ways around this. Gordon
You want to use Perl's quotemeta operator that's documented in the
perlfunc manpage.
Greg
--
Only politicians and bureaucrats benefit from welfare--and that's why
every welfare reform leads to bigger budgets and more people on welfare.
-- Harry Browne
------------------------------
Date: 15 Jun 2001 19:01:32 +0100
From: nobull@mail.com
Subject: Re: special characters
Message-Id: <u9r8wlzkoz.fsf@wcl-l.bham.ac.uk>
Gordon Vrdoljak <vrdoljak@uclink.berkeley.edu> writes:
> I was working on a program to read in materials from a text file, generate a
> form, and then with a seperate cgi script, attach prices to the materials. I
> spent an hour figuring out that if I have '()' characters in the material file,
> it won't match (ie $variable =~ /^$searchvar/; won't work if I have ()'s in
> $variable).
Huh? Surely you mean in $searchvar?
> I was wondering what other special characters I should watch out for or exclude,
A list of characters that are special in Perl regex can be
found... (drum roll)... in the documention of Perl regex
(i.e. "perldoc perlre"). Actually it sufficient to act as if any
non-alphanumeric printable ASCII character is special and should be
prefixed with a backslach if you want to be sure it won't be treated
as special (which is what the quotemeta() function does).
> or if there are any ways around this.
$variable =~ /^\Q$searchvar/;
You can also use index($variable,$searchvar)==0
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
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 1142
***************************************