[9244] in Perl-Users-Digest
Perl-Users Digest, Issue: 2839 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 11 11:17:14 1998
Date: Thu, 11 Jun 98 08:01:45 -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, 11 Jun 1998 Volume: 8 Number: 2839
Today's topics:
Re: reverse sorting (Michael J Gebis)
Re: Sorry for seperate posts <barnett@houston.Geco-Prakla.slb.com>
Re: Stages in a pipeline <tchrist@mox.perl.com>
Re: taking data out of ':' delimited string and placing dejajustin@my-dejanews.com
Re: taking data out of ':' delimited string and placing <jdf@pobox.com>
Re: taking data out of ':' delimited string and placing (Greg Andrews)
Vote today, read CFV for c.l.p.moderated, Post the CFV <ngouah@erols.com>
Re: Vote today, read CFV for c.l.p.moderated, Post the (Nathan V. Patwardhan)
Re: Vote today, read CFV for c.l.p.moderated, Post the (Chris Nandor)
Re: Vote today, read CFV for c.l.p.moderated, Post the <tchrist@mox.perl.com>
Why doesn't this work? <hannum@oak.cat.ohiou.edu>
Re: Why it's stupid to `use a variable as a variable na (Alan K. Jackson)
Win32 error message frinteru@hotmail.com
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Jun 1998 04:29:31 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: reverse sorting
Message-Id: <6lnmfb$dos@mozo.cc.purdue.edu>
Kwon Soon Son <cessi@hantan.postech.ac.kr> writes:
}what i'm trying to to is reverse sorting.
Read the man page on sort for the details, but the short and sweet of
it is, use something like this:
sort { $b <=> $a} @srclist;
In other words, plug in your own sort routine that sorts in reverse
order. Neat, no?
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: Thu, 11 Jun 1998 08:44:42 -0500
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: Sorry for seperate posts
Message-Id: <357FDF4A.D6481FC8@houston.Geco-Prakla.slb.com>
Michael D. Hofer wrote:
>
> John Porter wrote:
> >
> > HtmlPlace.Com wrote:
> > >
> > > I have searched all my local book store for "Programming Perl" "The
> > > Camel Book" and "The Llama Book" and nobody in this little side street
> > > town has them or can order them is there a place I can buy them directly
> > > or indirectly through a phone number rather than giving my credit card
> > > number online ?
> >
> > Computer Literacy Bookshops: 800-789-8590
> >
> > john Porter
>
> or my favorite (no relationship) at http://www.vcss.com/, order, and
> then you can call or fax your CC #...(or mail a check/mo)
>
<sig snipped>
I rather enjoy the convenience & simplicity of Amazon.com
(http://www.amazon.com). Books delivered right to your door in 2-3
days. They have a good stock of books, and should have the ones you
mentioned.
Or, you can go the direct to the source route at O'Reilly
(http://www.ora.com).
HTH.
Dave
--
"Security through obscurity is no security at all."
-comp.lang.perl.misc newsgroup posting
----------------------------------------------------------------------
Dave Barnett U.S.: barnett@houston.Geco-Prakla.slb.com
DAPD Software Support Eng U.K.: barnett@gatwick.Geco-Prakla.slb.com
----------------------------------------------------------------------
------------------------------
Date: 11 Jun 1998 12:22:46 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Stages in a pipeline
Message-Id: <6loi6m$lo$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Scott Bronson <sbronson@opentv.com> writes:
:I've been programming in Perl for a few weeks now. Long enough to
:recognize that there must be an elegant(ish) Perl solution to this
:problem, but not long enough to know what it is.
Ah, a beginner! Well, let it not be said that beginners' questions go
unanswered. Ask and you shall receive. I present to you an incremental
solution to your question that is virtually guaranteed unique amongst
respondents.
:Now, I'd like to set these functions up as a pipeline. One pipeline
:configuration would be:
:
:Print -> Format_Lists -> Number_Lines -> Remove_Header -> Get_Paragraph
:
:So, print calls Format Lists until Format_Lists returns null, printing
:out the data returned, and so on up the pipe. If I didn't want line
:numbers, I just re-order the stages in the pipe:
:
:Print -> Format_Lists -> Remove_Header -> Get_Paragraph
:
:And if I wanted headers and formatted lists, but no line numbers:
:
:Print -> Format_Lists -> Get_Paragraph
:
:You get the idea. What's an efficient, flexible way to set this up in
:Perl? Thanks,
First, a simple example implementing head -100:
head(100);
while (<>) {
print;
}
sub head {
my $lines = shift || 20;
return unless $pid = open(STDOUT, "|-");
die "cannot fork: $!" unless defined $pid;
while (<STDIN>) {
print;
last if --$lines < 0;
}
exit;
}
Now an incrementally more complex solution, which sets of one filter to
quote lines, another to number them:
number(); # push number filter on STDOUT
quote(); # push quote filter on STDOUT
while (<>) { # act like /bin/cat
print;
}
close STDOUT; # tell kids we're done--politely
exit;
sub number {
my $pid;
return if $pid = open(STDOUT, "|-");
die "cannot fork: $!" unless defined $pid;
while (<STDIN>) { printf "%d: %s", $., $_ }
exit;
}
sub quote {
my $pid;
return if $pid = open(STDOUT, "|-");
die "cannot fork: $!" unless defined $pid;
while (<STDIN>) { print "> $_" }
exit;
}
Once you have come to understand that one, it's time to
generalize the mechanism. Here are examples:
% ftroop /etc/motd
% ftroop -head=2 /etc/motd
% ftroop -number /etc/motd
% ftroop -number -quote /etc/motd
% ftroop -quote -number /etc/motd
% ftroop -revbyte /etc/motd
% ftroop -revbyte -revword /etc/motd
% ftroop -revword /etc/motd
% ftroop -titular /etc/motd
% ftroop -titular -hexnum /etc/motd
And here's the code
#!/usr/bin/perl
# ftroop - manage a whole troop of filters
# tchrist@perl.com
%filters = (
number => sub { "$.: $_" },
quote => sub { /\S/ && s/^/> /; $_; },
head => sub { exit if $. > $_[0]; $_; },
revword => sub { join(" ", reverse split(" ")) . "\n" },
revbyte => sub { chomp; $_ = scalar reverse . "\n" },
hexnum => sub {
s/(\d+)/sprintf("%#x", $1)/ge;
return $_;
},
titular => sub {
s{
(?! (?: a | an | the | of | to | or | and | at ) )
( \b \w+ \b )
}{\u$1}gx;
s/(\w)/\u$1/;
s/(\w+)(\W*)$/\u$1$2/;
return $_;
},
);
while (@ARGV && $ARGV[0] =~ /^-(.*)/) {
my($filter, @args) = split(/=/, $1);
shift;
my $code = $filters{$filter};
unless ($code) {
warn "$0: No filter for $filter\n";
next;
}
#print STDERR "$0: starting filter $filter\n";
start_filter($code, @args);
}
print while <>;
close STDOUT; # tell kids we're done--politely
exit;
sub start_filter {
my $code = shift;
return if $pid = open(STDOUT, "|-");
die "cannot fork: $!" unless defined $pid;
while (<STDIN>) { print $code->(@_) || $_ }
exit;
}
I couldn't decide whether the functions should just return the new thing,
or mutate $_. Production code should be clearer on this.
Now, is that cool, or what?
--tom
--
It is Unix. It is possible to overcome any number of these bogus features. --pjw
------------------------------
Date: Thu, 11 Jun 1998 12:48:41 GMT
From: dejajustin@my-dejanews.com
Subject: Re: taking data out of ':' delimited string and placing it into 6 variables
Message-Id: <6lojna$9uh$1@nnrp1.dejanews.com>
be sure something is being placed into $_...
if you'r running this on the password file then a chop command before your
line should do the trick..
In article <357FAFAE.E21047EF@bnex.com>,
Azman Shariff <azman@bnex.com> wrote:
>
> hi....
>
> i need a solution ..... I am quiet a novice in perl.... so maybe a few
> poniters would do me good :)
>
> data :
> roger:1002:10004:Roger Deng:/home/roger:/bin/bash
>
> looks familiar huh? .. .yepp it is from my passwd file.... i need to
> write code to takethe six fields and put them in diff variables like
> these
>
> var:
> $uname
> $uid
> $gid
> $fullname
> $home
> $shell
>
> how do i proceed? i tried this :
>
> ($fielduname, $fielduid, $fieldgid, $fieldfullname, $fieldhome,
> $fieldshell) = split(/:/,$_,6);
>
> doesn't seem to work though..
>
> if therei s a solution pls email me at azman@bnex.com or
> portal@pacific.net.sg
>
> thanx in advance guys!
>
>
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 11 Jun 1998 08:56:26 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Azman Shariff <azman@bnex.com>
Subject: Re: taking data out of ':' delimited string and placing it into 6 variables
Message-Id: <90n4hwj9.fsf@mailhost.panix.com>
Azman Shariff <azman@bnex.com> writes:
> how do i proceed? i tried this :
>
> ($fielduname, $fielduid, $fieldgid, $fieldfullname, $fieldhome,
> $fieldshell) = split(/:/,$_,6);
>
> doesn't seem to work though..
It what way does that "not work"? Does it cause your machine to emit
shrapnel? Does it print out the value of pi? What?
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf/
------------------------------
Date: 11 Jun 1998 14:31:41 GMT
From: gerg@shell. (Greg Andrews)
Subject: Re: taking data out of ':' delimited string and placing it into 6 variables
Message-Id: <6lopod$3l3$3@news.ncal.verio.com>
Azman Shariff <azman@bnex.com> writes:
>
>data :
> roger:1002:10004:Roger Deng:/home/roger:/bin/bash
>
>looks familiar huh? .. .yepp it is from my passwd file.... i need to
>write code to takethe six fields and put them in diff variables like
>these
>
>var:
> $uname
> $uid
> $gid
> $fullname
> $home
> $shell
>
>how do i proceed? i tried this :
>
> ($fielduname, $fielduid, $fieldgid, $fieldfullname, $fieldhome,
>$fieldshell) = split(/:/,$_,6);
>
>doesn't seem to work though..
>
The /etc/passwd file has 7 fields, not 6. Your example is missing the
password field between 'roger' and '1002'. Could that be the trouble
you're seeing?
-Greg
------------------------------
Date: Thu, 11 Jun 1998 10:01:09 -0400
From: Ngouah A Nguiamba <ngouah@erols.com>
Subject: Vote today, read CFV for c.l.p.moderated, Post the CFV here today,
Message-Id: <357FE325.4937@erols.com>
Please post the CFV in comp.lang.perl.misc today. One can
easily overlook the post done to news.groups, as I did.
There are too many newcomers who need to vote and are not
yet familiar with the issues.
My apologies for a previous post, where I voiced my discontent
that the CFV could not be found easily.
Birgitt Funk
------------------------------
Date: 11 Jun 1998 13:44:18 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Vote today, read CFV for c.l.p.moderated, Post the CFV here today,
Message-Id: <6lomvi$rqd@fridge.shore.net>
Ngouah A Nguiamba (ngouah@erols.com) wrote:
: Please post the CFV in comp.lang.perl.misc today. One can
: easily overlook the post done to news.groups, as I did.
I don't think that the CFV lets any of us repost it or mail it to
you. I think that the CFV was posted here as well, FYI.
--
Nate Patwardhan|root@localhost
"Fortunately, I prefer to believe that we're all really just trapped in a
P.K. Dick book laced with Lovecraft, and this awful Terror Out of Cambridge
shall by the light of day evaporate, leaving nothing but good intentions in
its stead." Tom Christiansen in <6k02ha$hq6$3@csnews.cs.colorado.edu>
------------------------------
Date: Thu, 11 Jun 1998 14:20:34 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Vote today, read CFV for c.l.p.moderated, Post the CFV here today,
Message-Id: <pudge-1106981014520001@dynamic174.ply.adelphia.net>
In article <6lomvi$rqd@fridge.shore.net>, nvp@shore.net (Nathan V.
Patwardhan) wrote:
# Ngouah A Nguiamba (ngouah@erols.com) wrote:
# : Please post the CFV in comp.lang.perl.misc today. One can
# : easily overlook the post done to news.groups, as I did.
#
# I don't think that the CFV lets any of us repost it or mail it to
# you. I think that the CFV was posted here as well, FYI.
Correct. It is against the rules to repost the CFV, and the CFV was
already posted here anyway.
Newsgroups:
news.announce.newgroups,news.groups,comp.lang.perl.misc,comp.lang.perl.announce
Subject: CFV: comp.lang.perl.moderated moderated
Followup-To: poster
Message-ID: <897448637.29761@isc.org>
--
Chris Nandor mailto:pudge@pobox.com http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10 1FF77F13 8180B6B6'])
------------------------------
Date: 11 Jun 1998 14:29:23 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Vote today, read CFV for c.l.p.moderated, Post the CFV here today,
Message-Id: <6lopk3$9ae$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, pudge@pobox.com (Chris Nandor) writes:
:It is against the rules to repost the CFV, and the CFV was
:already posted here anyway.
True on both counts. Unfortunately, those of us who kill crossposts
consequently missed it (like me).
--tom
--
/* And you'll never guess what the dog had */
/* in its mouth... */
--Larry Wall in stab.c from the v4.0 perl source code
------------------------------
Date: Thu, 11 Jun 1998 14:22:38 GMT
From: "Dave" <hannum@oak.cat.ohiou.edu>
Subject: Why doesn't this work?
Message-Id: <EuE2Eq.Hwv@boss.cs.ohiou.edu>
I am attempting to read the contents of an Informix table, and attempting to
return the rows of the column it contains into a dropdown menu box. I get
the following error:
syntax error at populate.pl line 51, near "my"
Not enough arguments for values at populate.pl line 70, near "values ="
I don't know why. Any clues?
Thanks for your help.
Dave
#################################
# below is referenced error line 51
my $query =<<EndOfQuery;
select *
from $table
EndOfQuery
my $cursor = $dbh->prepare($query);
$cursor = $dbh->prepare($query);
$cursor->execute;
$cursor->bind_columns(undef, \($name, $value));
while ($cursor->fetchrow_arrayref) {
push(@array, $name);
$hash{$name} = $value;
}
$cursor->finish;
# below is referenced error line 70
print header, popup_menu(-name => 'popup', -values = [@array], -labels =>
{%hash});
$dbh->disconnect();
print $form->endform();
print $form->end_html();
exit (0);
------------------------------
Date: 11 Jun 1998 14:35:25 GMT
From: ajackson+news@shellus.com (Alan K. Jackson)
Subject: Re: Why it's stupid to `use a variable as a variable name'
Message-Id: <slrn6nvqpc.9go.ajackson+news@mactra.brc.shell.com>
In article <6lnb70$lct$1@monet.op.net>, Mark-Jason Dominus wrote:
>
> People show up in comp.lang.perl.misc all the time asking how to use
> the contents of a variable as the name of another variable. For
> example, they have $foo = 'snonk', and then they want to operate on
> the value of $snonk.
> ...bobbit
> When people come into comp.lang.perl.misc asking how to do something
> stupid, I'm never quite sure what to do. I can just answer the
> question as asked, figuring that it's not my problem to tell people
> that they're being stupid. That's in my self-interest, because it
> takes less time to answer the question that way, and because someone
> might someday pay me to clean up after their stupidity, as happened in
> this instance. But if I do that, people might jump on me for being a
> smart aleck, which has happened at times. (``Come on, help the poor
> guy out; if you know what he really need why don't you just give it to
> him?'')
>
Personally I read this newsgroup (and others) not to "get the answer", but
to try to understand the deeper structure of the language. In every
language there is an idiom for doing things, that may not be at all
obvious. I want to learn the idiom, and that is what would be useful
for these folks to learn - whether they know it or not. In Perl, using
hashes instead of using the name of a variable as the contents of a variable
is a key idiom. There may be more than one way to do it, but many of the
ways to do it are wrong-headed and fraught with perils. Good idiomatic
use of a language should produce readable, robust, efficient code.
------------------------------
Date: Thu, 11 Jun 1998 13:07:02 GMT
From: frinteru@hotmail.com
To: michael_stahl@peoplesoft.com
Subject: Win32 error message
Message-Id: <6lokpl$bai$1@nnrp1.dejanews.com>
Hello all,
I am running a perl script to automate some processes on an NT machine using
Perl 4.003 for Win32. The error message that I am getting is as follows:
Can't locate object method "autoflush" via packager "IO::Handle" at autorps
line 83.
It should not look for the IO::handle.pm or should it? does the environment
have to be set right in your system path?
We are operating in an mks environ.
Any help would be appreciated.
Michael
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
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 2839
**************************************