[8664] in Perl-Users-Digest
Perl-Users Digest, Issue: 2281 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 9 12:07:18 1998
Date: Thu, 9 Apr 98 09:00:30 -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 Thu, 9 Apr 1998 Volume: 8 Number: 2281
Today's topics:
Re: "Continuations" in Perl <jdporter@min.net>
Re: @INC and avoiding -I (Andrew M. Langmead)
Re: [Q] How to extract a line at a time from a $string <qdtcall@esb.ericsson.se>
Re: [Q] How to extract a line at a time from a $string <rootbeer@teleport.com>
arrays in Format (Kevin B Cohen)
Re: BIG RENAME QUESTION??? <rootbeer@teleport.com>
Re: Can somebody help me understand the internals of "C (Andy Wardley)
crontab command <snx@snx.com>
display location in browser for bookmarking bob_barthelow@hp.com
embed Perl in Java <jkarney@netgenics.com>
Explicit Variable Declarations <fkarmali@uwaterloo.ca>
Re: Explicit Variable Declarations (Kevin Reid)
Re: Explicit Variable Declarations <rootbeer@teleport.com>
Re: Generating Password from Username in Perl ? (Greg Bacon)
getgrent and reading /etc/group (Andy Squires)
Re: getgrent and reading /etc/group <rootbeer@teleport.com>
Re: Help with S/$var/val/ problem (Jean-Damien Durand)
Re: Help with S/$var/val/ problem (Greg Bacon)
Re: Info Regarding Perl 5.005 (Jason Gloudon)
Re: MKDIR problem (Gabor)
Re: Obfuscated Perl: figure this one out (Kevin Reid)
Oops ( was:Re: Simple Unix Question, ( Simple for you (Rob Tanner)
Re: Optimization regexp/list for string search (Greg Bacon)
Re: Optimization regexp/list for string search (Andrew M. Langmead)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 09 Apr 1998 15:14:07 GMT
From: John Porter <jdporter@min.net>
Subject: Re: "Continuations" in Perl
Message-Id: <352CE727.B01@min.net>
John Porter wrote:
>
>[snippety snip]
I am so sorry. Every time I tried to post, I got a
"news server configuration" error message.
Kept trying, little realizing...
John Porter
------------------------------
Date: Thu, 9 Apr 1998 14:53:43 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: @INC and avoiding -I
Message-Id: <Er5IpK.4xt@world.std.com>
Build Administrator <bldadmin@esd.sgi.com> writes:
>On an NT4 system, how/where does @INC get initialized?
Unlike unix perl, which has the paths hard coded into the executable,
the Win32 port puts the directories for @INC in the system registry.
>I'm unable to use modules and INC is pointing to the wrong directories.
>If I attempt to append to it at run time (prior to a use directive),
>the use directive is flagged and the script won't run.
As others have mentioned, since "use" happens at compile time, not
runtime, runtime changes to @INC wont' come into effect soon
enough. If you want to put the changes in your perl script, best thing
to do is to use the "use lib" pragma. Otherwise, you could always set
the PERLLIB environment variable.
--
Andrew Langmead
------------------------------
Date: 09 Apr 1998 15:05:35 +0200
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: [Q] How to extract a line at a time from a $string
Message-Id: <isbtub16xs.fsf@godzilla.kiere.ericsson.se>
"Stephen_Chan" <schan_ca@rocketmail.com> writes:
> Now I need to iterate through "$mystring" one line
> at a time, sort of speak, so that I get:
foreach (split(/\n/,$mystring))
{
# do stuff to $_
}
This is pretty basic stuff. I really hope that you're just learning
Perl and not programming for real.
--
Calle Dybedahl, UNIX Sysadmin
qdtcall@esavionics.se http://www.lysator.liu.se/~calle/
------------------------------
Date: Thu, 9 Apr 1998 08:10:46 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Duncan Cameron <dcameron@nospam.bcs.org.uk>
Subject: Re: [Q] How to extract a line at a time from a $string
Message-Id: <Pine.GSO.3.96.980409080733.9100E-100000@user2.teleport.com>
On 9 Apr 1998, Duncan Cameron wrote:
> while ($mystring =~ /(.*\n)/g) {
> Or this:
>
> @part = ($mystring =~ /.*\n/g);
Be sure that the string ends with a final newline, or these won't work. I
prefer this:
for (split /\n/, $mystring) { ... }
...and as an added feature, the string is now "pre-chomped". Hope this
helps!
> Remove 'nospam.' to get my return address.
Remove 'nospam.' if you want replies by email. :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 9 Apr 1998 10:26:58 -0400
From: kcohen@julius.ling.ohio-state.edu (Kevin B Cohen)
Subject: arrays in Format
Message-Id: <6gilri$4q2@julius.ling.ohio-state.edu>
hi,
i am much enamored of perl's Format facility (data type??), which lets
you easily be very specific about what printed output will look like.
it's possible to get a format to print out a variable, or to print out
the return value of a subroutine. my question: is it possible to get
a format to print out an array?
kevin
"If we suppose for the moment that a pizza is a syntacticaly
structure..." --Nigel Chapman, "Perl: The Programmer's Companion"
------------------------------
Date: Thu, 9 Apr 1998 08:04:17 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Mark Polakow <mark@imp.net>
Subject: Re: BIG RENAME QUESTION???
Message-Id: <Pine.GSO.3.96.980409080213.9100D-100000@user2.teleport.com>
On Thu, 9 Apr 1998, Mark Polakow wrote:
> Subject: BIG RENAME QUESTION???
Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
> rename ("$file","$newname") or die "$!";
Those double quotes are superfluous. (They make it look as if they're
doing something, but they're not.)
> This works fine and renames like it should when executed from the
> commandline but returns
> 'C:\WEBSHARE\CGI-PERL\rename.pl' script produced no output
> when run from cgi
When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to solving
such problems. It's available on CPAN.
http://www.perl.com/CPAN/
http://www.perl.org/CPAN/
http://www.perl.org/CPAN/doc/FAQs/cgi/idiots-guide.html
http://www.perl.org/CPAN/doc/manual/html/pod/
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 9 Apr 1998 14:13:59 GMT
From: abw@cre.canon.co.uk (Andy Wardley)
Subject: Re: Can somebody help me understand the internals of "Carp"?
Message-Id: <Er5GvB.Gsr@cre.canon.co.uk>
Ken Gentle <kgentle@platinum.com> wrote:
>An annotated listing of Carp.pm might be all I need. I would really
>appreciate an interpretation, especially of "shortmess".
For your viewing pleasure... an annotated Carp.pm. I've commented most
of the code, leaving out only a couple of minor spots where my understanding
is fuzzy or I haven't bothered to properly think it out. These are
hopefully few and far between so it should be enough to get you going.
Hope this helps.
A
package Carp;
=head1 NAME
carp - warn of errors (from perspective of caller)
cluck - warn of errors with stack backtrace
(not exported by default)
croak - die of errors (from perspective of caller)
confess - die of errors with stack backtrace
=head1 SYNOPSIS
use Carp;
croak "We're outta here!";
use Carp qw(cluck);
cluck "This is how we got here!";
=head1 DESCRIPTION
The Carp routines are useful in your own modules because
they act like die() or warn(), but report where the error
was in the code they were called from. Thus if you have a
routine Foo() that has a carp() in it, then the carp()
will report the error as occurring where Foo() was called,
not where carp() was called.
=head2 Forcing a Stack Trace
As a debugging aid, you can force Carp to treat a croak as a confess
and a carp as a cluck across I<all> modules. In other words, force a
detailed stack trace to be given. This can be very helpful when trying
to understand why, or from where, a warning or error is being generated.
This feature is enabled by 'importing' the non-existant symbol
'verbose'. You would typically enable it by saying
perl -MCarp=verbose script.pl
or by including the string C<MCarp=verbose> in the L<PERL5OPT>
environment variable.
=cut
# This package is heavily used. Be small. Be fast. Be good.
#========================================================================
#
# Comments added by Andy Wardley <abw@kfs.org> 09-Apr-98, based on an
# **almost** complete understanding of the package. Corrections and
# comments are welcome.
#
#========================================================================
#
# The $CarpLevel variable can be set to "strip off" extra caller levels for
# those times when Carp calls are buried inside other functions. The
# $Max(EvalLen|(Arg(Len|Nums)) variables are used to specify how the eval
# text and function arguments should be formatted when printed.
#
$CarpLevel = 0; # How many extra package levels to skip on carp.
$MaxEvalLen = 0; # How much eval '...text...' to show. 0 = all.
$MaxArgLen = 64; # How much of each argument to print. 0 = all.
$MaxArgNums = 8; # How many arguments to print. 0 = all.
require Exporter;
@ISA = Exporter;
@EXPORT = qw(confess croak carp);
@EXPORT_OK = qw(cluck verbose);
@EXPORT_FAIL = qw(verbose); # hook to enable verbose mode
#
# if the caller specifies verbose usage ("perl -MCarp=verbose script.pl")
# then the following function will be called by the Exporter which knows
# to do this thanks to @EXPORT_FAIL, above. $_[1] will contain the word
# 'verbose'.
#
sub export_fail {
# get rid of the package name passed implicitly
shift;
if ($_[0] eq 'verbose') {
# disable warnings to avoid "sub-routine redefined..." warning
local $^W = 0;
# set shortmess() as an alias to longmess()
*shortmess = \&longmess;
# remove 'verbose' from the args to keep Exporter happy
shift;
}
return @_;
}
#
# longmess() crawls all the way up the stack reporting on all the function
# calls made. The error string, $error, is originally constructed from the
# arguments passed into longmess() via confess(), cluck() or shortmess().
# This gets appended with the stack trace messages which are generated for
# each function call on the stack.
#
sub longmess {
my $error = join '', @_;
my $mess = "";
my $i = 1 + $CarpLevel;
my ($pack,$file,$line,$sub,$hargs,$eval,$require);
my (@a);
#
# crawl up the stack....
#
while (do { { package DB; @a = caller($i++) } } ) {
# get copies of the variables returned from caller()
($pack,$file,$line,$sub,$hargs,undef,$eval,$require) = @a;
#
# if the $error error string is newline terminated then it
# is copied into $mess. Otherwise, $mess gets set (at the end of
# the 'else {' section below) to one of two things. The first time
# through, it is set to the "$error at $file line $line" message.
# $error is then set to 'called' which triggers subsequent loop
# iterations to append $sub to $mess before appending the "$error
# at $file line $line" which now actually reads "called at $file line
# $line". Thus, the stack trace message is constructed:
#
# first time: $mess = $error at $file line $line
# subsequent times: $mess .= $sub $error at $file line $line
# ^^^^^^
# "called"
if ($error =~ m/\n$/) {
$mess .= $error;
} else {
# Build a string, $sub, which names the sub-routine called.
# This may also be "require ...", "eval '...' or "eval {...}"
if (defined $eval) {
if ($require) {
$sub = "require $eval";
} else {
$eval =~ s/([\\\'])/\\$1/g;
if ($MaxEvalLen && length($eval) > $MaxEvalLen) {
substr($eval,$MaxEvalLen) = '...';
}
$sub = "eval '$eval'";
}
} elsif ($sub eq '(eval)') {
$sub = 'eval {...}';
}
# if there are any arguments in the sub-routine call, format
# them according to the format variables defined earlier in
# this file and join them onto the $sub sub-routine string
if ($hargs) {
# we may trash some of the args so we take a copy
@a = @DB::args; # must get local copy of args
# don't print any more than $MaxArgNums
if ($MaxArgNums and @a > $MaxArgNums) {
# cap the length of $#a and set the last element to '...'
$#a = $MaxArgNums;
$a[$#a] = "...";
}
for (@a) {
# set args to the string "undef" if undefined
$_ = "undef", next unless defined $_;
if (ref $_) {
# dunno what this is for...
$_ .= '';
s/'/\\'/g;
}
else {
s/'/\\'/g;
# terminate the string early with '...' if too long
substr($_,$MaxArgLen) = '...'
if $MaxArgLen and $MaxArgLen < length;
}
# 'quote' arg unless it looks like a number
$_ = "'$_'" unless /^-?[\d.]+$/;
# print high-end chars as 'M-<char>' or '^<char>'
s/([\200-\377])/sprintf("M-%c",ord($1)&0177)/eg;
s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg;
}
# append ('all', 'the', 'arguments') to the $sub string
$sub .= '(' . join(', ', @a) . ')';
}
# here's where the error message, $mess, gets constructed
$mess .= "\t$sub " if $error eq "called";
$mess .= "$error at $file line $line\n";
}
# we don't need to print the actual error message again so we can
# change this to "called" so that the string "$error at $file line
# $line" makes sense as "called at $file line $line".
$error = "called";
}
# this kludge circumvents die's incorrect handling of NUL
my $msg = \($mess || $error);
$$msg =~ tr/\0//d;
$$msg;
}
#
# shortmess() is called by carp() and croak() to skip all the way up to
# the top-level caller's package and report the error from there. confess()
# and cluck() generate a full stack trace so they call longmess() to
# generate that. In verbose mode shortmess() is aliased to longmess() so
# you always get a stack trace
#
sub shortmess { # Short-circuit &longmess if called via multiple packages
my $error = join '', @_;
my ($prevpack) = caller(1);
my $extra = $CarpLevel;
my $i = 2;
my ($pack,$file,$line);
# when reporting an error, we want to report it from the context of the
# calling package. So what is the calling package? Within a module,
# there may be many calls between methods and perhaps between sub-classes
# and super-classes, but the user isn't interested in what happens
# inside the package. We start by building a hash array which keeps
# track of all the packages to which the calling package belongs. We
# do this by examining its @ISA variable. Any call from a base class
# method (one of our caller's @ISA packages) can be ignored
my %isa = ($prevpack,1);
# merge all the caller's @ISA packages into %isa.
@isa{@{"${prevpack}::ISA"}} = ()
if(defined @{"${prevpack}::ISA"});
# now we crawl up the calling stack and look at all the packages in
# there. For each package, we look to see if it has an @ISA and then
# we see if our caller features in that list. That would imply that
# our caller is a derived class of that package and its calls can also
# be ignored
while (($pack,$file,$line) = caller($i++)) {
if(defined @{$pack . "::ISA"}) {
my @i = @{$pack . "::ISA"};
my %i;
@i{@i} = ();
# merge any relevant packages into %isa
@isa{@i,$pack} = ()
if(exists $i{$prevpack} || exists $isa{$pack});
}
# and here's where we do the ignoring... if the package in
# question is one of our caller's base or derived packages then
# we can ignore it (skip it) and go onto the next (but note that
# the continue { } block below gets called every time)
next
if(exists $isa{$pack});
# Hey! We've found a package that isn't one of our caller's
# clan....but wait, $extra refers to the number of 'extra' levels
# we should skip up. If $extra > 0 then this is a false alarm.
# We must merge the package into the %isa hash (so we can ignore it
# if it pops up again), decrement $extra, and continue.
if ($extra-- > 0) {
%isa = ($pack,1);
@isa{@{$pack . "::ISA"}} = ()
if(defined @{$pack . "::ISA"});
}
else {
# OK! We've got a candidate package. Time to construct the
# relevant error message and return it. die() doesn't like
# to be given NUL characters (which $msg may contain) so we
# remove them first.
(my $msg = "$error at $file line $line\n") =~ tr/\0//d;
return $msg;
}
}
continue {
$prevpack = $pack;
}
# uh-oh! It looks like we crawled all the way up the stack and
# never found a candidate package. Oh well, let's call longmess
# to generate a full stack trace. We use the magical form of 'goto'
# so that this shortmess() function doesn't appear on the stack
# to further confuse longmess() about it's calling package.
goto &longmess;
}
#
# the following four functions call longmess() or shortmess() depending on
# whether they should generate a full stack trace (confess() and cluck())
# or simply report the caller's package (croak() and carp()), respectively.
# confess() and croak() die, carp() and cluck() warn.
#
sub confess { die longmess @_; }
sub croak { die shortmess @_; }
sub carp { warn shortmess @_; }
sub cluck { warn longmess @_; }
1;
--
Andy Wardley <abw@kfs.org> http://www.kfs.org/~abw
Signature lost in transit. We apologise for any inconvenience caused.
------------------------------
Date: Thu, 09 Apr 1998 11:16:18 -0400
From: Stacy Hunter <snx@snx.com>
Subject: crontab command
Message-Id: <352CE63D.3C0DE08B@snx.com>
I apologize if this is somewhat off topic, however, what I would like to
do is launch a perl script from crontab, thus if I wanted the script
"file.pl" launched every morning at 10, the line would look like:
* 10 * * * ____________/path/file.pl.
Can someone help me fill in the blank?
Thanks much.
And thanks to those who helped me out with the earlier part of this
question regarding Passwords!
- Stacy
------------------------------
Date: Thu, 09 Apr 1998 10:17:54 -0600
From: bob_barthelow@hp.com
Subject: display location in browser for bookmarking
Message-Id: <6gior2$98g$1@nnrp1.dejanews.com>
I have written a web server perl cgi program which will read and modify an
html file and return it to the user. It accomplishes this by reading the html
file into an array and then printing the array after making some
modifications. Everything works fine. However, the user cannot bookmark the
page in the browser. The location line reflects only the the perl script.
e.g. http://my.web.server/scripts/myperl.pl. What I want to have appear in
the browser location: window is -
http://my.web.server/scripts/myperl.pl?p1=x&p2=y....etc.
The form in the page that makes the call to the perl script passes the
parameters using POST.
Being new at this I looked at AltaVista as an example. When I search on gorp,
what is returned in the location field is:
http://altavista.digital.com/cgi-bin/query?pg=q&what=web&kl=XX&q=gorp&search.x
=38&search.y=8.
How can I accomplish this in my perl CGI program? What does the browser look
at to display the location field?
tia,
bob barthelow
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Tue, 07 Apr 1998 17:01:11 GMT
From: Jason Karney <jkarney@netgenics.com>
Subject: embed Perl in Java
Message-Id: <352A5C59.3BF077C@netgenics.com>
I am trying to figure out the best way to embed Perl in Java, so that a
Java applet could interpret an arbitrary Perl script. The only info on
this subject I have seen is for the JPL, which so far as I can tell, is
only available as part of the Perl Resource Kit from O'Reilly.
Any suggestions or comments on this issue would be greatly appreciated.
Thanks.
--
--------------------------------------------------------------------
Jason Karney -- NetGenics Research Team jkarney@netgenics.com
------------------------------
Date: Thu, 9 Apr 1998 13:37:45 GMT
From: Faisal Karmali <fkarmali@uwaterloo.ca>
Subject: Explicit Variable Declarations
Message-Id: <Pine.OSF.3.93.980409093726.3129A-100000@novice.uwaterloo.ca>
Is there any way to make Perl require variables to be declared? For
example, I recently had a problem because I misspelled a variable name.
Rather than complaining, it creates a new variable with the misspelled
name.
Thanks.
------------------------------
Date: Thu, 9 Apr 1998 11:07:24 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Explicit Variable Declarations
Message-Id: <1d77sfm.163i93nkpdpz4N@slip166-72-108-50.ny.us.ibm.net>
Faisal Karmali <fkarmali@uwaterloo.ca> wrote:
> Is there any way to make Perl require variables to be declared? For
> example, I recently had a problem because I misspelled a variable name.
> Rather than complaining, it creates a new variable with the misspelled
> name.
>
> Thanks.
use strict "vars";
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: Thu, 9 Apr 1998 08:33:18 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Faisal Karmali <fkarmali@uwaterloo.ca>
Subject: Re: Explicit Variable Declarations
Message-Id: <Pine.GSO.3.96.980409082709.9100G-100000@user2.teleport.com>
On Thu, 9 Apr 1998, Faisal Karmali wrote:
> Subject: Explicit Variable Declarations
Parental Warning: The Following Perl Code contains Explicit Variable
Declarations!
:-)
> Is there any way to make Perl require variables to be declared?
Yes, this is one of the features of 'use strict'. I recomment using 'use
strict' from the beginning on any program that will ever be longer than
about a screenful of text. The full details are available through 'perldoc
strict'. Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 9 Apr 1998 14:00:42 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Generating Password from Username in Perl ?
Message-Id: <6gikaa$4b9$3@info.uah.edu>
[Posted and mailed]
In article <352cbcaa.9571342@news1.c2i.net>,
hege-n@hsr.no (Heggie) writes:
: I am trying to generate a password depending on the input on the
: username. The username consists of 6-7 numbers(integers).
: Let's say the Username is: ABCDEFG
: How can I make an algoritm so that the password generated is
: Password = 17 +83*BC ?
Perl provides an operator that allows you to extract substrings of a
string. Not surprisingly, this operator is called substr, and you can
read all about it in the perlfunc manpage.
For your particular problem, you can take advantage of the fact that
Perl doesn't make a distinction between numbers and strings, whereas in
a language like C, you'd have to convert a string to a numeric value.
In Perl, if you want to treat a scalar like a number, go ahead and do
something to it that you'd do to a number. If you want to treat it like
a string, go ahead and perform a string operation on it. Perl does all
the dirty work for you.
One way to solve you problem is this:
sub generate_password {
my $username = shift;
17 + 83 * substr($username, 1, 2);
}
Of course, you'll probably want to do a little error checking to make
sure that the username is in fact a string of at least six but not
more than seven digits.
Hope this helps,
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Thu, 9 Apr 1998 13:48:56 GMT
From: asquires@netcom.com (Andy Squires)
Subject: getgrent and reading /etc/group
Message-Id: <asquiresEr5FpK.JpA@netcom.com>
I have some questions about the system functions like getgrent, getpwent
etc.
First, is there something special about these functions that one should use
them instead of just reading through the group or passwd files?
Is there a way to get getgrent to recognize the fact that I have a group
which is carried over to two lines in the group file because there are to
many users listed for it to fit on one line. Or, is this a situation where
I should simply read through /etc/group and do the processing myself?
I appreciate any help.
Andy
--
| Andy Squires "The trouble with life is
| asquires@netcom.com there's no background music."
| Web Page is at http://www.announce.com/~asquires/andy.html
------------------------------
Date: Thu, 9 Apr 1998 08:25:20 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Andy Squires <asquires@netcom.com>
Subject: Re: getgrent and reading /etc/group
Message-Id: <Pine.GSO.3.96.980409081939.9100F-100000@user2.teleport.com>
On Thu, 9 Apr 1998, Andy Squires wrote:
> I have some questions about the system functions like getgrent, getpwent
> etc.
>
> First, is there something special about these functions that one should use
> them instead of just reading through the group or passwd files?
Yes. Many systems (such as NIS) keep the "real" password database in some
place other than /etc/passwd. If everything is properly installed, the
getpw* routines will find this information regardless of its location.
And, typically, it will do random accesses somewhat faster than a search
of /etc/passwd would be.
> Is there a way to get getgrent to recognize the fact that I have a group
> which is carried over to two lines in the group file because there are to
> many users listed for it to fit on one line.
If getgrent doesn't work right, something isn't installed (or configured)
properly. It's not likely to be perl's fault, though; check with your
vendor's docs. (Is your /etc/groups file in the right format?) Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 9 Apr 1998 13:01:30 GMT
From: ddurand@hpplus11.cern.ch (Jean-Damien Durand)
To: "Les Woolsey" <lwoolsey@innovative.ca>
Subject: Re: Help with S/$var/val/ problem
Message-Id: <6gigra$ae5$1@sunnews.cern.ch>
> I have a piece of code which can be summarized as follows:
>
> $_='junk%value%morejunk%$other%junk'; # a string for working on
> $kw = 'value'; #a value to look for in a variable
> s/%$kw%/frodo/g; #this substitution works
> $kw = '$other'; #this time the kw value contains a leading "$" character
> s/%kw%/beans/g; #this does not work !!!!!!!!!!!
Do: $kw = quotemeta('$other') and do not forget the '$' before kw in your
last regexp. See 'perldoc -f quotemeta'.
Cheers, Jean-Damien,
--
*******************************************************
* Jean-Damien Durand (Jean-Damien.Durand@cern.ch) *
* www : http://wwwinfo.cern.ch/~ddurand/ *
*******************************************************
------------------------------
Date: 9 Apr 1998 13:53:01 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Help with S/$var/val/ problem
Message-Id: <6gijrt$4b9$2@info.uah.edu>
In article <6gig0q$gk3$1@nr1.ottawa.istar.net>,
"Les Woolsey" <lwoolsey@innovative.ca> writes:
: I have a piece of code which can be summarized as follows:
:
: $_='junk%value%morejunk%$other%junk'; # a string for working on
: $kw = '$other'; #this time the kw value contains a leading "$"
: s/%kw%/beans/g; #this does not work !!!!!!!!!!!
:
: Can someone explain to me why the second substitution doesn't work. It's
: clearly caused by the $ in the contents of the variable.
Right. In the ``Regular Expressions'' section of the perlre manpage
(about a fifth of the way into the manpage--have you read it?), you
see the following list
In particular the following metacharacters have their
standard egrep-ish meanings:
\ Quote the next metacharacter
^ Match the beginning of the line
. Match any character (except newline)
$ Match the end of the line (or before newline at the end)
| Alternation
() Grouping
[] Character class
Take careful note of the special meaning attached to '$'.
: The actual code is running through a hash using the key values &
: substituting the associated values. It looks like:
:
: foreach $kw (keys %keywords)
: {
: $subct += s/%$kw%/$keywords{$kw}/g;
: }
:
: As I say, it works if the keyword ($kw) does not have a leading "$" but
: fails if it does. What have I done wrong & how do I fix it???
That will also break for many more characters that just the dollar sign.
If you page down one or two times, you'll find a way to quote (that is,
remove any special meaning) from all regular expression metacharacters.
The perlre manpage is good reading. I highly recommend it.
Hope this helps,
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Thu, 09 Apr 1998 15:35:04 GMT
From: jgloudon@manitoba.bbn.com (Jason Gloudon)
Subject: Re: Info Regarding Perl 5.005
Message-Id: <slrn6ipqg4.sla.jgloudon@manitoba.bbn.com>
Allen Choy <achoy@us.oracle.com> wrote:
>Anyone know what kind of features will be available in perl 5.005?
Big new feature : Multi-Threading.
--
Jason Gloudon
------------------------------
Date: 8 Apr 1998 19:20:39 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: MKDIR problem
Message-Id: <slrn6injn4.9cc.gabor@vnode.vmunix.com>
In comp.lang.perl.misc, Lasse Hillerxe Petersen <lassehp@imv.aau.dk> wrote :
# In article <Pine.GSO.3.96.980407173416.1034U-100000@user2.teleport.com>,
# Tom Phoenix <rootbeer@teleport.com> wrote:
#
# > "A program is written for the computer to interpret, and for the human
# > to interpret as well. We hope that they will agree on its meaning!"
#
# Well said. Anyway, I have been corresponding with BJF, and it turns out
# the problem was probably that the permissions given with mkdir are subject
# to the umask setting. An explicit chmod afterwards is necessary. I'm a
# little surprised noone has mentioned this yet?
I have two reasons for you.
1. You should know these things
2. And here is the kicker, it's mentioned on page 187 of the blue
camel
------------------------------
Date: Thu, 9 Apr 1998 11:07:20 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Obfuscated Perl: figure this one out
Message-Id: <1d77nwl.wh563cczomN@slip166-72-108-50.ny.us.ibm.net>
Excession <daclay@NOSPAMzip.com.au> wrote:
> On Wed, 8 Apr 1998 16:50:54 -0400, kpreid@ibm.net (Kevin Reid) wrote:
>
> >#!/usr/bin/perl -w-e 'open ME,@_[$$];print %_{$0+1}'
> >eval scalar((($_='!;_$$,!$_!;') =~ tr@_$;!,@=",$;@),
> >$_); eval "@{[reverse split /[1-9]/, '>1A2T3A5D4<6 '
> >.'7t8in1r2p2;405,801,8A9AT3k D5e6e7s8']}" __END__
>
> substituting eval for print:
Shouldn't that be "substituting print for eval"?
> c:\bat>perl tmppl.pl
> $,="";$"=$,s e e k D AT A , 0 , 0 ; p r in t < D A T A >
>
> Looks like attemps to print out your entire diskdrive.
When I run it, it only prints a little bit out.
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: Thu, 09 Apr 1998 08:40:22 -0700
From: rtanner@linfield.edu (Rob Tanner)
Subject: Oops ( was:Re: Simple Unix Question, ( Simple for you maybe ))
Message-Id: <rtanner-0904980840220001@wildflower.linfield.edu>
In article <rtanner-0804980819030001@wildflower.linfield.edu>,
rtanner@linfield.edu (Rob Tanner) wrote:
>
> `ls -l` is back-ticked. That means perl should execute the command "ls
> -l", the output of which is multiple lines and so is a list.
>
> The sequence $my_variable = `ls -l` will yield the count of returned lines
> in the variable $my_variable.
>
> The sequence @my_variable = `ls -l` will yield the output the the "ls"
> command in the array @my_variable.
>
> As you can see, there is a major difference there.
>
Oops, I goofed! :-(
Since I most typically use "@my_variable = `ls -l`" and never ever ever
use "$my_variable = `ls -l`", I forgot we are talking about i/o type
activity (pipes actually) and not array vs scalar contexts.
In the above cases, the back-ticked "ls -l" returns its full result to the
variable. If an list or array variable, line by line and element by
element. If a scalar, the whole output goes into the scalar as a scalar,
and if you want to view it line by line, you will need to split the line
up (using split or substr or some other equally grotesque mechanism --
which is why I never back-tick into a scalar).
Since I first misinformed and now must repent -- as the bible teaches,
it's payback plus 20%. So let me describe another way of executing UNIX
commands from within Perl and what the results look like.
open(LS, "ls -l |"); # the "|" is a UNIX pipe symbol
$my_variable = <LS>; # first line of output of ls command
$my_variable = <LS>; # second line of output of ls command
etc.
Not terribly useful as shown above, but see what I can do now:
open(LS, "ls -l |"); # the "|" is a UNIX pipe symbol
while (<LS>) { # a single line of output goes into $_
.... # the stuff I want to do
} # the "while" loop loops until EOT
Also, another way of collecting the command output:
open(LS, "ls -l |"); # the "|" is a UNIX pipe symbol
@my_variable = <LS>; # Is the equivalent of "@my_variable = `ls -l`"
And this method also works:
open(LS, "ls -l |"); # the "|" is a UNIX pipe symbol
print <LS>; # prints the output to STDOUT
That's my plus 20%. Sorry if I mislead anybody with my earlier erroneous
posting.
-- Rob
_ _ _ _ _ _ _ _ _ _
/\_\_\_\_\ /\_\ /\_\_\_\_\_\
/\/_/_/_/_/ /\/_/ \/_/_/_/_/_/ QUIDQUID LATINE DICTUM SIT,
/\/_/__\/_/ __ /\/_/ /\/_/ PROFUNDUM VIDITUR
/\/_/_/_/_/ /\_\ /\/_/ /\/_/
/\/_/ \/_/ /\/_/_/\/_/ /\/_/ (Whatever is said in Latin
\/_/ \/_/ \/_/_/_/_/ \/_/ sounds profound)
Rob Tanner
Manager of Systems and Communications
Linfield College, McMinnville, OR
(503) 434-2558 <rtanner@linfield.edu> _____________________________________________________________________
------------------------------
Date: 9 Apr 1998 13:44:19 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Optimization regexp/list for string search
Message-Id: <6gijbj$4b9$1@info.uah.edu>
In article <6gi2qt$jai$1@nnrp1.dejanews.com>,
herve_debar@hotmail.com writes:
: I have the following problem. I receive strings, and i keep them only if i
: haven't seen them previously. Right now, i'm storing the strings in an array
: and look iteratively for an exact match on all strings in the array.
Ouch. Actually, several (much more efficient) solutions to your problem
are covered in the FAQ (section four). Search for ``How can I extract
just the unique elements of an array?''
: Would a
: regexp search be more efficient, i.e. if i append all my strings into a large
: one, and do a regexp search ?
My guess is no because you'd have to recompile a constantly growing
regular expression for each iteration. If you want to be sure, you can
always use the Benchmark module that comes with the standard Perl
distribution.
Hope this helps,
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Thu, 9 Apr 1998 14:47:41 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Optimization regexp/list for string search
Message-Id: <Er5IFH.17A@world.std.com>
herve_debar@hotmail.com writes:
>I have the following problem. I receive strings, and i keep them only if i
>haven't seen them previously. Right now, i'm storing the strings in an array
>and look iteratively for an exact match on all strings in the array. Would a
>regexp search be more efficient, i.e. if i append all my strings into a large
>one, and do a regexp search ?
No a regular expression would probably not be more efficient, and if
you combine all of the strings together you may have the problem where
a regex would match two substrings of two different "elements", since
the line between them would be blurred.
Have you seen the FAQ entry "How can I tell whether an array contains
a certain element?"
<URL:http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq4/
How_can_I_tel_whether_an_aray_.html>
It suggests using the keys to a hash to store the data, and then you
can tell if the data is there without looping. If the hash has that
element, it is already there.
--
Andrew Langmead
------------------------------
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 2281
**************************************