[6944] in Perl-Users-Digest
Perl-Users Digest, Issue: 569 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 4 14:12:01 1997
Date: Wed, 4 Jun 97 11:00:55 -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 Wed, 4 Jun 1997 Volume: 8 Number: 569
Today's topics:
[Q] Parsing C++ w Perl <rossetti@apple.com>
Re: any editor for perl? (Matthew H. Gerlach)
Re: any editor for perl? (Scott McMahan)
Re: any editor for perl? (Helmut Jarausch)
Re: Any plans for perl plug-ins? lvirden@cas.org
Atomic file create or fail if already existing (Leonard Megliola)
CMD32.EXE setup w/Win 95. <videit@netaxs.com>
Re: Code examples: right justify text? (Chipmunk)
COMPUTER JOBS NEEDED <brian@pluto.tekmarkinc.com >
Re: ld problems (./so_locations) while building perl-5. (Walter Roberson)
Need help with PERL! <cmartin@interware.net>
Re: Need vacation program in Perl! lvirden@cas.org
Re: Newbie question (Chipmunk)
Re: newbie question2 <dani@apb.es>
Re: perl 5.03 by Activeware, for win95 (Fred Elbel)
Possible bug in URI::URL? <jhg@austx.tandem.com>
Re: Possible bug in URI::URL? <aas@bergen.sn.no>
Re: Reading Comma delimited, Quoted String records (Kevin Smith, ShadeTree Software, Inc.)
simple question about running system programs from with <albersl@cs.montana.edu>
Re: simple question about running system programs from <buxx@buxx.com>
Re: String Compare Problem <eike.grote@theo.phy.uni-bayreuth.de>
Re: String comparsion (Chipmunk)
Telnet <visiocad@easynet.fr>
Re: Telnet (Jeremy D. Zawodny)
Re: tr problems with variables <eike.grote@theo.phy.uni-bayreuth.de>
Using debugger with formats in the file <robertmy@pogo.wv.tek.com>
Re: What's perl equivalent to awk's $1, $2, etc.? <dean@tbone.biol.sc.edu>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Jun 1997 17:12:11 GMT
From: Michael D. Rossetti <rossetti@apple.com>
Subject: [Q] Parsing C++ w Perl
Message-Id: <5n47lb$cig$1@news.apple.com>
[Q] Parsing C++ w Perl
Friendly Sentient Beings,
Would anyone have a lead on a script for parsing a set of C++ files (many
headers and implementation files)?
I'm working on building a database of a large framework with several
tables containing information on classes, inheritance, globals, data
members, etc. If someone has already done the parsing in Perl it would
sure give me a leg up on the rest of it.
Thanks,
Mike R.
MacApp Engineering
Apple Computer, Inc.
rossetti@apple.com
------------------------------
Date: Wed, 4 Jun 1997 15:23:40 GMT
From: gerlach@netcom.com (Matthew H. Gerlach)
Subject: Re: any editor for perl?
Message-Id: <gerlachEB9C3G.G81@netcom.com>
>Vi is really old and nauseating... The ONLY reason you will ever
>find for using such an editor is "Its on every machine"....
Gee, compared to Microsquish products, UNIX itself is "old" and some
people consider it nauseating. Personally, the fact that vi is on
every machine is a big plus. Since I do a lot of perl work, and I have
bash setup for vi mode, using vi as editor makes for a consistent user
interface. Lastly I do a ton of work over slow connections.
Vi was designed in such an environment, and it works dame well.
>Dont waste your time on vi.
I'm old fashioned in that I believe 10 fingers is more effecient editing
than one hand with a mouse. I work with a bunch of people who gui type
of editors, and I'm always amazed how long it takes them to navigate
through all the "intuative" menus and stuff.
In the end, enjoy the fact there are choices; find the one you like that
serves your specific needs. For me, my needs are best met with vi.
Matthew H. Gerlach
------------------------------
Date: 4 Jun 1997 16:31:44 GMT
From: scott@lighthouse.softbase.com (Scott McMahan)
Subject: Re: any editor for perl?
Message-Id: <5n459g$1ie$1@mainsrv.main.nc.us>
Monty Scroggins (Monty@dhc.net) wrote:
: Vi is really old and nauseating...
Vi is still around because they got it right the first time and
nothing better has come along. (Emacs is just a bloated vi clone! :))
Scott
------------------------------
Date: 4 Jun 1997 16:48:49 GMT
From: jarausch@numa1.igpm.rwth-aachen.de (Helmut Jarausch)
To: Monty@dhc.net
Subject: Re: any editor for perl?
Message-Id: <5n469h$7ro$1@news.rwth-aachen.de>
In article <5n459g$1ie$1@mainsrv.main.nc.us>, scott@lighthouse.softbase.com (Scott McMahan) writes:
|> Monty Scroggins (Monty@dhc.net) wrote:
|>
|> : Vi is really old and nauseating...
|>
|> Vi is still around because they got it right the first time and
|> nothing better has come along. (Emacs is just a bloated vi clone! :))
I think there are better choices.
If you don't have X11, you can take JED.
If you have X11, take XJED or NEDIT, which I prefer.
Both have Perl syntax highlight (NEDIT only in very recent versions)
What a difference to vi !!!
--
Helmut Jarausch
Lehrstuhl f. Numerische Mathematik
Institute of Technology
RWTH Aachen
D 52056 Aachen, Germany
------------------------------
Date: 4 Jun 1997 16:54:46 GMT
From: lvirden@cas.org
Subject: Re: Any plans for perl plug-ins?
Message-Id: <5n46km$nmd$2@cas.org>
According to Tom Phoenix <rootbeer@teleport.com>:
:On 30 May 1997, Mark Nielsen wrote:
:
:> Would it be possible to create a plug-in which would interpret perl
:> commands? -- so that you wouldn't have to program in java.
:
:I think you're looking for the Penguin project. Pengiun can do all of the
:main things that Java can do, except that it works on more kinds of
:systems, it uses Perl, and it fails to send a stream of money to Sun. :-)
Wow - what a great tip. How do I set things up so my netscape browser
can make use of Penguin as a plug-in. I've been searching for relevant
assistance now for about 2 yrs.
--
Larry W. Virden INET: lvirden@cas.org
<URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
Unless explicitly stated to the contrary, nothing in this posting should
be construed as representing my employer's opinions.
------------------------------
Date: 4 Jun 1997 16:27:57 GMT
From: lmegliol@inertia.acs.uci.edu (Leonard Megliola)
Subject: Atomic file create or fail if already existing
Message-Id: <5n452d$gl8@news.service.uci.edu>
I need an atomic operation which will create a new file if it
doesn't exists, but fail if the file already does exist. The goal
is to create unique (random) filenames, and (even though it is
unlikely given my method of generating the filenames) I would like
to avoid any race conditions. I've thought about different
variations on sysopen and open, but I don't think it is possible.
Maybe this is something I should not worry about. Any suggestions?
Thanks.
Leonard
------------------------------
Date: 4 Jun 1997 15:05:35 GMT
From: "The Videit" <videit@netaxs.com>
Subject: CMD32.EXE setup w/Win 95.
Message-Id: <01bb52f0$42ffa720$77d508cf@portable>
I can't get perl to use CMD32.EXE as the shell. What is the correct
registry setup, etc? The info in Win95.txt doesn't seem to work for me.
Using build 306.
Thank you in advance,
The Videit
videit@netaxs.com
------------------------------
Date: 4 Jun 1997 16:08:14 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Code examples: right justify text?
Message-Id: <5n43te$7uk$1@dartvax.dartmouth.edu>
In article <33946969.11658356@news-2.csn.net>
frelbel@N0SPAMcsn.net (Fred Elbel) writes:
> I'm about to design a routine to right justify text paragraphs, but
> perhaps it's already been done :) I checked various archives and
> haven't found anything yet.
>
> I need to reformat plain text paragraphs. Each line is terminated
> with \n. However, each line is too long - I need to shorten them to
> 55 characters or so.
>
> Code fragments or suggestions welcome.
Do you want all the lines to be exactly 55 characters long (with added
spaces between words to get the necessary length) or at most 55
characters long?
Is it okay to join shorter lines together, or do you only want to split
long lines?
What should be done if there is a string of consecutive non-white space
characters longer than 55 characters?
open (IN, $infile) || die "Unable to open $infile for input: $!";
open (OUT, $outfile) || die "Unable to open $outfile for output: $!";
# read in paragraphs at a time
$/ = '';
while (<IN>) {
# change newlines to spaces
tr/\n/ /;
# first character is at 0
$preidx = -1;
$idx = 54;
# repeat until past end of string
while ($idx <= length) {
# if not at white space, back up
if (substr($_, $idx, 1) !~ /\s/) {
$idx-- while ((substr($_, $idx, 1) !~ /\s/) &&
($idx > $preidx));
}
# if not at previous index, replace white space with newline
if ($idx != $preidx) {
substr($_, $idx, 1) = "\n";
}
# else at previous index, jump forward and insert newline
else {
$idx += 55;
substr($_, $idx-1, 0) = "\n";
}
# update previous index and index
$preidx = $idx;
$idx += 55;
}
} continue {
# change trailing white space back to newline(s)
s/\s\s$/\n\n/;
s/\s$/\n/;
# print the wrapped paragraph
print OUT;
}
Chipmunk
------------------------------
Date: 4 Jun 1997 14:49:47 GMT
From: "brian s." <brian@pluto.tekmarkinc.com >
Subject: COMPUTER JOBS NEEDED
Message-Id: <01bc70f6$b37b28b0$3291d4d0@brian>
Tekmark Computer Services Inc. Is currently in great demand for ALL Job
Seekers who have Computer Skills. We one of the largest computer
consulting firms in the United States. We place people all over the United
States and the World. We can place everyone. We need people with all
disciplines. If you have Oracle, Sybase, SQL, DB/2, DBA, CICS, Lotus
Notes, System Engineering, Project Management, Telephony, TCP/IP, Rotuers,
Switching, All MS Products (MS Office, Project, Excel, WIN 95/NT/3.x),
GUI, CGI, UNIX, C/C++, Orbix, Corba, Perl, Solaris, CMIP/CMIS, JCL,
COBOL/COBOLII, JAVA, Internet, Clipper, Visual Basic, Financial
Applications, LAN/WAN, MAINFRAME, PL/1, Client/Server, ActiveX, Year 2000,
OO, Powerbuilder, Help Desk, Tech Writers. If you have any of these
skills or Anything else I might have left out please drop me a line either
at 908.572.5400 ext. 249 or brian@pluto.tekmarkinc.com. OR fax me your
resume to 908.572.7117 ATTN: BRIAN S.. I also want to extend this
invitation to all other Consulting Companies seeking to place people with
these skills. Aswell as anyone who can recommend someone they know with
these skills. If we hire the person you get $1000.
We are on vendors list to most of the Country's top Telecommunication Firms
and Banking Houses. Most of the jobs are in the New York, New Jersey,
Chicago, Philadelphi, and Boston. We pay top dollar.
THANK YOU,
BRIAN SCHOENFELD
TEKMARK COMPUTER SERVICES INC
------------------------------
Date: 4 Jun 1997 09:30:45 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: ld problems (./so_locations) while building perl-5.004 on Irix-6.2
Message-Id: <5n3ck5$t0q$1@canopus.cc.umanitoba.ca>
In article <199705272200.SAA08853@shekel.mcl.cs.columbia.edu>,
Erez Zadok <ezk@cs.columbia.edu> wrote:
:I'm getting linker errors when trying to build perl-5.004 on Irix 6.2. I
:used all of the default options offered by perl's Configure script. My
:$PATH has /usr/bin before /usr/lib (so I get those versions of cc/ld/etc).
:The same failures happen when I tried old_ld or uld instead of ld.
:ld: ERROR 48: Cannot access registry file ./so_locations (No locks
:available) - ignored.
Try copying so_locations (which might be /usr/lib/so_locations)
to another file, removing the original, and mv'ing the copy back.
This procedure will break any stray record or file locks (as will
rebooting.)
Doing any compiling over NFS (is NFS involved?) is problematic
unless the remote end has full lockd support.
------------------------------
Date: Wed, 04 Jun 1997 10:46:20 -0400
From: Craig Martin <cmartin@interware.net>
Subject: Need help with PERL!
Message-Id: <33957FBC.2FA7@interware.net>
Hi There,
My name is Craig Martin and I am looking for some help with a
PERL
program I am trying to write. I don't know if this is the correct
newsgroup to be submitting this to, but there seems to be no specific
one for PERL programmers.
I have written a program to add information to a FLAT file using
a
simple PERL script, with each field seperated by a comma and then each
record divided by a line break. I now want to be able to search through
this FLAT file for keywords that users enter. For example, one of the
fields in this file is last name. SO if someone were to type in my last
name (Martin) regardless of case (ie. case insensitive) every line that
contained this word would be captured from the file and printed to the
screen. So far I can read in the keyword the user enters and de-webify
it, but I have NO IDEA how to open and read the FLAT file line by line.
ANY help in this matter would be much appreciated.
Thanks in advance.
--
Craig Martin
cmartin@interware.net
http://www.interware.net
mailto:cmartin@interware.net
------------------------------
Date: 4 Jun 1997 16:52:22 GMT
From: lvirden@cas.org
Subject: Re: Need vacation program in Perl!
Message-Id: <5n46g6$nmd$1@cas.org>
According to Nathan V. Patwardhan <nvp@shore.net>:
:Come to think of it, mailagent, a mail filtering program written in Perl
:seems to support a "vacation mode" if memory serves correctly. Mailagent
mailagent does indeed support a very nice vacation mode.
--
Larry W. Virden INET: lvirden@cas.org
<URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
Unless explicitly stated to the contrary, nothing in this posting should
be construed as representing my employer's opinions.
------------------------------
Date: 4 Jun 1997 16:17:32 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Newbie question
Message-Id: <5n44es$7uk$2@dartvax.dartmouth.edu>
In article
<Pine.GSO.3.96.970603162517.28549O-100000@kelly.teleport.com>
Tom Phoenix <rootbeer@teleport.com> writes:
> On 3 Jun 1997, Chipmunk wrote:
>
> > $nchars = scalar(split(//, $_));
>
> I know you were joking, but that won't do what you (probably) think it
> will. It's deprecated, and for good reason.
Tom and I continued this discussion over email. Here's the conclusion:
Tom sent me this code to demonstrate what really happens:
# A sub to find the lengths of several strings at once?
sub lengths {
my(@lengths, $len);
while (@_) {
$_ = shift;
$len = split //, $_;
push @lengths, $len;
}
@lengths;
}
The reason the above subroutine does not work (in fact, it goes into an
infinite loop) is that, in a scalar context, split "returns the number
of fields found and splits into the @_ array." - 1st Camel, pg 185.
Something I hadn't realized until Tom provided the above example.
So, if you really want to use my way of getting the length of a string
(hehe), this would be safer:
@temp = split(//, $_);
$nchars = scalar(@temp);
Chipmunk
------------------------------
Date: Wed, 04 Jun 1997 16:54:45 +0200
From: Dani Macho Ortiz <dani@apb.es>
Subject: Re: newbie question2
Message-Id: <339581B5.26FD@apb.es>
This one does work:
#!/opt/GNUperl5/bin/perl
unless(open (SM, "</home/dani/perl/test.txt")) {
die("Error! No puedo abrir el fichero de entrada test.txt\n");
}
$line = <SM>;
while($line ne '') {
if ($line =~ /picture ([0-9]{1,8})\.wmf/) {
$line =~ s/$1\.wmf/nice.gif/g;
print "LINE: $line\n";
}
$line = <SM>;
}
close(<SM>);
steven depuydt wrote:
>
> Is there a way to do this:
>
> open (SM,"test.txt");
> while(<SM>) {
> if (/picture ([0-9]{1,8})\.wmf/) {
> s/$1\.wmf/nice.gif/g;
> }
> }
> This piece of code doesn't work.
> I want to reuse the digits ([0-9]{1,8}) in my replecement rule.
> Is there a way to do this?
>
> Thanks for any help.
>
> Steven.
--
-------------------------------------
(
( )
( )
/\ ( ) *
/ \| | * * *
/ \_|__ *
/ | *
| [ ] | *
| == |_______________________
|__| |____|
wwww wwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwww wwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwww wwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwww wwwwwwwwwwwwwwwwwwwwwwwww
Dani Macho Ortiz
Autoridad Portuaria de Barcelona
Email: <dani@apb.es>
http://www.apb.es
-----------------------------------
------------------------------
Date: Wed, 04 Jun 1997 14:52:14 GMT
From: frelbel@csn.net (Fred Elbel)
Subject: Re: perl 5.03 by Activeware, for win95
Message-Id: <3397802a.5061675@news-2.csn.net>
On Tue, 3 Jun 1997 12:01:17 GMT, pauls@seanet.com (paul Spitalny)
wrote:
> I recently downloaded perl 5.03 from active and have set it up to run.
> I have found a funny little problem. Let's say I have a perl script in the
> directory c:\a\b\c called fred.bat. when I type "fred" in this directory perl
> seems to look for the script in another directory, a directory in the path
> variable in my autoexec.bat file. One obvious solution is to write all of my
> perl scripts in this directory in the path, but that is a pain.
>
> Is there any way to get perl to look in the current directory. Or, is there
> another way I should run perl??
I had lots of problems with my install. I added a path to perl/bin in
my autoexec.bat, and I can run Perl from any directory.
Here are some tips I picked up, which helped me immensely:
Thanks to Ivan Adzhubei, who discovered the following bug in the
automatic installer:
If you did not install your pdksh's sh.exe in f:/bin, check that you
have PERL_SH_DIR set in Config.sys, and it uses / (not \) - this is a
bug in the automatic installer - it sets a meaningless PERL_SHPATH
instead!
This correction is reported to fix the problem "backticks and pipes do
not work". Possibly the same fix may work under Win* and DOS?
Thanks for the post - it prompted me to review my install. Referring
to ActiveWare Perl 5.03 for Windows95 (Win32) (Build 302 - Dec. 13,
1996), here is an excerpt from their Windows95 install notes
(win95.txt):
Notes for Windows '95 Users
=====================
Build 105:
----------
Most of the compatibility problems that occured in previous builds are
due to the 16-bit shell (COMMAND.COM) use on Win95.( The problems
included pipes and shell escapes).
To fix the shell problems, we have shipped a 32-bit shell wrapper with
perl-win32.You can also configure perl to use another shell if you
like.
To change the shell setting you must edit the registry.
The string:
HKEY_LOCAL_MACHINE\Software\Microsoft\Resource Kit\PERL5\WIN95SHELL
must be set to the full path your shell.
================ end excerpt ==============
Their command shell is named /Perl/bin/Cmd32.exe
So after editing my registry (correctly, this time), pipes and
redirection now work.
Regards,
Fred
-- Fred Elbel frelbel@N0SPAMcsn.net
-- To e-mail: delete N0SPAM in my return address
-- How to eliminate junk mail and spam:
-- http://www.csn.net/~felbel/jnkmail.html
------------------------------
Date: Wed, 04 Jun 1997 10:56:00 -0500
From: Jim Garrison <jhg@austx.tandem.com>
To: libwww-perl@ics.uci.edu
Subject: Possible bug in URI::URL?
Message-Id: <33959010.167E@austx.tandem.com>
Consider
use URI::URL;
.
.
$base = "http://myserver.domain.com";
$url = "/test/banner.html";
$u = new URI::URL($url,$base);
print $u->abs,"\n";
print $u->host,"\n";
I expect the output to be
http://myserver.domain.com/test/banner.html
myserver.domain.com
However, the actual output is
http://myserver.domain.com/test/banner.html
<blank line>
A similar result (an empty string) is returned
for the scheme method.
i.e. when a default base is provided and the url
is relative, the host and scheme methods still
return an empty string. Is this the way it was
intended to work? It seems to me that if I
provide a default base, then the host and
scheme (and user,password & port) methods should
use the default if necessary.
--
James Garrison mailto:jhg@mpd.tandem.com
Tandem Computers, Inc
14231 Tandem Blvd, Rm 1038 Phone: (512) 432-8455
Austin, TX 78728-6699 Fax: (512) 432-8247
------------------------------
Date: 04 Jun 1997 19:50:12 +0200
From: Gisle Aas <aas@bergen.sn.no>
Subject: Re: Possible bug in URI::URL?
Message-Id: <hn2p6l0kr.fsf@bergen.sn.no>
Jim Garrison <jhg@austx.tandem.com> writes:
> Consider
> use URI::URL;
> .
> .
> $base = "http://myserver.domain.com";
> $url = "/test/banner.html";
> $u = new URI::URL($url,$base);
> print $u->abs,"\n";
> print $u->host,"\n";
>
> I expect the output to be
> http://myserver.domain.com/test/banner.html
> myserver.domain.com
>
> However, the actual output is
> http://myserver.domain.com/test/banner.html
> <blank line>
>
> A similar result (an empty string) is returned
> for the scheme method.
>
> i.e. when a default base is provided and the url
> is relative, the host and scheme methods still
> return an empty string. Is this the way it was
> intended to work?
I think so.
> It seems to me that if I
> provide a default base, then the host and
> scheme (and user,password & port) methods should
> use the default if necessary.
I think one could argue for both. You could always say:
print $url->abs->host, "\n";
--
Gisle Aas <aas@sn.no>
------------------------------
Date: 4 Jun 1997 11:12:48 -0400
From: kevin@shady.com (Kevin Smith, ShadeTree Software, Inc.)
Subject: Re: Reading Comma delimited, Quoted String records
Message-Id: <5n40lg$htq@shady.shady.com>
In article <nj00n5.3ph.ln@localhost> tadmc@flash.net (Tad McClellan) writes:
>
>...
>
>Perl FAQ, part 4:
>
>--------------------------------------------------------------------
>=head2 How can I split a [character] delimited string except when
> inside [character]? (Comma-separated files)
>
>Take the example case of trying to split a string that is comma-separated
>into its different fields. (We'll pretend you said comma-separated, not
>comma-delimited, which is different and almost never what you mean.) You
>can't use C<split(/,/)> because you shouldn't split if the comma is inside
>quotes. For example, take a data line like this:
>
> SAR001,"","Cimetrix, Inc","Bob Smith","CAM",N,8,1,0,7,"Error, Core Dumped"
>
>Due to the restriction of the quotes, this is a fairly complex
>problem. Thankfully, we have Jeffrey Friedl, author of a highly
>recommended book on regular expressions, to handle these for us. He
>suggests (assuming your string is contained in the special variable
>$_):
>
> @new = ();
> push(@new, $+) while $text =~ m{
> "([^\"\\]*(?:\\.[^\"\\]*)*)",? # groups the phrase inside the quotes
> | ([^,]+),?
> | ,
> }gx;
> push(@new, undef) if substr($text,-1,1) eq ',';
>--------------------------------------------------------------------
Isn't it assuming the string is in $text?
--
Cool Beans! Kevin Smith
- Chump ShadeTree Software, Inc.
Philadelpha, PA Voice: 001-215-487-3811
sysop@bbs.cpcn.com Email: kevin@shady.com (shady!kevin)
------------------------------
Date: Wed, 04 Jun 1997 10:32:55 -0600
From: lucas albers <albersl@cs.montana.edu>
Subject: simple question about running system programs from with perl.
Message-Id: <339598B6.B9C525E7@cs.montana.edu>
Question: How to run grep from within perl and put the output in a
string or list.
Here is what I've tried so far, from the book.
system('grep "searchstring", filename')
or
$output = system('grep');
That will just return the letter 0, or 1 from the unsuccesful completion
of a program in unix. $output has the value of 0.
I want to run system commands and pass in variables to it.
So for example you could run grep so that (after aliasig it to whatever)
so that it will
prompt you for a searchstring and then a filename before you run it.
--
--Lucas Albers
albersl@esus.cs.montana.edu
------------------------------
Date: Wed, 04 Jun 1997 12:18:15 -0500
From: Buxx <buxx@buxx.com>
Subject: Re: simple question about running system programs from with perl.
Message-Id: <3395A357.5ABC@buxx.com>
lucas albers wrote:
>
> Question: How to run grep from within perl and put the output in a
> string or list.
> Here is what I've tried so far, from the book.
>
> system('grep "searchstring", filename')
> or
> $output = system('grep');
> That will just return the letter 0, or 1 from the unsuccesful completion
> of a program in unix. $output has the value of 0.
>
> I want to run system commands and pass in variables to it.
> So for example you could run grep so that (after aliasig it to whatever)
> so that it will
> prompt you for a searchstring and then a filename before you run it.
>
> --
> --Lucas Albers
> albersl@esus.cs.montana.edu
later perl releases have their own grep
--
/_/_/_/ Steve Vandiver Billings, Missouri, USA
_/ _/ mailto:buxx@buxx.com http://www.buxx.com
_/_/_/ _/ _/ _/ _/ _/ _/ "Find out what you
_/ _/ _/ _/ _/ _/ don't do well, then
/_/_/_/ _/_/_/ _/ _/ _/ _/ don't do it" - Alf
------------------------------
Date: Wed, 04 Jun 1997 17:17:36 +0200
From: Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>
Subject: Re: String Compare Problem
Message-Id: <33958710.794B@theo.phy.uni-bayreuth.de>
Hi,
Paul Cartier wrote:
>
> Could someone give me an example on how I can search the
> begining of a string for a match.
>
> script compare code:
>
> for ($x = @word_list; $x > 0; $x--) {
> $match_word = $word_list[$x - 1];
> if ($db_value =~ /$match_word/) {
^^
=============== insert a '^' here =============
> splice(@word_list,$x - 1, 1);
> } # End of If
> } # End of For Loop
Bye, Eike
--
======================================================================
Eike Grote, Theoretical Physics IV, University of Bayreuth, Germany
----------------------------------------------------------------------
e-mail -> eike.grote@theo.phy.uni-bayreuth.de
WWW -> http://www.phy.uni-bayreuth.de/theo/tp4/members/grote.html
http://www.phy.uni-bayreuth.de/~btpa25/
======================================================================
------------------------------
Date: 4 Jun 1997 15:26:56 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: String comparsion
Message-Id: <5n41g0$296$1@dartvax.dartmouth.edu>
In article <01bc6bf1$f5641ac0$0e1f849e@fg702-4.polyu.edu.hk>
"Alexander K. M. Leung" <kmleung@fg702-6.abct.polyu.edu.hk> writes:
> $option=<STDIN>
> if ($option="a") {
> :
> } elsif ($option="b") {
> :
> } elsif ($option="c") {
> :
> }
You're doing assignment, not string comparison.
Numeric comparisons are ==, !=, <, >, <=, >=, <=>.
String comparisons are eq, ne, lt, gt, le, ge, cmp.
Chipmunk
------------------------------
Date: 4 Jun 1997 15:21:32 GMT
From: "CAD-VISIOGRAPH" <visiocad@easynet.fr>
Subject: Telnet
Message-Id: <01bc70fa$c5dd97a0$085c72c3@visiocad.easynet.fr>
can I execute a Telnet with PERL and giving automaticaly the username and
the password ?
------------------------------
Date: Wed, 04 Jun 1997 16:28:41 GMT
From: zawodny@hou.moc.com (Jeremy D. Zawodny)
Subject: Re: Telnet
Message-Id: <33959630.86902198@igate.hst.moc.com>
On 4 Jun 1997 15:21:32 GMT, "CAD-VISIOGRAPH" <visiocad@easynet.fr>
wrote:
>can I execute a Telnet with PERL and giving automaticaly the username and
>the password ?
Uhm, maybe...
You can execute virtually *any* program from within a Perl script
using either system() or the backticks (`command`). It's just a
question of finding a telnet client that will let you either pass the
username and password on the command-line, or one that will let you
pipe that in.
In either case, you're probably approaching this the wrong way. Perl
can "do telnet" using all Perl code. You'd just need to open a TCP
conection to port 23 of the host you'd like to connect to and chat
with it.
Good luck,
Jeremy
------------------------------
Date: Wed, 04 Jun 1997 16:09:11 +0200
From: Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>
Subject: Re: tr problems with variables
Message-Id: <33957707.446B@theo.phy.uni-bayreuth.de>
Hi,
Dani Macho Ortiz wrote:
>
> We've got a problem if we want to make a translation
> of characters an if these ones are defined into variables:
>
> $char1 = "x";
> $char2 = "w";
> $cad = "HelloxPerlxNewsx!";
>
> $_ = $cad;
> $changes = tr /$char1/$char2/;
> print "CHANGES: $changes\n";
>
> The previous code would print "CHANGES: 0"!!
>
> Do you know why and how could we do what we intend to?
>
Didn't you take a look at the manual pages of perl? 'man perlop'
says (at "tr/SEARCHLIST/REPLACEMENTLIST/cds"):
Note that because the translation table is built at compile
time, neither the SEARCHLIST nor the REPLACEMENTLIST are
subjected to double quote interpolation. That means that
if you want to use variables, you must use an eval() :
eval "tr/$oldlist/$newlist/";
die $@ if $@;
eval "tr/$oldlist/$newlist/, 1" or die $@;
Bye, Eike
--
======================================================================
Eike Grote, Theoretical Physics IV, University of Bayreuth, Germany
----------------------------------------------------------------------
e-mail -> eike.grote@theo.phy.uni-bayreuth.de
WWW -> http://www.phy.uni-bayreuth.de/theo/tp4/members/grote.html
http://www.phy.uni-bayreuth.de/~btpa25/
======================================================================
------------------------------
Date: Wed, 04 Jun 1997 08:55:55 -0700
From: Robert U Myers <robertmy@pogo.wv.tek.com>
Subject: Using debugger with formats in the file
Message-Id: <3395900B.603F@pogo.wv.tek.com>
When I have formats in my file the debugger never stops at break
points. Is this problem specific to me?
--
-Bob Myers
____________________________________________________________________________
Desk: (503) 685-2471 Pager: 204-8930
Group: CPID ME Tools
Email: Robert.U.Myers@tek.com
Mail: 60-431
------------------------------
Date: 04 Jun 1997 12:12:18 -0400
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
Subject: Re: What's perl equivalent to awk's $1, $2, etc.?
Message-Id: <m167vue49p.fsf@nauplius.psc.sc.edu>
shaug@callamer.com (O'Shaughnessy Evans) writes:
> In article <33907DAA.3B60@indiana.edu>,
> "D.F. Parkhurst" <parkhurs@indiana.edu> writes:
> ...
> > I have three books on perl, but can't find concepts like "field" or
> > "parsing" in the index of any of them. Is there an equivalent concept
> > to $1 (etc.) in perl, and if so, what is it called?
...
> As far as splitting up
> the lines of a file goes, try something straightforward like this to get a
> feel for how split() works:
>
> #!/bin/perl -w
>
> while ($in = <>) {
> @fields = split(' ', $in);
>
> for ($i=0; $fields[$i]; $i++) {
> print "$i: $fields[$i]\n";
> }
> print "\n";
> }
A couple of minor nits to pick (though there is always More Than One
Way to Do It in Perl):
Subscripting tends to be time-inefficient in Perl, relative to list
operations, so I'd tend to use the @fields list directly, rather than
subscripting into it.
Another issue is that the for-loop ending condition is a bit dicey in
the code above: the loop will end either when $fields[$i] becomes
undefined (the presumptive desired condition) or when $fields[$i] is
equal to 0. Ouch. (In fact, perl 5.004 will give you a warning
message about this behavior if you're running with "-w").
So... how about:
#!/bin/perl -w
use strict;
while (<>) {
my(@fields) = split(' ', $_);
my($i) = 0;
for (@fields) {
print $i++, ": $_\n";
}
print "\n";
}
Or even:
#!/bin/perl -w
use strict;
while (<>) {
my($i) = 0;
for (split(' ', $_)) {
print $i++, ": $_\n";
}
print "\n";
}
Or...
#!/usr/local/bin/perl -w
use strict;
while (<>) {
my($i) = 0;
print map {$i++, ": $_\n"} split(' ', $_);
print "\n";
}
(Just having fun...)
-Dean
--
N. Dean Pentcheff <pentcheff@acm.org> WWW: http://tbone.biol.sc.edu/~dean/
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-3936)
PGP ID=768/22A1A015 Keyprint=2D 53 87 53 72 4A F2 83 A0 BF CB C0 D1 0E 76 C0
Get PGP keys and information with the command: "finger dean@tbone.biol.sc.edu"
------------------------------
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 569
*************************************