[13044] in Perl-Users-Digest
Perl-Users Digest, Issue: 454 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 10 21:07:21 1999
Date: Tue, 10 Aug 1999 18:05:07 -0700 (PDT)
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, 10 Aug 1999 Volume: 9 Number: 454
Today's topics:
Re: chop? Split? help? <cassell@mail.cor.epa.gov>
Re: chop? Split? help? <revjack@radix.net>
Re: Custer's Last Code (Alan Curry)
Re: Custer's Last Code (Sam Holden)
Re: Custer's Last Code <fkrul@acc.com>
Re: Custer's Last Code <fkrul@acc.com>
Re: Flocking, whassat? (Matthew David Zimmerman)
Re: getting perl onto windows laptop <cassell@mail.cor.epa.gov>
Re: getting perl onto windows laptop (I R A Darth Aggie)
Re: getting perl onto windows laptop <randy@theory.uwinnipeg.ca>
Re: getting perl onto windows laptop <bwalton@rochester.rr.com>
Re: HTTP_REFERER and Frames <cassell@mail.cor.epa.gov>
Re: Loading a web page <kimgraham@hotmail.com>
Re: Perl Question <phony@nospam.com>
Re: pricing a perl job <fkrul@acc.com>
Re: reference to object method <dchristensen@california.com>
Re: reference to object method <dchristensen@california.com>
Re: sed vs. grep for string manipulation? (Donovan Rebbechi)
Re: Simple Perl Parsing? (Larry Rosler)
Re: turn $6 into $6000 (I R A Darth Aggie)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 10 Aug 1999 17:29:24 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: chop? Split? help?
Message-Id: <37B0C3E4.390AC89E@mail.cor.epa.gov>
QuestionExchange wrote:
[snip of badly-munged original post]
> Use an s/// expression like the following to remove the
> extension on a filename: $filename = "blah.txt"; $filename
> =~ s/\..*$//; print "$filename\n"; # will print 'blah' The
And when he runs this on question.exchange.03.txt what will
happen? Will it remove the extension '.txt'? No. What happens
when he runs this on the file .htaccess ?
Larry Rosler already answered this properly (and completely).
> "\." matches the '.' that the extension starts with. The ".*"
Well, actually "\." will match the *first* real period.
Regexen match leftmost first [up to constraints imposed by
the rest of the regex].
> matches anything up to the "$", which marks the end of the
> line. If you want to do this to all of the files in @allfiles
> at once, and you're using Perl 5, you can use the map command
> as follows: map(s/\..*$//, @allfiles);
This won't work as written. Maybe you need to assign this to
an array?
> shifting twice to get
> rid of "." and ".." is probably not the best thing to do,
> because they might not be there or might be in a different
Agreed. But grep() can cope with this easily if the filenames
are all in an array. For potentially large lists of files,
you might want to use readdir() in a while loop and use
'next' to skip over unwanted filenames. But TMTOWTDI.
> place. You could do something like this to solve your overall
> problem: opendir BUSDIR, "$basepath$pagedir" || die "Unable to
> open directory: $!"; @allfiles = readdir BUSDIR; closedir
> BUSDIR; foreach $file (@allfiles) { ($file eq '.' || $file
> eq '..') && next; $file =~ s/\..*$//; $link =
> "http://www.blah.com/cgi-bin/$file"; # now do whatever you
> want # with $link }
I suspect you can't control the line-wrapping, but you'll
probably want to work on that. Otherwise your code is even
more obscure than ordinary Perl. :-)
But you have a serious error in your code. Your opendir()
statement has bad precedence - I like to use 'or' in place of
'||' in such situations. You also have some inefficiencies.
You would probably be better off doing the readdir() inside a
while loop and doing all processing in there, rather than
a separate readdir() slurp followed by a loop.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 11 Aug 1999 00:42:29 GMT
From: revjack <revjack@radix.net>
Subject: Re: chop? Split? help?
Message-Id: <7oqgtl$199$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight
David Cassell explains it all:
:QuestionExchange wrote:
:[snip of badly-munged original post]
[more snippery]
:I suspect you can't control the line-wrapping, but you'll
:probably want to work on that. Otherwise your code is even
:more obscure than ordinary Perl. :-)
Our new friend QuesEx had proven to be very responsive to several
e-mailed constructive criticisms regarding newsgroup article
formatting, and customs such as .sig separators, etc. Just wanted to
mention that. Would that it were so with everyone.
------------------------------
Date: Wed, 11 Aug 1999 00:29:39 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: Custer's Last Code
Message-Id: <Tt3s3.2595$DY2.112046@typ11>
In article <37B0C30B.4037A557@acc.com>, Frank Krul <fkrul@acc.com> wrote:
>So resetting the SUID and adding the following path in the perl script right
>before the system call or exec I get the same error:
>
>$ENV{path}="/www:/www";
^^^^
>
>Insecure $ENV{PATH} while running setuid at /dev/fd/3 line 123.
^^^^
Do you see the difference between "path" and "PATH"? If not, keep looking.
--
Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
--------------+save some time): | \__/ \__/ \___: \___:
Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: 11 Aug 1999 00:41:51 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Custer's Last Code
Message-Id: <slrn7r1hn8.fte.sholden@pgrad.cs.usyd.edu.au>
On Tue, 10 Aug 1999 17:25:47 -0700, Frank Krul <fkrul@acc.com> wrote:
>I R A Darth Aggie wrote:
>
>> On Mon, 09 Aug 1999 17:41:01 -0700, Frank Krul <fkrul@acc.com>, in
>> + Insecure $ENV{PATH} while running setuid at /dev/fd/3 line 120.
>>
>> This is a feature, not a flaw.
>
>Here's the question that I can't get answered:
>
>How can I have a perl program run as user 'web' anytime it is triggered by
>shell scripts and web servers that run as differing users (nobody etc)?
>
>I chmod the file 4755 giving me the rwsr-xr-x with webgeek as owner on the
>perl script. The script always gives me the error:
>
>Insecure $ENV{PATH} while running setuid at /dev/fd/3 line 123.
>
>When trying to access *any* directory, even ones it could without the SUID.
>Chmoding the file to 755 allows it run fine except that it only can read
>directories that the user triggering it (nobody) has access to (of course).
Read up on taint checking in the perl documentation and it all should be
explained. Look in the 'perldoc perlsec'
q{
Perl automatically enables a set of special security checks, called I<taint
mode>, when it detects its program running with differing real and effective
user or group IDs. The setuid bit in Unix permissions is mode 04000, the
setgid bit mode 02000; either or both may be set. You can also enable taint
mode explicitly by using the B<-T> command line flag. This flag is
I<strongly> suggested for server programs and any program run on behalf of
someone else, such as a CGI script. Once taint mode is on, it's on for
the remainder of your script.
While in this mode, Perl takes special precautions called I<taint
checks> to prevent both obvious and subtle traps. Some of these checks
are reasonably simple, such as verifying that path directories aren't
writable by others; careful programmers have always used checks like
these. Other checks, however, are best supported by the language itself,
and it is these checks especially that contribute to making a set-id Perl
program more secure than the corresponding C program.
}
If you are writing code which runs setuid then you should read all 350 or
so lines of the perlsec documentation, twice. Before you create a script
that unleashes demons from hell.
>
>So resetting the SUID and adding the following path in the perl script right
>before the system call or exec I get the same error:
>
>$ENV{path}="/www:/www";
>
>Insecure $ENV{PATH} while running setuid at /dev/fd/3 line 123.
>
>So is there any way I can do this? Or this an inherent limitation caused by
>security concerns in PERL? Some people on this list have insisted that I
>can just add the $env{path} and it will run fine, which is very frustrating
>for me not seeing this work.
I doubt anyone said that, and if they did they were wrong.
There is a world of difference between $ENV{path}, $env{path}, and $ENV{PATH}.
Only one is correct and that would be the pne that the perl error message
mentions.
And do you really have executables in /www. Good values for PATH are
/bin:/usr/bin, even better is nothing at all. If you run external programs
then use the full path names (use some config variables to aid in porting
the script of course).
--
Sam
PC's are backwards ... throw them out! Linux is ok though.
--Rob Pike (on the subject of CR/LF etc)
------------------------------
Date: Tue, 10 Aug 1999 17:44:54 -0700
From: Frank Krul <fkrul@acc.com>
Subject: Re: Custer's Last Code
Message-Id: <37B0C786.157410C0@acc.com>
Here's the question that I can't get answered:
How can I have a perl program run as user 'web' anytime it is triggered by
shell scripts and web servers that run as differing users (nobody etc)?
I chmod the file 4755 giving me the rwsr-xr-x with webgeek as owner on the
perl script. The script always gives me the error:
Insecure $ENV{PATH} while running setuid at /dev/fd/3 line 123.
When trying to access *any* directory, even ones it could without the SUID.
Chmoding the file to 755 allows it run fine except that it only can read
directories that the user triggering it (nobody) has access to (of course).
So resetting the SUID and adding the following path in the perl script right
before the system call or exec I get the same error:
$ENV{PATH}="/www:/www";
Here's the question that I can't get answered:
How can I have a perl program run as user 'web' anytime it is triggered by
shell scripts and web servers that run as differing users (nobody etc)?
I chmod the file 4755 giving me the rwsr-xr-x with webgeek as owner on the
perl script. The script always gives me the error:
Insecure $ENV{PATH} while running setuid at /dev/fd/3 line 123.
When trying to access *any* directory, even ones it could without the SUID.
Chmoding the file to 755 allows it run fine except that it only can read
directories that the user triggering it (nobody) has access to (of course).
So resetting the SUID and adding the following path in the perl script right
before the system call or exec and putting absolute paths in the exec call I
get a differnt error:
$ENV{path}="/www:/www";
"Insecure dependency in exec while running setuid at /dev/fd/3 line 123.
Content-type: text/html "
So is there any way I can do this? Or this an inherent limitation caused by
security concerns in PERL? Some people on this list have insisted that I
can just add the $env{path} and it will run fine, which is very frustrating
for me not seeing this work.
Frank Krul
------------------------------
Date: Tue, 10 Aug 1999 17:41:16 -0700
From: Frank Krul <fkrul@acc.com>
Subject: Re: Custer's Last Code
Message-Id: <37B0C6AB.F0C36246@acc.com>
"Randal L. Schwartz" wrote:
> Uh, why didn't you just fix the error that it says, rather than trying
> to work around it?
>
Because I RTFM or more specifically the "PERL Cookbook" which states:
The backtick operator and OPEN function call the shell to run, this makes them
unsafe when used in a program with special privelages. Use pipe, fork and exec
to create a low-level workaround.
That I did.
>
> Set $ENV{PATH} to a value that didn't come from the outside world.
> This will work:
>
> $ENV{PATH} = "/bin:/usr/bin";
> print "Just another Perl hacker,"
No, if I put the path as anything local and specify an absolute path inside the
exec call I get a different error though:
Insecure dependency in exec while running setuid at /dev/fd/3 line 123.
------------------------------
Date: 11 Aug 1999 00:05:34 GMT
From: mdz4c@node8.unix.Virginia.EDU (Matthew David Zimmerman)
Subject: Re: Flocking, whassat?
Message-Id: <7oqeoe$70l$1@murdoch.acc.Virginia.EDU>
In article <7oqa1k$vg4$1@slrn.eurobell.net>,
Troy Knight <flexit@flexit.eurobell.co.uk> wrote:
>I'm no perl expert as you will tell from this post and I have a question on
>file locking.....What is it? I think it stops things getting mixed up when a
>file is being read and written to, is this correct?
Right. If more than one copy of a program is running at the same time (or
different programs for that matter) try to access or write to the same
data file at the same time, it'll screw up the data file. File locking is
like manners for processes. The first copy of a program (or process) opens
the file and starts to write to it, putting out a signal in the process
saying, "I'm updating this file.". The second process checks for this
signal before it tries to open and write to the file as well, and if it
detects the lock, it says "Oh, I'm sorry. I'll wait until you finish."
> I also think, correct me
>if I'm wrong, that there are four functions you can use, can someone explain
>what these are,
See the FAQ, as suggested by others. Try typing:
perldoc -f flock
as well.
>and can someone also tell me when eactley I need to use file
>locking.....thanks, much appreciated.
If you have a website with CGI scripts, and there's heavy traffic on the
site, chances are 2 or more people may be running copies of the same CGI
script at the same time.
HTH! Matt
--
Matthew Zimmerman ------------ http://www.people.virginia.edu/~mdz4c
Interdisciplinary Biophysics Program --------- University of Virginia
| "You got to be very careful if you don't know where you're going, |
| because you might not get there." -- Yogi Berra |
------------------------------
Date: Tue, 10 Aug 1999 17:35:44 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: getting perl onto windows laptop
Message-Id: <37B0C560.94B8113E@mail.cor.epa.gov>
JAMES GRONQUIST wrote:
>
> I've got an older laptop computer. It is not connected to the net and
> I'm trying to get perls for windows loaded onto it. The zip file is too
> big for 1 disk. I've tried directly connecting the notebook to another
> desktop using a serial cable but it would not work. Any ideas how I can
> get perl onto this system? Is there anyplace that I can get perl on
> floppies?
I don't know of one. But I do have a non-Perl answer for you.
Check out some websites which carry MS-DOS software and look for
slice.com [which will let you hack a big file apart and stick
it onto floppies for transport, then stick the file back together
afterward].
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 11 Aug 1999 00:14:18 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: getting perl onto windows laptop
Message-Id: <slrn7r1g6t.8ad.fl_aggie@thepentagon.com>
On Tue, 10 Aug 1999 16:15:27 -0700, JAMES GRONQUIST
<JAMES.GRONQUIST@Sun.COM>, in <37B0B28F.C4DB382C@Sun.COM> wrote:
+ big for 1 disk. I've tried directly connecting the notebook to another
+ desktop using a serial cable but it would not work. Any ideas how I can
+ get perl onto this system? Is there anyplace that I can get perl on
+ floppies?
Depends...does DOS have a unix cat (1) function? If so, you can use
split (1) to chop up the file into pieces, then 'cat' them back together.
James - presuming you have access to unix in order to download+split the
perl distribution of choice...
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: Tue, 10 Aug 1999 19:37:39 -0500
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: getting perl onto windows laptop
Message-Id: <7oqh27$pb8$1@canopus.cc.umanitoba.ca>
JAMES GRONQUIST <JAMES.GRONQUIST@Sun.COM> wrote in
message news:37B0B28F.C4DB382C@Sun.COM...
> I've got an older laptop computer. It is not connected to the net and
> I'm trying to get perls for windows loaded onto it. The zip file is too
> big for 1 disk. I've tried directly connecting the notebook to another
> desktop using a serial cable but it would not work. Any ideas how I can
> get perl onto this system? Is there anyplace that I can get perl on
> floppies?
Hi,
If you have access to a networked Win32 machine with
WinZip on it, WinZip can create zip archives that span
multiple floppies.
best regards,
Randy Kobes
--
Physics Department Phone: (204) 786-9399
University of Winnipeg Fax: (204) 774-4134
Winnipeg, MB R3B 2E9 http://theory.uwinnipeg.ca/
Canada randy@theory.uwinnipeg.ca
------------------------------
Date: Tue, 10 Aug 1999 20:50:36 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: getting perl onto windows laptop
Message-Id: <37B0C8DC.8E12C874@rochester.rr.com>
>
...
> I've got an older laptop computer. It is not connected to the net and
> I'm trying to get perls for windows loaded onto it. The zip file is too
> big for 1 disk. I've tried directly connecting the notebook to another
> desktop using a serial cable but it would not work. Any ideas how I can
> get perl onto this system? Is there anyplace that I can get perl on
> floppies?
...
James, use a zip program that has disk-spanning capability, like WinZip or
PKZIP. You will probably have to turn the disk-spanning option on. You
can get the Perl distribution file onto a few floppies and unzip them
nicely on the other end. Works fine -- it's what I do. If you are using
ActiveState Perl, you can pick up zip files for packages from
http://www.activestate.com/packages/zips, and, after re-ziping the big ones
to span them across floppies and unziping them on a junk directory on the
target system (like c:\junk -- and be sure to preserve the directory
structure when unzipping), install them with:
ppm "--location=c:\junk"
install packagename
...
quit
------------------------------
Date: Tue, 10 Aug 1999 17:32:54 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: HTTP_REFERER and Frames
Message-Id: <37B0C4B6.70843873@mail.cor.epa.gov>
TVsezSO wrote:
>
> i am haveing a small prob with the environment variable HTTP_REFERER if
> i call the cgi script from a frame page it returns the menu frame url
> instead of the main frame. i am new at perl so forgive me if i say
> something stupid. if someone could point me in the right direction to
> find the information i need i would be most happy. Thanks --Dave
I think that you'll find the best place to ask this is in a
CGI group, since this is really about the details of web authoring,
rather than the Perl code which does the work. So I would
suggest that the `right direction' is toward the newsgroup
comp.infosystems.www.authoring.cgi .
But perhaps some fine individual will answer your question
here also. In the meantime, let me just mention one non-Perl
point: HTTP_REFERER cannot be depended upon. Among other
things, it is too easy to spoof, and you can't depend on
it being in the environment passed to you by the web server.
Good luck,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 10 Aug 1999 17:27:30 -0700
From: Kim <kimgraham@hotmail.com>
Subject: Re: Loading a web page
Message-Id: <37B0C371.2288F363@hotmail.com>
How could you do the same thing using SSI, to open a file with prices in a
flatfile database and display it in one section of the page So you want to
have the price for a mouse and you want the price from the file to display
in the existing web page, to cut down on maintenance of the site. I know
how to display an entire data file, but I can't figure out how to display
one record of the file. I'm not even sure if I'm on the right track.
alexander.zinniker@trivadis.com wrote:
> ...
> > But how do I get a Perl program to load a web page which
> > already exists as an HTML file, without requiring the user
>
> why want you to use a Perl script to display a Page that allready
> exists?
>
> > to click on anything? (So printing out a <FORM action="myurl">
> > and waiting for the user to click on "submit" is not acceptable.)
>
> o.k. you could place this tag in your html code:
>
> <a href=/cgi-bin/myscript.cgi?bla>Bla</a>
>
> then you could use the follwing script to print your page:
>
> Note: THIS IS DANGEROUS!!! with such a script everybody can display
> every file on your machine the user with which the webserver is running
> has access to (including /etc/passwd). So instead of passing the
> filename you should pass a number or something else and then check in
> your script which file should be displayed.
>
> #!/usr/bin/perl
>
> my $file = $ARGV[0];
> open (IN, $file) || die 'couldnot open $file';
> print "content-type: text/html\n\n";
> while ($line=<IN>) {
> print $line;
> }
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
------------------------------
Date: 11 Aug 1999 00:10:35 GMT
From: "Bart Simpson" <phony@nospam.com>
Subject: Re: Perl Question
Message-Id: <7oqf1r$gri$0@216.39.133.54>
You posted this same question yesterday, and it was answered then, dont know
why you are posting it again. But, I believe the answer given was that you
have to have an email address in the from field, or it inserts a default.
You should do something like this instead:
print MAIL "From: John <your.email.address>\n\n");
Most window's email programs will display the nickname, John, when the email
is received.
<jsmith19991@my-deja.com> wrote in message
news:7oqcg1$572$1@nnrp1.deja.com...
> I'm having a problem with a perl script. The problem
> we are having is with the E-mailing of information to a
> client. To make it simple, the scriptsends an Email to
> someone after they enter their address (Mary Smith in
> the following example). The script includes the following
> lines for sending the mail:
>
> ...
>
> open(MAIL,"|$mailprog -t");
>
> print MAIL "To: Mary Smith\n";
> print MAIL "From: John\n\n");
> print MAIL "Subject: Information\n\n";
>
> ...
>
> When the Email is received by the person however, the "From"
> field reads not "John", but "John@whsun626.webhosting.com"
>
> How do we get rid of the extra server info following the name?
> We've tried a few things but it always reads the same.
>
> Thank you for your time...
>
>
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
------------------------------
Date: Tue, 10 Aug 1999 17:58:31 -0700
From: Frank Krul <fkrul@acc.com>
To: Max Pinton <max@maxgraphic.com>
Subject: Re: pricing a perl job
Message-Id: <37B0CAB7.FD6525F5@acc.com>
I get $250 an hour for on site web programming. Most of that is NSAPI C
stuff, but I charge the same for perl, and my perl is pretty lame.
Demand is the issue. Time is useless unless you charge by hour and not by
project. Time studying in a book to find answers should not be billed, as
you probably misrepresented yourself in that case. Perl is commonplace and
on average I don't think people charge much, it's like javascript, you can
pump out something nice in a week (a testiment to the beauty of the
language) where as with C or Java you need to study much longer.
Frank
Max Pinton wrote:
> Hi,
>
> I just finished my largest perl project to date, and I'm wondering what
> to bill. It took me about 16 hours, but I'm a newbie and much of that
> time was debugging and head-scratching. It's a job-tracking site, and
> can:
>
> * accept a job order from a form
> * save the entire order and a brief status line
> * show all status lines in a table, with links to the complete job order
> * color the status lines according to data in the order (rush = yellow)
> * let the user change data in the status lines as the job progresses
> * let the user's client view (but not edit) the status lines
> * let the user's client enter a change order
> * most activities are also e-mailed to the user
> * let the user hide, delete & archive status lines
>
> So, none of this stuff is rocket science, but it all works well and the
> client & client's clients are pleased.
>
> How much would you charge for such a script?
>
> Thanks (& please e-mail too),
>
> Max
> max@maxgraphic.com
------------------------------
Date: Tue, 10 Aug 1999 17:56:09 -0700
From: "David Christensen" <dchristensen@california.com>
Subject: Re: reference to object method
Message-Id: <37b0c7ee@news5.newsfeeds.com>
Martin:
I am working on a console menu-driven program to allow interactive
access to the data and methods of objects. I want to put the
names, references to, and other information about the methods into
a table so I can do things with it at run time -- generate menus,
invoke the methods, etc..
>First, you'll need to decide what sort of sub you need. You get a
>reference to the sub by doing something like:
>
>my $ref = \&Bar::FooOnYou;
>
>When you call this again, you'll be responsible for supplying the
>correct arguments, because from here on, you've lost the blessed
>object. What you get is a reference to the sub, not a reference to
an
>object specific version of that sub. There is no such thing. This
>means that if you get a reference to an object method, you will
have
>to call it like this:
>
>&$ref($bar, "Howdy\n");
>...
>&$ref($bar, @arguments);
>...
OK that's the answer I was looking for. I will be sure to keep a
copy of the blessed object around for use with the method table.
Here's the working demo code:
foo.pl:
1 #!/fsf/bin/perl -w
2 use Bar;
3
4 my $bar = new Bar();
5
6
7 $bar->FooOnYou("Howdy ");
8
9
10 my $ref = \&Bar::FooOnYou;
11 my @args = ("Doody!\n");
12
13 &$ref($bar, @args);
bar.pm:
1 package Bar;
2
3 # constructor
4 sub new {
5 my $proto = shift;
6 my $class = ref($proto) || $proto;
7 my $self = {};
8 bless ($self, $class);
9 return $self;
10 }
11
12 # function
13 sub FooOnYou {
14 $self = shift;
15 print @_;
16 }
17
18 1; # use
run:
~/code/perl/foo$ ./foo
Howdy Doody!
Thanks! :-)
--
David Christensen
dchristensen@california.com
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 10 Aug 1999 18:11:57 -0700
From: "David Christensen" <dchristensen@california.com>
Subject: Re: reference to object method
Message-Id: <37b0cb64@news5.newsfeeds.com>
Damian:
> my $ref = \&Bar::FooOnYou; # methods, even object methods,
> # belong to classes not
> # individual objects
>
> $var->$ref("Howdy\n"); # object methods must be called on
> # objects even when called via a
> # reference.
OK interesting symetry with Martien's approach:
&$ref($bar, "Howdy\n");
I'm wondering if this is TIMTOWDI, or if there's a gotcha in
there...
>If you *really* want to be able to call the method as:
>
> &$ref("Howdy\n");
>
>(and you might, if you were using it as a callback or something
>similar), then you'll need to use a closure:
>
> my $bar = Bar->new(); # as before
>
> $ref = sub { $bar->FooOnYou(@_) }; # wrap up object and
> # method call in an
> # anonymous subroutine
>
> &$ref("Howdy\n"); # call it
Yowza! I like it!
Thanks :-)
--
David Christensen
dchristensen@california.com
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 10 Aug 1999 20:13:43 -0400
From: elflord@news.newsguy.com (Donovan Rebbechi)
Subject: Re: sed vs. grep for string manipulation?
Message-Id: <slrn7r1g1l.dpe.elflord@panix3.panix.com>
On 10 Aug 1999 10:55:36 -0000, Anno Siegel wrote:
>Donovan Rebbechi <elflord@news.newsguy.com> wrote in comp.lang.perl.misc:
>
>>Because a lot of sed and grep wizards hang out their.
>
>What do they hang out,
they hang out their clothes to dry
> and why is that a recommendation?
Because they'd look pretty silly wearing wet clothes (-;
--
Donovan
------------------------------
Date: Tue, 10 Aug 1999 17:44:14 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Simple Perl Parsing?
Message-Id: <MPG.121a67397f9f405b989e28@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7oqdgr$6h7$1@murdoch.acc.Virginia.EDU> on 10 Aug 1999
23:44:27 GMT, Matthew David Zimmerman <mdz4c@node8.unix.Virginia.EDU>
says...
+ In article <MPG.121a4651244fc684989e23@nntp.hpl.hp.com>,
+ Larry Rosler <lr@hpl.hp.com> wrote:
+ >In article <7oq30g$1mt$1@murdoch.acc.Virginia.EDU> on 10 Aug 1999
+ >20:45:04 GMT, Matthew David Zimmerman <mdz4c@node2.unix.Virginia.EDU>
+ >says...
+ >> In article <7optnf$2ov$1@macaw.cyberport.com>,
+ >> Linux GNUBEE <dchurch@kabana.net> wrote:
+ >> >my $line = "fasdjfhkdfhaksdfhSTARThello worldENDaskjkdfljkdfjls";
+ >> >
+ >> >How can I parse out only the text between the two tags, including
+ >> >the tags in their respective positions within the string.
+ >>
+ >> $line =~ /(START.*?END)/;
+ >> print $1;
+ >
+ >Do you know what happens if:
+ >a. the pattern match fails?
+ >b. the START and END tags are on different lines within the string?
+
+ ###
+ #!/uva/bin/perl5 -w
+
+ use strict;
+
+ my $line =
+ "whateverBEGINyadayad
+ ayadaENDanything";
+
+ print $line, "\n";
+
+ print $1 . "\n" if $line =~ /(BEGIN.*?END)/s;
+ ###
+
+ So did I pass? What's my grade, Mr. Rosler? :)
A- ? Entirely on arguable style points.
You didn't use perl from an ordinary place: /usr/bin/perl or
/usr/local/bin/perl (which may be your system administrators' fault,
unless they made the proper links and you didn't use them).
You used double-quotes on a string with no interpolation or escapes.
You used two different ways of adding newlines, neither of which would
have been my choice ("$line\n", "$1\n"), especially in Perl Golf.
'BEGIN' ne 'START'. :-)
+ Matt
+
+ print "Just Another Perl Beginner";
You are hereby dubbed 'Novice'.
Larry
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 11 Aug 1999 00:18:27 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: turn $6 into $6000
Message-Id: <slrn7r1gel.8ad.fl_aggie@thepentagon.com>
On 10 Aug 1999 19:33:12 -0400, Uri Guttman <uri@sysarch.com>, in
<x73dxrb493.fsf@home.sysarch.com> wrote:
+ >>>>> "MM" == Mark Mielke <markm@nortelnetworks.com> writes:
+ MM> And we don't have transparent necks or polygonic faces as South Park
+ MM> would have you believe... :-)
+
+ yeah, prove it, you canadian MF!!
You mis-spelt UF, you PF.
+ :-)
+ that movie turned me into a potty mouth. yeah!!
Watch it, Uri, or we'll install a V-chip in you. It'll work on various
words like 'Microsoft', 'Bill Gates', 'Windows', 'NT', and 'python'.
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu.
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 454
*************************************