[8882] in Perl-Users-Digest
Perl-Users Digest, Issue: 2499 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 5 04:06:50 1998
Date: Tue, 5 May 98 01:00:40 -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 Tue, 5 May 1998 Volume: 8 Number: 2499
Today's topics:
Re: $$#_ ? <dfetter@shell4.ba.best.com>
Re: 'each' and recursion, do they mix? (Chip Salzenberg)
Re: Adding 600 users to a Linux password file <dfetter@shell4.ba.best.com>
Re: basic email parser? (Martien Verbruggen)
Re: cd with a perl-script <qdtcall@esb.ericsson.se>
Communicating from child proc to parent via IPC? (Jordan Gottlieb)
Computing length of hash <ian.maloney@ubs.com>
Re: condition to subroutine <qdtcall@esb.ericsson.se>
Re: CPAN & Module gripes (was Re: Ever Wonder...?) <aas@sn.no>
Re: directorys and Files? (Martien Verbruggen)
Re: Ever Wonder Why Not Everyone Uses Modules? phdss@writeme.comm
Re: Ever Wonder Why Not Everyone Uses Modules? <tchrist@mox.perl.com>
Re: How to clear browser Cache with perl <Tony.Curtis+usenet@vcpc.univie.ac.at>
Re: If Perl had immediate subroutines... <jll@skynet.be>
Installation problems <Srinivas.MV@Analog.Com>
Re: list from regexp <danboo@negia.net>
Re: newbie, how to extract line n from a file (Martien Verbruggen)
perl and Cisco??? <andrew@iaccess.com.au>
Re: Perl script doesn't work (Martien Verbruggen)
Re: Perl Socket and proxy Server (Martien Verbruggen)
Running script as background program. <blan0416@uidaho.edu>
Running script as background program. <blan0416@uidaho.edu>
Running script as background program. <blan0416@uidaho.edu>
Running script as background program. <blan0416@uidaho.edu>
writing to a file <soetensi@se.bel.alcatel.be>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 5 May 1998 06:42:28 GMT
From: David Fetter <dfetter@shell4.ba.best.com>
Subject: Re: $$#_ ?
Message-Id: <6imcck$872$1@nntp1.ba.best.com>
Phil R Lawrence <prl2@lehigh.edu> wrote:
> $_ is a hard reference to an array. How do I determine the subscript of the
> final element of the array?
> $$#_ doesn't seem to work.
scalar($_)-1 does for me :)
--
David Fetter 888 O'Farrell Street Apt E1205
shackle@ren.glaci.com San Francisco, CA 94109-7089 USA
http://www.best.com/~dfetter +1 415 567 2690 (voice)
print unpack ("u*",q+92G5S="!!;F]T:&5R(%!E<FP@2&%C:V5R"@``+)
"The Buddha, the Godhead, resides quite as comfortably in the circuits of
a digital computer or the gears of a cycle transmission as he does at the
top of a mountain or in the petals of a flower."
Robert Pirsig
------------------------------
Date: Tue, 05 May 1998 00:03:44 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: 'each' and recursion, do they mix?
Message-Id: <6ill43$e03$1@cyprus.atlantic.net>
Keywords: fractious Grayson multiplication pug
According to mjd@op.net (Mark-Jason Dominus):
>In article <6iip7i$c8u$1@cyprus.atlantic.net>,
>Chip Salzenberg <chip@mail.atlantic.net> wrote:
>>Yes, scalar '..' does have the same problem as //o.
>
>The p5p discussion from February-March says otherwise.
>I didn't understand the explanation, unfortunately.
Mmm, OK, I think I remember that... If I remember correctly, and if
that's true, it's because the state is kept effectively in the stack
frame, and not in the OP tree. If that's true, then repeated recursive
calls to a sub won't retain the state of .. in the subroutines. That
could be considered a bug or a feature, depending on your moond.
--
Chip Salzenberg - a.k.a. - <chip@pobox.com>
"I brought the atom bomb. I think it's a good time to use it." //MST3K
-> Ask me about Perl training and consulting <-
Like Perl? Want to help out? The Perl Institute: www.perl.org
------------------------------
Date: 5 May 1998 06:47:07 GMT
From: David Fetter <dfetter@shell4.ba.best.com>
Subject: Re: Adding 600 users to a Linux password file
Message-Id: <6imclb$872$2@nntp1.ba.best.com>
Wiebe de Wolf <wiebe@worldcom.nl> wrote:
> Hi to everybody, and thanks... but.......
> Got some answers, which could be quite usefull to a trained Perl
> programmer.
> First of all: I have to use the Perl4 which is provided by my Internet
> provider (we have a virtual server).
Perl4 has CERT warnings and published cracks out for it. Your ISP is
subject to mitnickization and should get rid of it immediately.
> Second: I am not familliar with modules and libraries.
Kein problem :) The docs and FAQ make them familiar.
--
David Fetter 888 O'Farrell Street Apt E1205
shackle@ren.glaci.com San Francisco, CA 94109-7089 USA
http://www.best.com/~dfetter +1 415 567 2690 (voice)
print unpack ("u*",q+92G5S="!!;F]T:&5R(%!E<FP@2&%C:V5R"@``+)
A computer without Microsoft and IBM is like chocolate cake without
ketchup and mustard
------------------------------
Date: 5 May 1998 04:16:01 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: basic email parser?
Message-Id: <6im3q1$2ls$1@comdyn.comdyn.com.au>
[The original article isn't here yet, so I'm replying to this]
In article <ZAv31.1205$mu1.396906@news.randori.com>,
garyg@gator.net (Gary M. Greenberg) writes:
> In article <35468EEB.9ADC08CE@corp.home.net>, James Davis <james.davis@corp.home.net> wrote:
>> Can anyone recommend a PERL module/process for parsing through emails?
>>
Mail::Util
Mail::Header
Basically get the Mailtools distribution from CPAN.
http://www.perl.com/CPAN/authors/Graham_Barr/
> Maybe you can use the code to write a perl version; maybe I'll do
> it.
It's already done :)
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | That's not a lie, it's a terminological
Commercial Dynamics Pty. Ltd. | inexactitude.
NSW, Australia |
------------------------------
Date: 05 May 1998 09:24:05 +0200
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: cd with a perl-script
Message-Id: <islnshgoyy.fsf@godzilla.kiere.ericsson.se>
John Andrea <jandrea@iosat.com> writes:
> > > Can anybody tell me how i can change the directory of the shell from
> > > wich I'm starting the perl script ?
>
> perl has a chdir function
> isn't that what's wanted ?
No. chdir() changes the current working directory for the running
process and any children it spawns, it will not and can not affect the
running process' parent (which is what was asked for). Changing things
in the parent without the parent's active cooperation is nontrivial.
--
Calle Dybedahl, UNIX Sysadmin
qdtcall@esavionics.se http://www.lysator.liu.se/~calle/
------------------------------
Date: 5 May 1998 05:37:58 GMT
From: eygottli@ouray.cudenver.edu (Jordan Gottlieb)
Subject: Communicating from child proc to parent via IPC?
Message-Id: <6im8jm$r8m$1@news.cudenver.edu>
Hello out there,
I am working for a network engineering company which is in the
process of deploying some very "alpha/bleading edge" equipment. This
equipment "falls asleep" at times and needs multiple ping packets to be woken
back up (this great feature should be fixed in a couple of months). I am
attempting to write a perl script that checks to make sure
that the equipment is not asleep (by pinging it up to five times or
$Ping_Count). If the equipment does not respond to my initial pings.
I ping it until it wakes up ( < $Wakeup_Ping_Count currently set at
20 pings).
Because I do not want to wait on the sleeping equipment ( because
$Wakeup_Ping_Count may need to be as high as 200) I fork a process
to handle the wakeup process. After about an hour of playing with fork
I figured it out and padded myself on the back a couple of times. But
then I realized I have no clue how to use IPC to return information
from the child process (and then de-padded myself on the back). I
originally intended to store the string information for both the
equipment that "needed to be waked up by x pings" and the equipment that
"could not be waked up" in a hash for example:
$equip{'10.4.33.9'}="Successful at attempt #$ax on $TStamp";
$equip{'10.4.33.17'}="Failed all attempts";
How would you go about using IPC to communicate back to the parent process
so that the parent process can update the hash?
Sorry for the "long winded" post. I am a network engineer who has just
recently gotten into scripting/development and did not want to leave
anything out. I would appreciate any input.
Due to a confidentiality agreement I can not divulge who I
work for or what equipment is causing us this "heartache" (as my
company could be sued and I would probably lose my job).
Below is what I have come up with so far.
Cheers,
Jordan
#!/usr/local/bin/perl
# Local Declarations
$Ping_Count=5; # number of times to ping initially
$Wakeup_Ping_Count=20; # number of wakeup pings to send
$Fork_Tracker=0; # Keeps track of how many times I have
forked
@Addresses = qw(10.4.33.9 10.4.33.17 10.4.33.25 10.4.33.33 10.4.33.41
10.4.33.49 10.4.33.57 10.4.33.65 10.4.33.73 10.4.33.81
10.4.33.89 10.4.65.9 10.4.65.17 10.4.65.25 10.4.65.33
10.4.33.97); # The addresses to ping (not valid
# internet addresses)
# End Local Declarations
# This subroutine attempts to ping a host $Ping_Count times. If
# successful on
# any of the tries it will return a 1 to the caller. If not successful it
# will return a zero.
sub FIRST_TEST {
# Local Variables
my $SUCCESS=0;
for ($x=0 ; $x < $Ping_Count ; $x++) {
if ((`ping '$_[0]' 1 2>/dev/null`) && ($?==0)) {
$SUCCESS=1;
last;
}
}
return $SUCCESS;
}
# This subroutine attempts to ping a host $Wakeup_Ping_Count times. This
# subroutine is generated by a child process. What I want it to do is
# communicate the "print statement strings" back to the parent process.
# How can I use IPC to do this?
sub EXTENDED_TEST {
# Local Variables
my $IP_Address=$_[0];
for ($x=0, $ax=1 ; $x < $Wakeup_Ping_Count; $x++, $ax++) {
if ((`ping '$IP_Address' 1 2>/dev/null`) && ($?==0)) {
chop($TStamp=`date`);
print "Successful at attempt $ax on $TStamp for
$IP_Address\n";
last;
}
if ( $x == 19) {
print "Failed all attempts for $IP_Address\n";
}
}
}
# Main Block
foreach $test (@Addresses) {
if (&FIRST_TEST($test)) {
}
else {
$Fork_Tracker++;
$return_val=fork;
if ($return_val == 0) {
if (&EXTENDED_TEST($test)) {
print "OK attempt II\n";
}
exit 0;
}
elsif (defined ($return_val)) {
# The parent process
}
else {
die "fork error: $!\n";
}
}
}
# Parent needs to wait for all of the forked child processes
print "There are $Fork_Tracker processes to wait for\n";
for ($x=1; $x <= $Fork_Tracker; $x++) {
print "Waiting for process #$x\n";
$pid=wait;
print "done waiting proccess #$x for $pid\n";
}
------------------------------
Date: Tue, 05 May 1998 08:57:59 +0200
From: Ian Maloney <ian.maloney@ubs.com>
Subject: Computing length of hash
Message-Id: <354EB877.8354265@ubs.com>
In the Camel book (p.183) the recommended way to get the length of a
hash is with:
scalar keys %hash;
My guess is that this is quite 'expensive' as it has to first build the
list of keys, and as I want to do this often (every cycle through the
program) I have been keeping track of the length with a counter to avoid
this operation.
My question is: am I correct in thinking that this is an expensive
operation? and is there an alternative?
Regards
Ian Maloney
------------------------------
Date: 05 May 1998 09:14:14 +0200
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: condition to subroutine
Message-Id: <isogxdgpfd.fsf@godzilla.kiere.ericsson.se>
Graham Wallace <graham@contact.com.au> writes:
> If $variable eq "xyz" { &subroutine }
>
> I keep getting coding errors for this line, I'm sure there is a simple
> way around it, but I can't find it. Please help
The information you need is available in the perlsyn manpage. And if
your Perl book really didn't tell you the syntax for an "if" statement
I'd say it was a *very* shoddy Perl book.
--
Calle Dybedahl, UNIX Sysadmin
qdtcall@esavionics.se http://www.lysator.liu.se/~calle/
------------------------------
Date: 05 May 1998 07:44:55 +0200
From: Gisle Aas <aas@sn.no>
Subject: Re: CPAN & Module gripes (was Re: Ever Wonder...?)
Message-Id: <m3n2cxb7ag.fsf@furu.g.aas.no>
Eryq <eryq@zeegee.com> writes:
> In case you're interested, the confusion is that MIME::Base64 and
> MIME::QuotedPrint (written I think by Gisle) are included in libwww,
> but MIME-tools is not; it's another bundle entirely, written by
> me *on top of* Gisle's stuff.
>
> Perhaps Gisle's stuff should be extracted from libwww, and
> distributed as MIME-core...?
It is already unbundled and have be distributed as MIME-Base64 since
1997-07-10.
If you don't want to use CPAN.pm, then it is handy to have a local
copy of CPAN/modules/02packages.details.txt which is a very grepable
file.
$ grep MIME 02packages.details.txt
MIME::Base64 2.03 GAAS/MIME-Base64-2.03.tar.gz
MIME::Body undef ERYQ/MIME-tools-3.204.tar.gz
MIME::Decoder 3.202 ERYQ/MIME-tools-3.204.tar.gz
MIME::Entity 3.204 ERYQ/MIME-tools-3.204.tar.gz
MIME::Field::ContDisp 3.201 ERYQ/MIME-tools-3.204.tar.gz
MIME::Field::ConTraEnc 3.201 ERYQ/MIME-tools-3.204.tar.gz
MIME::Field::ContType 3.201 ERYQ/MIME-tools-3.204.tar.gz
MIME::Field::ParamVal 3.201 ERYQ/MIME-tools-3.204.tar.gz
MIME::Head 3.202 ERYQ/MIME-tools-3.204.tar.gz
MIME::IO 3.201 ERYQ/MIME-tools-3.204.tar.gz
MIME::Latin1 3.202 ERYQ/MIME-tools-3.204.tar.gz
MIME::Lite 1.121 ERYQ/MIME-Lite-1.121.tar.gz
MIME::Parser 3.203 ERYQ/MIME-tools-3.204.tar.gz
MIME::ParserBase 3.203 ERYQ/MIME-tools-3.204.tar.gz
MIME::QuotedPrint 2.02 GAAS/MIME-Base64-2.03.tar.gz
MIME::ToolUtils 3.204 ERYQ/MIME-tools-3.204.tar.gz
(My copy of the file seem to not be very fresh.)
--
Gisle Aas
------------------------------
Date: 5 May 1998 04:30:55 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: directorys and Files?
Message-Id: <6im4lv$2ls$3@comdyn.comdyn.com.au>
In article <354E8CC7.964@primary.net>,
darkcyde <bazaillion@primary.net> writes:
> Is there any commands in perl for instance if you gave it a directory it
> could traverse it and obtain all the names and files in the directory?
You really should spend some time reading the perl documentation.
# perldoc perl
# perldoc perlsyn
# perldoc perldata
# perldoc perlop
# perldoc perlfunc
You really should buy a good book about perl:
http://language.perl.com/info/documentation.htm
You really should spend some time reading this newsgroup before
posting to it.
You really should use dejanews to find out if someone already has
asked this question.
Specific answer:
# perldoc -f opendir
# perldoc -f readdir
# perldoc -f closedir
If by 'traverse' you mean recurse:
# perldoc File::Find
If you need to store all those names in a list of lists or a hash or
something like that:
# perldoc perldsc
# perldoc perllol
Martien
PS. You see? if you had just taken the time to read some
documentation, you would have known. If you had bought a good book on
perl, you would have known. If you had read a few messages in this
group, you would have known. If you had done some searches on
dejanews, you would have known. I hope you will remember that for the
next time.
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | We are born naked, wet and hungry. Then
Commercial Dynamics Pty. Ltd. | things get worse.
NSW, Australia |
------------------------------
Date: Mon, 04 May 1998 23:26:42 -0500
From: phdss@writeme.comm
Subject: Re: Ever Wonder Why Not Everyone Uses Modules?
Message-Id: <CUpT1IIelwLS092yn@netins.net>
Art Cohen <upsetter@shore.net> wrote:
[a few snips :here-there]
>I delete everything and try to intstall again. I notice an error message
>telling me that I need "Data::Dumper" to be installed. So I ftp back to
>CPAN and download Data::Dumper.
>As I try to install Data::Dumper, I get this message:
>gcc: installation problem, cannot exec `cpp': No such file or directory
>*** Error code 1
>make: Fatal error: Command failed for target `Dumper.o'
Sure you have compiler support? Many of the newer isp's that allow
perl cgi wont allow C compilers to run. Mine is that way - don't
even have shell access (ftp upload, server sets permissions, and we
gets one write directory) - so modules are out of the question. (I
wouldn't use them anyway).
>I've now been working on this for an hour and I still can't run a two-line
>test script. If I were actually working on something that needed to be
>finished any time soon, I would have abandoned this approach about a half
>an hour ago and just written the code to communicate with sendmail.
I know that frustration very well - went through it trying to
install that libwww myself, it was very painful - ultimately deleted.
>Is it any wonder why a lot of perl developers don't use pre-written
>modules?
<rant>
Not a wonder to me at all. Modules:
/A:You can usually write the program faster than you can
dial/dl/hangup/install/read docs/fix it/fix the fix/. And when
you are done, you still only have someone elses (usually lame)
code that will only do 75% of what you really wanted in the first
place.
/b:Are other peoples code. You are either a programer or not.
/c:You learn nothing by using a module. You have little clue what
the module is going to do, and your understanding of perl is not
increased one centilia. (Unless your using the module for the
pure sake of seeing how the prg is written [most cool])
/d:Disk spam. Take libwww for instance: installing it (guessing)
2-4 meg of spam for what? A set of slow running subscripts that
accomplish very little that you couldn't do faster manually.
And I wish you good luck de-installing it (the horror, the horror).
/e:I don't get how it works, but I'm sure modules are just another
MLM scam. ;-) $$ Its FREE!! $$ lol.
On the upside, modules can be quite useful for learning and
ripping apart. The 'ol libwww is a good example of how to do some
things, and also how not to do somethings. Pure scripts are ok for
learning too, but there is so much repetition among scripts (file
handling, other i/o, etc) that modules to offer specific examples of
routines you want to write. In that sense, they are the perfect
teaching tool...but using them in mainline code, never (I don't
think any self-respecting programmer could).
>Modules are *supposed* to make it easier to accomplish certain
>tasks without getting bogged down in the minutiae of your operating system
>but in this case, it's exactly the opposite. Whereas I could have written
>the "raw" perl code to accomplish the task at hand in about five minutes,
deja vu.
>I've now spent an hour fruitlessly trying to install a module that's
>supposed to make my life easier.
Least ya can say that you learned something this week (oh: and
welcome to using modules).
>End of rant.
on the defacto 10 scale: a solid 7.5.
</rant>
4 out of 5 doctors agree, venting is good - and I do feel better.
BT
--
-- Brett Tabke (phdss at writeme.com - fix munged reply-to)
-- stuff http://www.netins.net/showcase/phdss/
...ML: The only language worth learning in my lifetime. (I'm 35)
------------------------------
Date: 5 May 1998 07:01:24 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Ever Wonder Why Not Everyone Uses Modules?
Message-Id: <6imdg4$ba5$1@csnews.cs.colorado.edu>
I can see it's time to argue the other way. I told you
both sides had something to learn.
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, phdss@netins.net writes:
:/A:You can usually write the program faster than you can
Really? Let's see you write Tk. Or libwww. Or even curses for that
matter. How about Storable? DB_File? Go ahead.
:/b:Are other peoples code. You are either a programer or not.
Just because you're capable of doing something doesn't mean
you have to. Just because you're capable of cooking your own
meal thrice a day all your life doesn't mean you want to.
care to.
:/c:You learn nothing by using a module.
Sometimes that is not the goal.
: You have little clue what
: the module is going to do, and your understanding of perl is not
: increased one centilia.
My guess is the world you're after is scintilla. Fortunately, the
Text::Soundex module decided they hashed to the same value, so I could
figure out what you meant. :-)
:/d:Disk spam. Take libwww for instance: installing it (guessing)
: 2-4 meg of spam for what? A set of slow running subscripts that
: accomplish very little that you couldn't do faster manually.
You are insane. Please go fetch a document by URL, including redirect
handling, and then parse the HTML by yourself into a tree structure
that you can traverse for modification. Go ahead. You're a
programmer, after all.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Espousing the eponymous /cgi-bin/perl.exe?FMH.pl execution model is like
reading a suicide note -- three days too late."
--Tom Christiansen <tchrist@mox.perl.com>
------------------------------
Date: 05 May 1998 08:37:59 +0200
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: How to clear browser Cache with perl
Message-Id: <7xra29dxyw.fsf@beavis.vcpc.univie.ac.at>
Re: How to clear browser Cache with perl, Joseph
<sirron@mail.mcoe.k12.ca.us> said:
Joseph> Hello listeros, Can anyone tell me the way to clear
Joseph> browser cache from a cgi script written in perl?
You can't force a browser/user-agent to do anything.
There is no general solution to this problem (and rightly
so, IMHO).
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, AT | http://www.vcpc.univie.ac.at/
"You see? You see? Your stupid minds! Stupid! Stupid!" ~ Eros, Plan9 fOS.
------------------------------
Date: Tue, 05 May 1998 10:04:08 +0200
From: Jean-Louis Leroy <jll@skynet.be>
Subject: Re: If Perl had immediate subroutines...
Message-Id: <VA.000000b4.188b17ba@jll>
> These objects are all implemented by anonymous hashes, and the
> overhead of the getter/setter functions just turned out to be
> tremendous.
> [...]
> Being able to inline some of these functions might help a lot.
It would indeed. I assume that you have something like this in mind:
package Person;
immediate sub get_name
{
my ($expr) = @_;
return "($expr)->{name}";
}
sub print
{
# ...
print $self->get_name;
}
..and the call would be transformed into: print ($self)->{name}
Unfortunately, isubs can't be used to inline accessors, at least not in a
weakly typed language :( The example above would require the parser to
know that '$self' is a Person.
But, who knows, when Perl gets a measure of strong typing (this should
happen in 5.005, shouldn't it?)...
Jean-Louis Leroy
http://ourworld.compuserve.com/homepages/jl_leroy
------------------------------
Date: Tue, 05 May 1998 11:24:57 +0500
From: Srinivas MV <Srinivas.MV@Analog.Com>
Subject: Installation problems
Message-Id: <354EB0B8.23895EDE@Analog.Com>
Hello,
Can someone tell me where I can find info on probalble
workarounds/pointers to problems encountered during perl installation?
I am stuck with one on solaris platform. I have used the default
options for
all the questions. I am able to compile perl 5.004 but during
"make test" it fails at test base/term.t It exists with a
segmentation fault
after the last (7th) test in this. If that test is removed there is no
seg. fault
(but obviously some other test fails).
Any help/pointers on this will be greatly appreciated.
Thanks in advance.
Srinivas.
(srinivas.mv@analog.com)
------------------------------
Date: Tue, 05 May 1998 00:59:49 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: list from regexp
Message-Id: <354E9CC5.39AE689@negia.net>
Bruce Langlois wrote:
>
> If I have a string with an indeterminate number of repeating groups, preceeded
> by some other
> characters, say:
>
> @dbgddbggdbbgddd-b
>
> and I want to insert a seperator between the groups so it looks like this:
>
> @dbg.ddb.ggd.bbg.ddd-b
>
[SNIP]
>
> This is the basic regexp which I use to extract the pre, match, and post
> portions:
>
> m/[^dbg]*([dbg]{3}*)[^dbg]*/
s/([dbg]{3})(?=[dbg])/$1./g;
or in commented form:
s/( # begin capture
[dbg]{3} # three valid chars in a row
) # end capture
(?= # look ahead but don't track
[dbg] # one of the valid chars
) # end look ahead
/$1./gx; # replace with capture and dot
i think this should do the trick. basically it says, replace all
chunks of three comprised of the letters in the class with themselves
followed by a dot, if the following character is also in the class.
the second class may not suit your needs, but i am sure you could modify
it easily. perhaps something like [^-] or \w would be better.
hope this helps,
--
Dan Boorstein home: danboo@negia.net work: danboo@y-dna.com
"THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
- Cosmic AC
------------------------------
Date: 5 May 1998 03:49:41 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: newbie, how to extract line n from a file
Message-Id: <6im28l$2hl$1@comdyn.comdyn.com.au>
In article <6iibkp$dpf$1@artemis.it.luc.edu>,
sandell@sparky.parmly.luc.edu (Gregory J. Sandell) writes:
> I want to be able to say
> $myline=getline(2);
Please, please, please, read some of the documentation that comes with
perl.
# perldoc perl
# perldoc perlsyn
# perldoc perlop
# perldoc perldata
# perldoc perlfunc
# perldoc -f open
# perldoc -f close
sub getline {
my $file = shift;
my $num = shift;
# Need error checking here.
open(ZZZ, $file) || die "Cannot open $file: $!";
my $line = (<ZZZ>)[$num - 1];
close(ZZZ);
return $line;
}
my $myline = getline("some_file.txt", 2);
die "No such line" unless defined $myline;
Some notes:
- There is no error checking on the index.
- If you ask for line 0, you get the last one.
- If you ask for a line number that is too high, the function returns
undef.
- It would be extremely stupid to call this function more than once.
If you need more than one line from this file, you should do it
differently.
> Thanks. Email replies, please!
No problem. Nope.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Make it idiot proof and someone will
Commercial Dynamics Pty. Ltd. | make a better idiot.
NSW, Australia |
------------------------------
Date: Tue, 5 May 1998 17:27:23 +1000
From: "Andrew Specht" <andrew@iaccess.com.au>
Subject: perl and Cisco???
Message-Id: <6imetg$gna@sleipnir.iaccess.com.au>
Hi,
How do i communicate with a cisco router using perl scripts?
I would like to add an entry to the access list using a perl script. Is this
possible?
Thanks in advance
Andrew Specht
System Administrator
Internet Access Australia
andrew@iaccess.com.au
------------------------------
Date: 5 May 1998 04:18:41 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Perl script doesn't work
Message-Id: <6im3v1$2ls$2@comdyn.comdyn.com.au>
In article <354fb704.16419439@news.algonet.se>,
hawk@algonet.se (Hakan Hjelmstrom) writes:
> You're missing a newline in the header.
> Also, I can't seem to spot the closing BODY or HTML tags,
> but these usually are very rare in Perl :-)
Indeed. Because they have nothing to do with Perl. They're HTML. The
fact that people forget about them has nothing to do with Perl. The
same people wouldn't put them in if they were writing in any other
language.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au |
Commercial Dynamics Pty. Ltd. | What's another word for Thesaurus?
NSW, Australia |
------------------------------
Date: 5 May 1998 03:59:45 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Perl Socket and proxy Server
Message-Id: <6im2rh$2ik$1@comdyn.comdyn.com.au>
In article <354E820A.41C67EA6@net.net>,
ayl <test@net.net> writes:
[Reformat]
> I am trying to use port 80 to have a diirect connection for http
> request. The problem is, this is not permitted. I have to have my
Do you mean a server or a client? To start up a server that utilises
port 80 on a unix box, you most likely have to be root.
> perl script talk to a Proxy server first. Does anyone know how to
> talk to a proxy server, sending an URL request to a proxy server?
Hmmm.. This probably means that what you really are asking is
'I have a client, that needs to contact a remote server on port
80. Due to our firewall setup I am not allowed to do this
directly, but I can utilise a proxy service for port 80. How do I
do this, using perl?'
Is that it?
If you're talking about HTTP with a HTTP proxy service, use LWP. You
can get it from CPAN. Should have you up and running in a few minutes.
> BTW I dont want to use any of the CPAN module.
If you don't want to use a module (and I am not even going to ask
why), then I guess this is not really a perl question. You will need
to implement all the protocols involved yourself. Ask on one of the
comp.infosystems.www.* groups what the protocols are, where you can
get the RFCs and how to implement them. Then use the perl builtins to
open a socket connection to the proxy server, and send it the commands
it expects. Do something useful with the response.
Good luck for the coming few weeks :)
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Very funny Scotty, now beam down my
Commercial Dynamics Pty. Ltd. | clothes.
NSW, Australia |
------------------------------
Date: Mon, 04 May 1998 23:51:15 -0700
From: Derek Blandford <blan0416@uidaho.edu>
To: comp.unix.programmer@uidaho.edu, comp.unix.questions@uidaho.edu
Subject: Running script as background program.
Message-Id: <354EB6E2.470FD45A@uidaho.edu>
I've created a chat written in Perl that uses sockets. The main program
needs to run continously, meaning I need to be able to shut down telnet
without it closing the program. I'm not sure if this is a Perl question
or a Unix question, so it's posted in both. Please reply at least via
email....thanks a million.
Jason Hansen
------------------------------
Date: Mon, 04 May 1998 23:51:35 -0700
From: Derek Blandford <blan0416@uidaho.edu>
Subject: Running script as background program.
Message-Id: <354EB6F7.6002BEC6@uidaho.edu>
I've created a chat written in Perl that uses sockets. The main program
needs to run continously, meaning I need to be able to shut down telnet
without it closing the program. I'm not sure if this is a Perl question
or a Unix question, so it's posted in both. Please reply at least via
email....thanks a million.
Jason Hansen
------------------------------
Date: Mon, 04 May 1998 23:49:10 -0700
From: Derek Blandford <blan0416@uidaho.edu>
To: comp.unix.shell@uidaho.edu, comp.unix.programmer@uidaho.edu, comp.unix.questions@uidaho.edu
Subject: Running script as background program.
Message-Id: <354EB665.AAFE49BA@uidaho.edu>
I've created a chat written in Perl that uses sockets. The main program
needs to run continously, meaning I need to be able to shut down telnet
without it closing the program. I'm not sure if this is a Perl question
or a Unix question, so it's posted in both. Please reply at least via
email....thanks a million.
Jason Hansen
------------------------------
Date: Mon, 04 May 1998 23:49:50 -0700
From: Derek Blandford <blan0416@uidaho.edu>
To: comp.unix.programmer@uidaho.edu, comp.unix.questions@uidaho.edu
Subject: Running script as background program.
Message-Id: <354EB68E.53B39C11@uidaho.edu>
I've created a chat written in Perl that uses sockets. The main program
needs to run continously, meaning I need to be able to shut down telnet
without it closing the program. I'm not sure if this is a Perl question
or a Unix question, so it's posted in both. Please reply at least via
email....thanks a million.
Jason Hansen
------------------------------
Date: Tue, 05 May 1998 08:38:06 +0200
From: Inge Soetens <soetensi@se.bel.alcatel.be>
Subject: writing to a file
Message-Id: <354EB3CE.28DA@se.bel.alcatel.be>
Hello,
can anyone help me with this ?
I'm trying to put some data in a new file,
but I have a little problem :
this is the code I use....
#!/usr/local/bin/perl
if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
# Load the FORM variables
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
print "Content-type: text/html\n\n";
print "<HTML><HEAD>\n";
print "<TITLE>Add / Update a Detection Point</TITLE>\n";
print "</HEAD>\n";
print "<BODY >\n";
print "<CENTER><H2> Add / Update DP</H2></CENTER>\n";
print "</BODY></HTML>\n";
...
then some of the FORM-variables are written onto the HTML-site.
and then I would like to save some data in a file
...
$tdp_file = "../tdp_arm.txt";
$test = "Testing ....";
open (TDPARM, ">$tdp_file")|| die "Can't find article $TDPARM: $!\n"; ;
print TDPARM $test ;
close (TDPARM) ;
}
This doesn't work.
Please help ....
Thanks
Inge
------------------------------
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 2499
**************************************