[6603] in Perl-Users-Digest
Perl-Users Digest, Issue: 228 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 3 15:16:51 1997
Date: Thu, 3 Apr 97 12:00:21 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 3 Apr 1997 Volume: 8 Number: 228
Today's topics:
Re: Advice/suggestions: Perl under DOS <dean@tbone.biol.sc.edu>
CFP: 7th ECOOP PHDOOS workshop [NB: <2 weeks deadline] <eernst@fraxinus.daimi.aau.dk>
Re: File Read/Write Problem (Simon Hyde (aka Jeckyll))
Re: Getting the contents of a URL. <tchrist@mox.perl.com>
Help Doing a chomp type function <allenm@lexis-nexis.com>
Re: Help Doing a chomp type function (Nathan V. Patwardhan)
Re: Help doing a print from an array (Matthew Cravit)
Re: How to declare (or my) a $$var variable? (Simon Hyde (aka Jeckyll))
Multidimensional Arrays! (Desmond Ye-Ket NG)
Re: New Microsoft Perl Product (fwd) ()
Re: New Perl Web Page (Simon Hyde (aka Jeckyll))
ORAPERL Binary <steven.j.rheintgen@lmco.com>
Re: Perl vs. C/C++ (Simon Hyde (aka Jeckyll))
Please - need help with for loop on hostname script jsykes@tartar.ulib.albany.edu
Re: Running program on a remote machine (Simon Hyde (aka Jeckyll))
Re: server directory protection vs. cgi-bin style passw (Simon Hyde (aka Jeckyll))
Re: Simple array question by newbie... j.mcgahen@realogic.com
Re: Visual Perl++????? ()
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 03 Apr 1997 13:21:43 -0500
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
To: Rodney Broom <broomer2@primenet.com>
Subject: Re: Advice/suggestions: Perl under DOS
Message-Id: <m1ohbwrmq0.fsf@nauplius.psc.sc.edu>
[Note: since this is not a query related to Perl modules, I've
redirected this reply to c.l.p.m]
Rodney Broom <broomer2@primenet.com> writes:
> OK, I have this little 386 running DOS 6.22, no windows. I would like to
> use it a developement platform for Perl. I have a P120 Win95 machine
> also and I have had no problems making Perl work there. I have seen
> people talking about using the OS2 version, but, I'm having troubles
> determining what files to take from these FTP sites. Also, I am looking
> for the binaries.
Appended is a posting I made a few months ago. I suspect it's still
largely accurate, but some details may have changed with time.
But... it should give you the necessary details to do what you'd like.
-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"
============================================================================
I recently went through the exercise of hunting for a DOS/Win Perl,
needing to write a Perl program that would run on Unix, DOS 5, and
Windows 95/NT, and be distributable (along with Perl) with a minimum
of fuss.
I settled on Ilya Zakharevich's OS/2 port of Perl. Yup. It will run
on DOS and Windows systems. It's a very full Perl port that is
aggressively maintained and kept up to date.
You'll need to tinker slightly. Following is an outline of a recipe
that worked for me.
Grab the port from CPAN. Start at <URL:http://www.perl.com/perl> and
look for "Software", then "Alien Ports", then "CPAN/ports", and follow
links until you get to OS/2 ports, and then the "ilyaz" directory.
Once there, look for the most recent version in a directory that looks
something like "5.003.05" (of course, that number will change as
versions get updated). Within that is a set of zip files. Get these
files:
perl_aou.zip
perl_mlb.zip
perl_pod.zip
perl_ste.zip
perl_utl.zip
plREADME.zip
Make sure you have a decent unzip utility on DOS/Win. One that works
is Info-Zip's, which you can grab from the "arcers" directory of the
MSDOS section of the Simtel archives at oak.oakland.edu
(<URL:http://oak.oakland.edu/pub/simtelnet/msdos/arcers/unz520x.exe>).
That file will unzip into multiple files, including a good DOS unzip
program. The reason you need a good one is that you need to unzip
into a tree, and you need to properly truncate long filenames -- that
unzipper seems to do the job properly.
OK, now that you've got the code and an unzipper, do the following to
create a Perl hierarchy (the following manipulation gets done from a
DOS window, if you're under Windows):
cd \
mkdir perl
mkdir perl\bin
mkdir perl\lib
mkdir perl\lib\pod
Now unpack the zip files into appropriate directories. To do that,
change directories to the target directory first, then from there,
unzip the archive files as follows:
perl
plREADME.zip
perl\bin
perl_aou.zip
perl_utl.zip
perl\lib
perl_mlb.zip
perl_ste.zip
perl\lib\pod
perl_pod.zip
Put the following in your autoexec.bat (carefully noting the slash
directions in the text that follows):
set path=...your...existing...path...;c:\perl\bin
set perllib_prefix=f:/perllib c:/perl
(I assume your perl destination is drive "c:", otherwise modify the
"c:"s above appropriately, but don't change the "f:").
===== Note: The following is from Ilya Zakharevich: =====
As I mentioned it in another post today, unless you install sh.exe
from sh_dos.zip, and set PERL_SH_DIR according to the docs, you are
not going to have backticks and pipes working.
=========================================================
Now, based on addresses in Ilya's documentation, go out and grab the
latest versions of the "emxrt" package and the "rsx" package. Unzip
them under a temporary directory. Copy the following files to
c:\perl\bin:
from the emx package:
emx.exe [VCPI DOS extender for DOS]
emxfpemu [coprocessor emulator for 386sx machines]
emxbind.exe [emx executable load-format twiddling program]
emxl.exe [emx stub loader module]
from the rsx package:
rsx.exe [DPMI DOS extender for Windows]
Now drop out into DOS if you're running under Windows (not a DOS
shell: if you're in Windows, kill Windows and drop to plain DOS).
Go to the c:\perl\bin directory and use emxbind to extract the a.out
module from perl_.exe, something like:
emx emxbind.exe -x perl_.exe perl.out
Use emxbind to bind the a.out module with the emxl.exe stub:
emx emxbind.exe emxl.exe perl.out perl.exe
Assuming that worked, you can now delete the following files:
emxbind.exe
emxl.exe
perl.out
perl_.exe
perl5_00.exe
If you're really twitchy about a startup warning message under
Windows, you can use a hex editor or other binary editor to edit the
file "rsx.exe" so that it will not complain about the emx version
you're using. In the file "rsx.exe", search for the string
"emx_version". You'll find the emx version number in reverse,
something like: "emx_version=b9.0" (which really refers to emx version
number 0.9b). Change the version number/letter to fit the emxrt
version you downloaded (in my case, recently, I changed "b9.0" to
"c9.0", which defines me as really twitchy I suppose). Save the new
rsx.exe (must be in the filename "rsx.exe"). Then the runtime warning
about emx versions will shut up.
Reboot your machine to let the c:\autoexec.bat changes take effect.
What have you achieved by this? The OS/2 version will run using
either the emx.exe DOS extender (using the VCPI protocol, suitable for
"naked" DOS) or the rsx.exe extender (using the DPMI protocol,
compatible with Windows 3.x, 95 (and NT?)). The rigamarole with
emxbind pulled out the core executable and rebound it with a stub
loader that will automatically and transparently find and use the
emx.exe extender in plain DOS, and the rsx.exe extender under Windows
(as long as they're in a directory on the PATH). Setting the
emxlib_prefix variable properly sets Perl's @INC list of where to
search for Perl libraries.
The "utility" programs in \perl\bin are set up as OS/2 "cmd" files.
You'll need to trim off the top few lines that get them to execute
under the OS/2 command interpreter. There are magical incantations
you can do to turn them into automatically executing DOS batch files
(which I don't know), or you can create a batch file for each of them
(in the same directory) that looks something like the following (for
an example "utility.cmd" file):
@perl -S utility.cmd %1 %2 %3 %4 %5 %6 %7 %8 %9
in the file "\perl\bin\utility.bat".
And that's that!
------------------------------
Date: 03 Apr 1997 17:06:34 +0200
From: Erik Ernst <eernst@fraxinus.daimi.aau.dk>
Subject: CFP: 7th ECOOP PHDOOS workshop [NB: <2 weeks deadline]
Message-Id: <yz8lo70cfid.fsf@fraxinus.daimi.aau.dk>
|-----------------------------------------------------------------------|
| |
| 7th ECOOP Workshop for Doctoral Students in Object-Oriented Systems |
| |
|-----------------------------------------------------------------------|
| |
| Jyvaskyla, Finland, June 9/10, 1997 |
| |
|-----------------------------------------------------------------------|
| Please accept our apologies if you receive multiple copies of this. |
|-----------------------------------------------------------------------|
CALL FOR PARTICIPATION
The aim of the workshop is to bring together PhD students who are
working on foundations, design, implementation, or application of
object-oriented systems and methods.
The workshop will provide an opportunity for PhD students to
meet, to discuss their research, and to further develop their
working skills. It will generally be interactive, focusing on
active work in groups.
Another function of the workshop is to continue and enlarge the
international network of PhD students in object-oriented systems
(PhDOOS), which has been initiated at the 1st workshop, held in
conjunction with ECOOP'91 in Geneva/Switzerland. The PhD network
counts approximately 125 members from all over the world, all of
them PhD candidates. The network's mailing list and WWW pages
are used mainly for information and discussion of OO-related
topics. More information on the PhDOOS can be found at
http://mbi.dkfz-heidelberg.de/PhDOOS/
It is also a tradition to take advantage of the fact that people
are gathered, by going together to a restaurant or similarly
after the regular programme of the day.
TOPICS
The technical programme of the workshop will be held in subgroups,
followed by a summary session of all attendants. In the subgroups,
discussions on 3-4 related topics will be held, bringing together
participants who work in related areas. The discussions will be
based on position statements and paper presentations (see below).
The corresponding abstracts and papers will be electronically
distributed among the participants in advance. An overview of the
work of each subgroup will be prepared and presented in the plenary
session later.
The non-technical programme consists of two keynote talks by
invited speakers about the PhD-getting process and conducting
research, a writing workshop, and discussions about the results of
the preECOOP initiative of the PhDOOS network, about further
developments of the PhDOOS network, and about the social situation
of PhD students.
The workshop results will be collected in a report covering the
technical as well as the non-technical results.
HOW TO APPLY
Since this workshop is associated with the PhDOOS Network you should
become a member of this network to participate in the workshop.
If you are not already a member you should send a one-page (500
words) abstract of your dissertation research. The abstract should
be submitted electronically as soon as possible, using the WWW form
<URL:http://mbi.dkfz-heidelberg.de/PhDOOS/CfP.html>
or by email to
<URL:mailto:A.M.Demiris@DKFZ-Heidelberg.de>.
Applicants can either apply for a short position statement of 5
minutes or a presentation of 20 minutes time. If applying for
a presentation, a paper covering its contents has to be submitted.
This paper would typically be 3-8 pages and its primary purpose is
to give other participants an overview of your work and allow them
to recall it later on. Papers should be submitted electronically
till April 15th, 1997, to eernst@daimi.aau.dk. The papers and the
network abstracts will be made available to the workshop
participants prior to the workshop and will serve as the basis for
the technical discussions at the workshop.
TIMETABLE
April 15th, 1997: deadline for paper submission to
eernst@daimi.aau.dk
May, 2nd, 1997: notification of acceptance, distribution of
abstracts and papers, call for working group
proposals
May, 20th, 1997: notification on established working groups
ORGANIZERS:
Frank Gerhardt gerhardtf@str.daimler-benz.com
Mercedes-Benz AG, OD/IT
Methoden und Verfahren
E702
D-70322 Stuttgart
Germany
Lutz Wohlrab lwo@informatik.tu-chemnitz.de
Technische Universitaet Chemnitz-Zwickau
Fakultaet fuer Informatik
Lehrstuhl Betriebssysteme
D-09107 Chemnitz
Germany
Erik Ernst eernst@daimi.aau.dk
Gammel Viborgvej 106
DK-8381 Mundelstrup
Denmark
|-----------------------------------------------------------------------|
| PhD students normally not able to attend due to a lack of funding |
| are encouraged to contact Lutz about this. We have obtained some |
| financial support for workshop participation. |
|-----------------------------------------------------------------------|
--
Erik Ernst eernst@daimi.aau.dk
Computer Science Department of Aarhus University, Denmark
------------------------------
Date: Thu, 03 Apr 1997 18:44:20 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: File Read/Write Problem
Message-Id: <3343b63d.109639@news.uni-stuttgart.de>
On Wed, 02 Apr 1997 23:25:27 -0500, brian nahas
<bnahas@darwin.cc.nd.edu> wrote:
>Hi,
> I need a little help. I am trying to open a file
>for read and write access. I am trying to read up to a certain
>point and then write over the rest. I am opening the file using:
>open(FILEHANDLE,"+<filename");
>This allows me to read up to a certain point, but then when I write
>it appends to the end of the file. If I use:
>open(FILEHANDLE,"+>filename");
>I am not able to read from the file. It is a rather large file
>so I do not want to have to read it all in to an array and then
>do my editing. Any help would be greatly appreciated. Thanks.
>-Brian Nahas
from the perlfunc seek manpage
(http://www.perl.com/perl/nmanual/pod/perlfunc/seek.html):
On some systems you have to do a seek whenever you switch between
reading and writing. Amongst other things, this may have the effect of
calling stdio's
clearerr. A ``whence'' of 1 (SEEK_CUR) is useful for not moving the
file pointer:
seek(TEST,0,1);
------------------------------
Date: 3 Apr 1997 17:37:59 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Getting the contents of a URL.
Message-Id: <5i0ptn$o36$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, SFAIREY@dsl.uk.ibm.com (Fairey Simon) writes:
:What he wants to do is have a script that when supplied with a URL will
:return the contents of the page in text format.
>From the perlfaq, part 9. See http://www.perl.com/perl/faq/index.html for
details and other cool informmation that will help you in your journey.
How do I fetch an HTML file?
Use the LWP::Simple module available from CPAN, part of the
excellent libwww-perl (LWP) package. On the other hand, and if
you have the lynx text-based HTML browser installed on your
system, this isn't too bad:
$html_code = `lynx -source $url`;
$text_data = `lynx -dump $url`;
The FAQ doesn't say this (but should: Gnat, please add a rendition of
the following to part9)), but all you have to do is something like this,
once you have the LWP suite of modules:
perl -MLWP::Simple -e 'getprint "http://www.sn.no/libwww-perl/"'
One advantage to this approach is that it works through a proxy, assuming
everything is set up for that. See lwpcook(1) and friends for deatils.
Hm.. that just gets it as HTML. If you want it as text, you'll have
to do something more like this:
perl -MHTML::Parse -MLWP::Simple -MHTML::FormatText
-e 'print HTML::FormatText->new->format(parse_html(get("http://perl.com/")))'
Or as a program:
#!/usr/bin/perl -w
use LWP::Simple;
use HTML::Parse;
use HTML::FormatText;
print HTML::FormatText->new->format(parse_html(get("http://perl.com/")));
Error checking and argument parameterization have been left as an exercise
for the reader.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
/* we have tried to make this normal case as abnormal as possible */
--Larry Wall in cmd.c from the perl source code
------------------------------
Date: Thu, 03 Apr 1997 12:54:10 -0500
From: Allen May <allenm@lexis-nexis.com>
Subject: Help Doing a chomp type function
Message-Id: <3343EEC2.7794@lexis-nexis.com>
I want to find where each users home account is.. I am doing
a:
#!/serve/bin/perl -w
open(USERS, "user_list") || die "could not open file ($!)";
while(<USERS>) {
$person="$_";
$local = `ypcat passwd | grep $person`;
print $local;
}
I want to remove the exta info that the ypcat gives me. I tried doing
a $local =~ s/^$person//g; to start widdling away at the output of
$person
but it doesn't work.
Any suggestions?
-Allen
+---------------------------------------------------------------+
| ____ _ |
|Allen H. May |__\_\_o____/_| |
|LEXIS-NEXIS Help Desk Engineer <[___\_\_-----< |
|email - Allen.May@lexis-nexis.com | o' |
| |
+---------------------------------------------------------------+
------------------------------
Date: 3 Apr 1997 18:07:35 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Help Doing a chomp type function
Message-Id: <5i0rl7$po1@fridge-nf0.shore.net>
Allen May (allenm@lexis-nexis.com) wrote:
: #!/serve/bin/perl -w
: open(USERS, "user_list") || die "could not open file ($!)";
: while(<USERS>) {
: $person="$_";
: $local = `ypcat passwd | grep $person`;
: print $local;
: }
You might want to chop each line ($_) as it is read out of the
data file, and also chop $local to strip the trailing \n that ypcat
might give you.
Naturally, some of the below can be simplified into one-liners, but
I'll leave that to your discretion.
Here:
#!/serve/bin/perl -w
open(USERS, "user_list") || die "could not open file ($!)";
while(<USERS>) {
chop;
$person=$_;
$local = `ypcat passwd | grep $person`;
chop($local);
print $local;
}
close(USERS);
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: 3 Apr 1997 11:28:38 -0800
From: mcravit@best.com (Matthew Cravit)
Subject: Re: Help doing a print from an array
Message-Id: <5i10d6$juk@shellx.best.com>
[Courtesy cc to cited author via email]
In article <3343B60B.7229@lexis-nexis.com>,
Allen May <allenm@lexis-nexis.com> wrote:
>I think I am making this more difficult than I should but
>it's not workin'.
>
>I have a list of users in a file called user_list. I want
>to open the file as an array then get a print of each user
>on the list.
I'm not sure what you mean by "open the file as an array". I assume
you mean you want to read the contents of the file into an array that
you can then manipulate.
>@TESTS = USERS;
This definitely doesn't do what I think you want it to.
> print (@TESTS[$count]);
> @TESTS[$count++];
These two lines of code also don't quite do what I think you want them to.
You're trying to iterate over the elements in the array, I think. To read
a list of names into an array, and then iterate over the elements of the
array and do stuff, try something like this:
----------
#!/usr/local/bin/perl
open (FILE, "user_list") or die("Could not open the file: $!\n");
while (<FILE>)
{
chomp;
push (@userlist, $_);
}
close(FILE);
foreach $user (@userlist)
{
print "The user is $user\n";
}
---------
This does what I think you meant by your original question.
Hope this helps.
/MC
--
--
Matthew Cravit, N9VWG | Experience is what allows you to
E-mail: mcravit@best.com (home) | recognize a mistake the second
mcravit@taos.com (work) | time you make it.
------------------------------
Date: Thu, 03 Apr 1997 18:44:26 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: How to declare (or my) a $$var variable?
Message-Id: <334bcf66.6551884@news.uni-stuttgart.de>
On 1 Apr 1997 22:10:32 GMT, whc@mink.att.com (Wing Choy) wrote:
>I have large CGI form that has many fields and I using the
>following code to make it become a local variable in my perl
>script:
>
>foreach $var ($query->param)
>{
> # retrieve CGI variable and make it an actual perl variable
> $$var = $query->param($var);
This isn't doing what you want it to, you might want to try using eval
like this:
eval("\$$var = \$query->param(\$var)");
or even better just using an associative array (hash) like this:
$in{$var} = $query->param($var);
(this can be declared using my(%in) before you use it)
------------------------------
Date: 3 Apr 1997 19:50:45 GMT
From: desmond@lisa.cs.mcgill.ca (Desmond Ye-Ket NG)
Subject: Multidimensional Arrays!
Message-Id: <5i11ml$eq5@sifon.cc.mcgill.ca>
Hello,
I am having some trouble with 2D arrays in PERL5.
This is my code
open (OUT, "+> file.out") || die;
{
@input = split (' ', $_);
print;
for $i (0..$#input)
{
print "i: $i input: $input[$i]\n";
if(!defined ( $counter[$i]))
{
$counter[$i] = 0;
}
$arr[$i][$counter[$i]] = $input[$i];
print "counter[i]: $counter[i]\n";
$counter[$i] = $counter[$i] + 1;
print OUT "array = "$arr[$i][$counter[$i]]"\n";
}
}
close (OUT);
close (DATA);
at the print to the filehandle OUT, everything is blank. I printed the
counter and the input and it was fine. Can anyone please tell me what is
wrong here?
Thanks in advance.
-Desmond Ng
desmond.ng@ec.gc.ca
------------------------------
Date: 3 Apr 1997 14:18:50 GMT
From: scott@lighthouse.softbase.com ()
Subject: Re: New Microsoft Perl Product (fwd)
Message-Id: <5i0e8a$9dg$1@mainsrv.main.nc.us>
Alan Bostick (abostick@netcom.com) wrote:
: Visual Perl++
This is obviously an April Fool's Joke, but if Microsoft really
did write a Perl++ that:
1. Had a switch statement
2. Compiled perl to native code instead of interpreted it
3. Allowed use of Visual J++'s debugger
They'd probably sell a lot of copies. A LOT of copies.
:Now Microsoft synergizes that power and utility with Object-Oriented
:Programming and Microsoft's Object Linking and Embedding (OLE) support
:with Visual Perl++, multiplying them beyond imagining and bringing them
:to the Windows 95 environment.
The Win32 port of Perl already does this :)
:* Translator Wizard - a utility to translate Visual Perl++
: source code into C++, ready for compiling and linking to
:executables.
This is hardly something to joke about. A Perl "compiler", even
one as simplistic as something that slapped an interpreter
DLL and tokenized code together with a C runtime library,
would be a BIG, BIG seller. People *WANT* this, and with
Visual Basic's success, apparently don't care if it is slow.
Packaging the perl interpreter in such a way that it was
very easy to redistribute programs would appeal to a lot
of people.
Scott
------------------------------
Date: Thu, 03 Apr 1997 18:44:25 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: New Perl Web Page
Message-Id: <334acb4f.5504847@news.uni-stuttgart.de>
On 2 Apr 1997 20:47:58 GMT, Jason Many <cgi@ctfire.com> wrote:
>A brand new CGI/Perl web page has just opened!
>
>Check out The CGI-BIN at http://www.ctfire.com/thebin/
>
>It's the largest single collection of CGI scripts on the web!
>
>The CGI-BIN includes CGI scripts to run message boards, chat programs,
>passworded pages, mailing lists, shopping carts, and a lot more!
As we explained to you on #perl that is a CGI site, not a perl site,
go advertise it in comp.infosystems.www.authoring.cgi
------------------------------
Date: Wed, 02 Apr 1997 18:28:19 -0500
From: "Steven J. Rheintgen" <steven.j.rheintgen@lmco.com>
Subject: ORAPERL Binary
Message-Id: <3342EB93.320D@lmco.com>
I have not been successful in finding oraperl binary for a sun solaris
operating system version 2.5. Can anyone help!
Thanks
------------------------------
Date: Thu, 03 Apr 1997 18:44:23 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: Perl vs. C/C++
Message-Id: <3348c218.3145567@news.uni-stuttgart.de>
On Wed, 02 Apr 1997 14:38:26 -0800, Dan Corbett <dcorbett@jcaho.org>
wrote:
> 1) How easy is it to learn?
That really depends on the person, but I found it pretty easy with a
bit of basic C knowledge, and some basic (yes that ghastly language
:-) and I did it the hard way from example scripts and manpages
(although the perl manpages are pretty good).
> 2) How well does it handle files and strings?
Very well, it's a lot easier than in C, eg to read in a tab delimited
file, sort it based on 2 seperate fields and switch the order of the
fields, leaving the top line alone:
open(FILE, 'filename');
@array_of_lines = <FILE>; #read file into an array
close(FILE);
open (OUT, '>filename');
print OUT shift(@array_of_lines); #print out the first line and remove
it from the array;
foreach $line (@array_of_lines){
#Stick the line split around tabs into a simulated 2d array
push(@fields_2d [split(/\t/, $line)]);
}
# Sort alphabetically by the first field and numerically by the third
sort {$a->[0] cmp $b->[0] or $a->[2] <=> $b->[2] } @fields_2d;
foreach $line (@fields_2d){
#Switch the second and third fields
$temp = ${$line}[1];
${$line}[1] = ${$line}[2];
${$line}[2] = $temp;
#Join back together and print out to the file
print OUT join("\n", @$line);
}
close (OUT);
> 3) What about support and documentation?
There is a very extensive set of manpages (take a look at them in HTML
at http://www.perl.com/perl/nmanual) and FAQs, along with this
newsgroup and the efnet IRC channel #perl to help you if you have
problems.
> 4) What about all this CGI and webserver stuff, etc.
Again for this Perl can be a lot easier than C, especially if your
using addon modules like CGI.pm
(http://www.perl.com/CPAN/modules/by-module/CGI). Perl is basically a
text manigment and manipulation language, a job which it does very
well indeed, and most CGI mainly involves text management and
manipulation. There is also a great deal of help/examples on doing CGI
in Perl since Perl is the main language used for CGI.
Perl does have it's disadvantages, if your looking for a very nippy
program then Perl isn't really where you want to be programming,
although the initial compile can be cut away by using the perl to C
compiler it's still not very fast.
However it is relatively platform independant, complicated programs
can be written relatively quickly in perl and don't run too slowly,
and once you get into it perl doesn't seem a very complicated language
with all the messing around that is required in C for things like
strings.
------------------------------
Date: Thu, 03 Apr 1997 11:51:35 -0600
From: jsykes@tartar.ulib.albany.edu
To: sykesj@nimo.com
Subject: Please - need help with for loop on hostname script
Message-Id: <860088731.29630@dejanews.com>
hello!
this may or may not have been posted by me already - my system went down
during the post confirmation.
anyway, i am a new perl person, currently trying to teach myself perl
using the excellent perl for dummies and teach yourself perl in 21 days.
both books are excellent - well written and clear. anyway, in the 21 day
book, there is a piece of code that i find very useful. in fact i am
using it already, but i would like to change it a little. the code asks
me for an ip address and responds with that machine's hostname. as i
currently have the task of doing a system inventory of 200 machines, this
script helps me a lot. the only trouble is i have to enter each ip
address one at a time, eg: 111.111.111.1, then 111.111.111.2, all the way
up to 111.111.111.999 (not the real ip addresses, but the same order).
i would like to put in a for loop into the code that enables me to do a
one time hostname lookup of all the machines and not be prompted for each
one. i have been experimenting with creating a text file of the addresses
and reading each line in as an array, but there must be a simpler way.
can i not tell perl to create an array beginning at 111.111.111.1 and
ending at 111.111.111.999 and to check every number in between?
here is the code:
# p14_5.pl
print ("Enter an Internet address:\n");
$machine = <STDIN>;
$machine =~ s/^\s+|\s+$//g;
@bytes = split (/\./, $machine);
$packaddr = pack ("C4", @bytes);
if (!(($name, $altnames, $addrtype, $len, @addrlist) =
gethostbyaddr ($packaddr, 2))) {
die ("Address $machine not found.\n");
}
print ("Principal name: $name\n");
if ($altnames ne "") {
print ("Alternative names:\n");
@altlist = split (/\s+/, $altnames);
for ($i = 0; $i < @altlist; $i++) {
print ("\t$altlist[$i]\n");
}
}
i am sure that in a month or so, after reading the books, i will know how
to do this. but in the meantime, if any of you are feeling generous
enough, i would very much appreciate your help. please email me your
responses, to either sykesj@nimo.com or jsykes@tartar.ulib.albany.edu
many thanks in advance
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Thu, 03 Apr 1997 18:44:21 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: Running program on a remote machine
Message-Id: <3345b894.709190@news.uni-stuttgart.de>
On 3 Apr 1997 03:34:10 GMT, "Bob Bell" <bbell@voicenet.com> wrote:
>Newsgroups: comp.lang.perl, comp.lang.perl.misc
^^^^^^^^^^^^^^ this newsgroup does not exist, it is dead,
it is no more.
> I'm a fairly experienced programmer, but I'm new to Perl, so I appreciate
>your patience. I am interested in using a Perl program where part of it
>would require running a program on a remote server. For instance, if you
>were doing it manually, you could telnet to the machine, log in, and run
>the program. Is there a way to do this in Perl code? I haven't really
>messed around with Perl modules yet, so it there some prebuilt code I
>should be looking for? Thanks, it is appreciated. E-mail replies would
>probably be best, and URLs to sites with the info I need would be excellent
>(save you time and let me learn more in the process).
>
You could get the Net::Telnet module from
www.perl.com/CPAN/modules/by-module, however you could just do
something like:
open(COMMAND, 'rsh remote_host command |');
Or if you don't have rsh rights you could try looking into rexec
aswell, if either work that would seem the easiest way.
------------------------------
Date: Thu, 03 Apr 1997 18:44:24 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: server directory protection vs. cgi-bin style password
Message-Id: <3349cb0b.5436278@news.uni-stuttgart.de>
On 2 Apr 1997 20:51:27 GMT, pa19@tiac.net (Paul Antinori) wrote:
>Where can I find more info on server directory protection vs. cgi-bin
>style passwords? Thanks
>
In a CGI newsgroup (comp.infosystems.www.authoring.cgi) not a perl
newsgroup.
------------------------------
Date: Thu, 03 Apr 1997 19:26:15 GMT
From: j.mcgahen@realogic.com
Subject: Re: Simple array question by newbie...
Message-Id: <334403b1.1884441@client.ce.news.psi.net>
On 3 Apr 1997 13:28:10 GMT, alweiner@clark.net (Alan Weiner) wrote:
>I've written a simple subroutine which inputs a month and returns the
>next month. However, it doesn't seem to work :)
>
>1) Is there a better way to do this?
>2) What am I doing wrong?
>
>Here's what I've got:
>
>
>@months=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","No
>v","Dec","Jan");
>
>$nxtMonth=getNxtMonth("Mar");
>print "$nxtMonth";
>
>sub getNxtMonth {
>local($thisMonth)=@_;
>foreach (@months) {
> if($thisMonth == $_) {
> return ($months[$#months+1]);
> }
> }
>}
>
>Thanx for any help you can provide! Pls post the answer here...
>
>
The problem is with your $months($#months+1). the $# will return
the number of elements in the array, in your case 12, then you add one
to it, to make 13. It would be easier to run through your array with
a for statement using $#months as the delimeter. That way adding 1
when the match is made provides the correct element.
Joel
------------------------------
Date: 3 Apr 1997 14:25:00 GMT
From: scott@lighthouse.softbase.com ()
Subject: Re: Visual Perl++?????
Message-Id: <5i0ejs$9dg$2@mainsrv.main.nc.us>
Josef Siu-wai Leung (siuwl@acm.org) wrote:
: I saw a news message in this newsgroup that Microsoft is going to release
: a Perl++ product. BUT I failed to find the relevant news from
: www.microsoft.com. Please post a note if you find any evidence to proof
: or disproof. Thanks.
April Fool's jokes just don't work on Usenet.
Okay, you may *SEND* the message April 1, but people don't necessarily
*GET* the message then. In fact, with my experience, the odds are
against it. Even if the message did get to the reader's news server on
April 1, the reader may not actually read the news on that date.
And many people don't know it's April Fool's day -- it's either not in
their culture or they forget it even exists.
Unfortunately, in this case, the "joke" wasn't even very good! It
advertised a product a lot of people actually *WANT*, and is created a
huge pent-up demand for it. If I were MS, I'd vaporware announce Visual
Perl++ today and assign my best team to getting it ready for 1Q 1998.
I'd hire the best Perl internals hackers on Usenet and lock them
in a room until Visual Perl++ was done, then pay them anything
they wanted.
Scott
------------------------------
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 228
*************************************