[13721] in Perl-Users-Digest
Perl-Users Digest, Issue: 1131 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 20 13:11:01 1999
Date: Wed, 20 Oct 1999 10:10:26 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <940439424-v9-i1131@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 20 Oct 1999 Volume: 9 Number: 1131
Today's topics:
Re: Ignore the idiots (Tad McClellan)
IP address hakanogren@my-deja.com
Re: linux perl editor? <elaine@chaos.wustl.edu>
Re: linux perl editor? <rhomberg@ife.ee.ethz.ch>
Re: linux perl editor? <gellyfish@gellyfish.com>
Re: Making a hash of subroutines schablone@my-deja.com
Re: Matching an asterisk <kbandes@home.com>
mod_prl binaries <anant_sd@trigent.com>
Re: Newbie - Help on installing perl <elaine@chaos.wustl.edu>
Re: Newbie regex question on quoting <aqumsieh@matrox.com>
Re: Passing function as parameter. (Tad McClellan)
Re: Passing function as parameter. (Bart Lateur)
Re: Passing function as parameter. <lr@hpl.hp.com>
Perl command line? <rmnesu@ptd.net>
Re: Perl command line? (Brett W. McCoy)
Re: Please help with format <elaine@chaos.wustl.edu>
Re: Question on comments in Perl? (Tad McClellan)
Re: reading binary data files <simon@profero.com>
Re: Substitution (Tad McClellan)
Re: Substitution <lr@hpl.hp.com>
Working on an Array of Hashes: "using $_->{ }" (Pfash1)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 20 Oct 1999 06:27:33 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Ignore the idiots
Message-Id: <le5ku7.h2e.ln@magna.metronet.com>
emlyn_a@my-deja.com wrote:
: Just because Abigail is posting questions that engage YOU, it does not
: exclude anyone else from posting for legitimate questions they have.
^^^^^^^^^^
FAQs are not legitimate questions in *any* Usenet newsgroup.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 20 Oct 1999 15:53:55 GMT
From: hakanogren@my-deja.com
Subject: IP address
Message-Id: <7ukoid$bgs$1@nnrp1.deja.com>
Hello.
I would like to know how I can get the IP number from the machine where
the script is running.
\\ Hakan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Oct 1999 11:20:48 -0400
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: linux perl editor?
Message-Id: <380DDDB5.647B3D86@chaos.wustl.edu>
Kent Perrier wrote:
> I like echo.
Real men use ed :)
> Groovy! Smashing! Yay capitalism!
Unix baby, It makes me horny, yeah! ;)
- Austin Powers, Man of Mystery
Where is the International?
e.
------------------------------
Date: Wed, 20 Oct 1999 17:33:06 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: linux perl editor?
Message-Id: <380DE0B2.891A4D00@ife.ee.ethz.ch>
Craig Berry wrote:
>
> Jonathan Stowe (gellyfish@gellyfish.com) wrote:
> : On Tue, 19 Oct 1999 12:39:39 -0500 Marc H. Robards wrote:
> : > Anyone have any recommendations for a perl editor under Linux? Or is emacs
> : > or vim the way to go? I've just started using Linux, so any suggesstions
> : > would be appreciated.
> :
> : Yes vi,vim,nvi,elvis,emacs,joe,ev,pico,textedit,xedit,ptked will do fine.
> :
> : Of course real programmers use 'dd'
>
> Some of us traditionalists use 'cat >prog'.
perl is definitely the best tool for that job
perl -leprint\ \"#\!/usr/bin/perl\ -wl\\nuse\ strict\;print\
\\\"hi\\\"\;\\n\" > pl
perl -echmod -e0755, -epl
because you can also change your scripts
perl -i -pes/hi/hello\ world/ pl
(for added functionality, of course there are no bugs)
- Alex
------------------------------
Date: 20 Oct 1999 16:50:42 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: linux perl editor?
Message-Id: <380de4d2_2@newsread3.dircon.co.uk>
Art <ahenry@awak.c0m> wrote:
> I attached a really nice .vimrc that I use. It makes everything pretty and
> helps catch silly mistakes.
> Also works with other languages even HTML. Just put it in your home dir.
> M(BTM+2TM('!R:61K971T)W,@+G9I;7)C(&9I;&4*(BTM+2TM(&1E<VEG;F5D
>
That doesnt look like no .vimrc I ever saw ....
/J\
--
"I suggest you apply some lubrication before any bending begins" -
Antoine de Caunes, Eurotrash
------------------------------
Date: Wed, 20 Oct 1999 15:42:36 GMT
From: schablone@my-deja.com
Subject: Re: Making a hash of subroutines
Message-Id: <7uknt9$ar9$1@nnrp1.deja.com>
In article <s0790h64bhk81@corp.supernews.com>,
cberry@cinenet.net (Craig Berry) wrote:
> schablone@my-deja.com wrote:
> : I know hashes are flattened in subroutine calls, so I want to pass a
> : reference to the hash. Only it doesn't seem to work. Am I barking up
the
> : wrong tree?
>
> Right idea, wrong execution. See below.
Execution, execution. Should I shoot someone?
> : If anyone can help me on this one, the post of Lord High Keeper of
Tall
> : Lattes and Pineapple Cubes is theirs for the asking (once I've
actually
> : got the Umbrella of World Power in my hands, that is).
>
> What's the bennie package look like?
Hmm. What's a bennie package and how would I recognise one? Does
it bite?
> : #!/usr/bin/perl -w
> : #use strict;
>
> That doesn't do you any good if you comment it out.
Ah, yes. That was obviously a Freudian slip brought on by too much
worrying about hashes.
> : my %test;
> : my @data;
> :
> : @data = ('244', 'Slightly Evil Bob', 'Chicken & Cucumber');
> :
> : %test = (
> : id => $data[0],
> : name => $data[1],
> : sandwich => $data[2]
> : );
>
> You could express this as
>
> @test{'id', 'name', 'sandwich'} = @data;
>
> or even
>
> @test{'id', 'name', 'sandwich'} = ( '244',
> 'Slightly Evil Bob',
> 'Chicken & Cucumber' );
>
> were you in the mood to ditch the @data variable. Hash slices are
your
> slightly scary and often puzzling friends. :)
There was a reason, don't ask me what. Now, scary hash slices? Remind me
to write a memo to my secret police.
Now, am I getting this right? If I declare an array which is
structured like a hash, I can refer to it as a hash?
> : DoSomething (\%test, "Favourite Sandwich Data for: ");
> :
> : exit(0);
> :
> :
> : sub DoSomething {
> : my %Newhash = shift;
> : my $message = shift;
>
> The first arg is a hash *reference*, but you're shifting it out into a
> *hash*. Bad, bad, bad. A reference is a scalar. Recoding:
Smack, smack. I was hoping the magic pixies would pick up the hint and
put the data where I wanted it. Silly me.
> my ($nhref, $message) = @_;
>
> : print $message;
> : print $Newhash{'name'}."\n";
> : print $Newhash{'sandwich'};
>
> print $message,
> $nhref->{name}, "\n",
> $nhref->{sandwich};
>
Aha, enlightenment :-). Many thanks for your help, the post of Lord High
Bennie Package is yours for the taking (once I've shaken this damn
penguin off my foot that is).
Schablonski
"Dictatorships for hire by the hour or by the day"
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Oct 1999 11:27:04 -0400
From: Kenneth Bandes <kbandes@home.com>
Subject: Re: Matching an asterisk
Message-Id: <380DDF48.8FDAC52C@home.com>
"Brett W. McCoy" wrote:
>
> Also Sprach Abigail <abigail@delanet.com>:
>
> >-- text =~ /.*\*$/;
> >
> >That's going to fail on "foo\nbar*" (false negative).
> >
> >It's also going to fail on "foo*\n" (false positive).
>
> *smack* Forgot about newlines. Dang.
Try \z (end of string):
$text =~ /.*\*\z/s;
Don't forget the s or . won't match the embedded newline.
Ken Bandes
------------------------------
Date: Wed, 20 Oct 1999 15:45:11 GMT
From: anant <anant_sd@trigent.com>
Subject: mod_prl binaries
Message-Id: <s0ros7g1r0193@corp.supernews.com>
hi
Do you know where i will find mod_perl binaries?
thanks,
anant
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: Wed, 20 Oct 1999 11:29:50 -0400
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: Newbie - Help on installing perl
Message-Id: <380DDFD3.C10CB4FE@chaos.wustl.edu>
Noira Hadi wrote:
>
> I am installing perl on a Sun machine running Solaris 2.6. I encountered
> error message below. Need to know where I can get the C compiler? And do
> I have to re-install the perl again?
*sigh* Ask your system admin to install gcc if they haven't already. If
you are root, well, may some deity help you. I would recommend reading
the docs included with the source that might tell you how to install
Perl.
e.
------------------------------
Date: Wed, 20 Oct 1999 10:28:30 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Newbie regex question on quoting
Message-Id: <x3yogdu6r8y.fsf@tigre.matrox.com>
jhagerty@my-deja.com writes:
> Some brainiac is the text that I am parsing decided to leave astersiks
> as a marker. I don't want the marker so i need to strip out the
> asterisks.
Ok.
> Reading the Perl doc's it appears that I should be able to substitute
> the asterisks out by quoting the metacharacter out. This is what I am
> trying to do with:
>
> $string =~ s/\*//gs;
This is fine. You don't need the /s modifier though. It only affects
the behaviour of the dot.
You can also use the faster tr///:
$string =~ tr/*//d;
> However, this is matching the entire string and leaving me nothing.
No. It can't be doing that:
% perl -wl
$string = 'a string * with * everywhere *';
$string =~ s/\*//g;
print $string;
__END__
a string with everywhere
It seems to be it's doing what it's supposed to do. Show us your real
code, the problem has to be somewhere else. To check, print $string
just before the substitution and just after it.
HTH,
--Ala
------------------------------
Date: Wed, 20 Oct 1999 06:24:51 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Passing function as parameter.
Message-Id: <j95ku7.h2e.ln@magna.metronet.com>
xxaxx@my-deja.com wrote:
: The recursive directory scan works fine. And I can do stuff to each of
: the files found. But at the moment I have to write a different set of
: subroutines for each type of job I want to accomplish.
: In c I would just pass in the point to the function, then after a few
: minutes (or hours) of syntax chasing the routine would use the parameter
: passed function on each occurance of the found files.
: How would this be done in perl?
With a CODE reference.
perldoc perlref
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 20 Oct 1999 15:46:39 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Passing function as parameter.
Message-Id: <380fe242.548920@news.skynet.be>
xxaxx@my-deja.com wrote:
>In c I would just pass in the point to the function, then after a few
>minutes (or hours) of syntax chasing the routine would use the parameter
>passed function on each occurance of the found files.
>
>How would this be done in perl?
pass either
sub { something }
which is an expression of ref type 'CODE', or
\&callback
which is the same, and where you define the sub separately:
sub callback {
blah
}
You can call it as
$coderef->(@param);
or as
&$coderef(@param);
which is pretty much the same. You choose. I like the arrow.
An example:
# cheerleader.pl
$coderef = sub { my $i = shift; print "It's a $i!\n"; };
# don't forget the ";", since it's an ordinary statement!
foreach $letter (split //, 'PERL') {
$coderef->($letter);
}
--
Bart.
------------------------------
Date: Wed, 20 Oct 1999 09:51:31 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Passing function as parameter.
Message-Id: <MPG.127792ec4f0e53ec98a0d0@nntp.hpl.hp.com>
In article <slrn80rj5e.gep.bmccoy@moebius.foiservices.com> on Wed, 20
Oct 1999 14:03:09 GMT, Brett W. McCoy <bmccoy@foiservices.com> says...
...
> Your function reference could then be called as &$funcref or even
> &{$funcref}.
Or even (for completeness) as:
$funcref->()
(though that is a Golf triple-bogey).
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 20 Oct 1999 16:13:51 GMT
From: Richard Neidermyer <rmnesu@ptd.net>
Subject: Perl command line?
Message-Id: <380DEAFF.BC7388BE@ptd.net>
I have downloading the latest version of active state perl. When the dos
prompt pops up after I click on perl.exe none of my command lines will
work. For example, to run a hello world program I type:
C:\>perl c:\temp\hello.pl
assuming hello.pl is in the temp directory. W
What is going on with this. I get errors like wrong syntax near C:\ or
invalid operand near \hello.pl. I have no idea as to what to do. If
anyone can help, I would greatly appreciate it!
Richard
------------------------------
Date: Wed, 20 Oct 1999 16:21:37 GMT
From: bmccoy@foiservices.com (Brett W. McCoy)
Subject: Re: Perl command line?
Message-Id: <slrn80rr92.gep.bmccoy@moebius.foiservices.com>
Also Sprach Richard Neidermyer <rmnesu@ptd.net>:
>I have downloading the latest version of active state perl. When the dos
>prompt pops up after I click on perl.exe none of my command lines will
>work. For example, to run a hello world program I type:
>
>C:\>perl c:\temp\hello.pl
>
>assuming hello.pl is in the temp directory. W
>
>What is going on with this. I get errors like wrong syntax near C:\ or
>invalid operand near \hello.pl. I have no idea as to what to do. If
>anyone can help, I would greatly appreciate it!
Don't click on perl.exe. Just open a DOS box manually and start your
program that way. Even better, use the perl2bat utility that turns your
perl scripts into a batch file that you can run without explicitly
starting the perl interpreter.
Oh, yeah, read the documentation that came with ActiveState Perl. They've
done a good job of it and it's well worth the read.
--
Brett W. McCoy bmccoy@foiservices.com
Computer Operations Manager (Alpha Geek) http://www.foiservices.com
FOI Services, Inc./DIOGENES 301-975-0110
---------------------------------------------------------------------------
------------------------------
Date: Wed, 20 Oct 1999 11:18:18 -0400
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: Please help with format
Message-Id: <380DDD1F.37073608@chaos.wustl.edu>
allnightprod@my-deja.com wrote:
> #!c:/perl/bin/perl
Where is '-w'? This might give you some big clues
>
> $fname = "john";
> $lnight = "smith";
>
> format TEST2 =
> Name: @<<<<<<<<<< Last: @<<<<<<<<<<
> $fname, $lname
Having $lnight and $lname might be a problem.
> write(TEST2);
This is not the way you set $~, please read the format documentation.
> Why does it not display my data???
Because you didn't read the documentation and are posting to usenet when
you should be looking at your code?
e.
------------------------------
Date: Wed, 20 Oct 1999 05:48:44 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Question on comments in Perl?
Message-Id: <s53ku7.o0e.ln@magna.metronet.com>
Mandeep Singh (singh_mandeep@jpmorgan.com) wrote:
: Is there a way to put C/C++/Java like comment to a block of code.?
^^^^^
^^^^^
perldoc -q block
You are expected to check the Perl FAQ *before* posting to
the Perl newsgroup you know.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 20 Oct 1999 16:19:35 +0100
From: Simon Wistow <simon@profero.com>
Subject: Re: reading binary data files
Message-Id: <380DDD87.C93E0C22@profero.com>
> I'm trying to read a binary file using Perl.
> I've check through a lot of the online docs
> and a few books and I can't seem to get it to
> work. Here is an example:
I've been periodically hacking away at a binary file module for an SWF module
I'm working on. Currently it lets you read an arbitary number of bits from a
file by loading a byte into a buffer and then shifting stuff off that then
refilling the buffer as necessary.
I posted a couple of weeks agao asking for help on writing to binary files using
roughly the same technique but got only one reply.
it's on Deja at
http://x34.deja.com/getdoc.xp?AN=533917866&CONTEXT=940432620.155189285&hitnum=1
Hopefully I should have a bit more time to work on it soon mainly cos I need it
for a project I'm working on at college.
Simon
------------------------------
Date: Wed, 20 Oct 1999 06:22:02 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Substitution
Message-Id: <a45ku7.h2e.ln@magna.metronet.com>
oliver.cookYTTFIT@ukonline.co.uk wrote:
: I wrote this script, but it bombs with the error "Can't modify array
: deref in substitution at /usr/local/apache/cgi-bin/plan.pl line 6,
: near "s/\n/\<p\>/;""
: The script is:
: #!/usr/bin/perl
You are missing a "-w" there.
You are missing a "use strict;" too.
: print "content-type:text/html\n\n";
You are missing a space there, I think.
: open (PLAN, "/home/ollie/.plan") || die "could not open plan file";
:
: @plan = <PLAN>;
: close(PLAN)||die "could not close plan file";
: @plan =~ s/\n/\<p\>/;
^ ^
^ ^ unnecessary and misleading
The binding operator (=~) binds the pattern match to a string
(a scalar).
It doesn't work on an array.
: Any help on this one would be very gratefully received.
foreach my $plan (@plan) {
$plan =~ s/\n/<p>/;
}
: Please remove the YTTFIT before replying by email.
Please remove the YTTFIT if you desire replies by email.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 20 Oct 1999 09:47:40 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Substitution
Message-Id: <MPG.12779208d3346d2d98a0cf@nntp.hpl.hp.com>
In article <a45ku7.h2e.ln@magna.metronet.com> on Wed, 20 Oct 1999
06:22:02 -0400, Tad McClellan <tadmc@metronet.com> says...
> oliver.cookYTTFIT@ukonline.co.uk wrote:
...
> : print "content-type:text/html\n\n";
>
> You are missing a space there, I think.
The space is required by the HTTP RFC, but most browsers tolerate no
space. Write conservatively, read liberally.
> foreach my $plan (@plan) {
> $plan =~ s/\n/<p>/;
> }
Par, at best.
s/\n/<p>/ for @plan;
Eagle.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 20 Oct 1999 16:23:30 GMT
From: pfash1@aol.com (Pfash1)
Subject: Working on an Array of Hashes: "using $_->{ }"
Message-Id: <19991020122330.03737.00000161@ng-fi1.aol.com>
I will bestow great appreciation on the helper of:
Trying to compare two arrays of hashes. There is confirmation of a match but
when I try to use the $_->{ } to get string I end up with nothing. See my
comments in the code below:
#!perl #-w
open (FH, 'file.db') || die &error_file;
my @replies;
{
local $/ = "---------------------------------\n";
while (<FH>)
{
chomp;
if ( s/^>\n> To: (.*)\n+>\n> Sender's Name: (.*)\n//)
{
push @replies, {mentor => $1, student => $2, replies => $_};
foreach (@sent_emails) #here is the comparison to the other array.
{
if( $_->{from} eq $2) #"$_->{from}" is from the other array.
{
print "there is a reply to a student's email\n"; #this tells me that the
arrays are being compared and there are matches but....
push (@certain_replies, $_->{replies}); #... why can't I push the
corresponding strings into this array?
}
}
}
}
close <FH>;
}
print "REPLIES THAT MATCH SENDERS:@certain_replies"; #this shows nothing
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 1131
**************************************