[13548] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 958 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 30 21:07:36 1999

Date: Thu, 30 Sep 1999 18:05:10 -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: <938739910-v9-i958@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 30 Sep 1999     Volume: 9 Number: 958

Today's topics:
        Bug in Perl 5.0? or something to do with RegExp alex_rayan@my-deja.com
    Re: Bug in Perl 5.0? or something to do with RegExp (Larry Rosler)
    Re: Bye Tom? (WAS: Re: injecting "my" varibales into ca <ltl@rgsun5.viasystems.com>
    Re: Bye Tom? (WAS: Re: injecting "my" varibales into ca <jbc@shell2.la.best.com>
    Re: Bye Tom? (WAS: Re: injecting "my" varibales into ca <cassell@mail.cor.epa.gov>
    Re: Calling a subroutine held at one sever from another geotekjohn@my-deja.com
    Re: Catching errors in anouther name space. <cassell@mail.cor.epa.gov>
        console program <SternSZ@gmx.de>
    Re: console program <makkulka@cisco.com>
    Re: dates <cassell@mail.cor.epa.gov>
    Re: forms and validation of strings... <cassell@mail.cor.epa.gov>
    Re: Hashes w/multiple values per key (Perl Cookbook) <R <cassell@mail.cor.epa.gov>
    Re: Help with this Crazy script! <spowell@usurf.com>
    Re: Help with this Crazy script! <jtraug@seanet.com>
    Re: Help with this Crazy script! <ltl@rgsun5.viasystems.com>
        Help: Subroutines in Perl <jedin@twistedmatrix.com>
    Re: Help: Subroutines in Perl <makkulka@cisco.com>
    Re: newbie: preload .wav files question <cassell@mail.cor.epa.gov>
    Re: numeric sort on field 2 in @array... (Larry Rosler)
    Re: numeric sort on field 2 in @array... (Larry Rosler)
    Re: numeric sort on field 2 in @array... (Larry Rosler)
    Re: numeric sort on field 2 in @array... (Abigail)
        piping a variable to an external command <cliff@scs.uiuc.edu>
    Re: RegEx for html->plain text <cassell@mail.cor.epa.gov>
    Re: Same problem for me <flavell@mail.cern.ch>
    Re: using tr? <rick.delaney@home.com>
    Re: Wrong value returned when accessing list using scal (Larry Rosler)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 30 Sep 1999 23:16:19 GMT
From: alex_rayan@my-deja.com
Subject: Bug in Perl 5.0? or something to do with RegExp
Message-Id: <7t0qvp$qmu$1@nnrp1.deja.com>

Hi friends,
   I need to call different functions or all of them according to the
mode ,the user types.
   I get the following output when I run this script!

 Calling Function 1
 Process over
------------------------------------

#! /usr/local/bin/perl

my $mode  ="a";
my $c_over =0;

if ($mode =~ /c|a/gi and $c_over==0){
   print "\n Calling Function 1";
   # do function1
   $c_over =1;
   $d_over =0;
}

if ($mode =~/d|a/gi and $d_over ==0){
  print "\n Calling Function 2";
  # do function2
  $d_over =1;
}

print "\n Process over";

Anything else I'm missing in this script ? or perl cant handle matching
like this????

Thanx


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Thu, 30 Sep 1999 16:48:02 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Bug in Perl 5.0? or something to do with RegExp
Message-Id: <MPG.125d968ed77caab698a015@nntp.hpl.hp.com>

In article <7t0qvp$qmu$1@nnrp1.deja.com> on Thu, 30 Sep 1999 23:16:19 
GMT, alex_rayan@my-deja.com <alex_rayan@my-deja.com> says...
 ...
> if ($mode =~ /c|a/gi and $c_over==0){
 ...
> if ($mode =~/d|a/gi and $d_over ==0){
 ...
> Anything else I'm missing in this script ? or perl cant handle matching
> like this????

You are very impatient indeed.  You posted essentially the same question 
twice within an hour.  Had you waited just a bit, you would have seen 
the three cogent answers that have already appeared.

Usenet isn't an instant-response help desk.  That usually costs lots of 
money.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 30 Sep 1999 23:01:05 GMT
From: lt lindley <ltl@rgsun5.viasystems.com>
Subject: Re: Bye Tom? (WAS: Re: injecting "my" varibales into callers scope)
Message-Id: <7t0q3h$g4q$1@rguxd.viasystems.com>

Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:

:>Did you ever see a constructive posting from Tom and a destructive
:>posting of Tom sent within a short amount of time?  I do not recall
:>such things happening (often?).  Mind boggles what can cause this (the
:>most vicious conjecture involves running out of medications ;-).

I haven't been around long enough to be an authority, but I did notice
*you* could set him off pretty easily.  So could challenges to his
ethics, and some pretty egregious violations of netiquette when the
perpetrator persisted in transgressing.  

Everybody has hot buttons.  

-- 
// Lee.Lindley   /// I used to think that being right was everything.
// @bigfoot.com  ///  Then I matured into the realization that getting
////////////////////   along was more important.  Except on usenet.


------------------------------

Date: 01 Oct 1999 00:18:48 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: Bye Tom? (WAS: Re: injecting "my" varibales into callers scope)
Message-Id: <37f3fde8$0$201@nntp1.ba.best.com>

Abigail <abigail@delanet.com> wrote:
> Scratchie (AgitatorsBand@yahoo.com) wrote on MMCCXXI September MCMXCIII
> in <URL:news:07NI3.72$QB2.11160@news.shore.net>:
> !! 
> !! What are you implying? That because Tom has contributed a lot of work to
> !! the perl community that we should pretend that he isn't a condescending
> !! jerk when he posts?


> You don't have to pretend that, as he isn't.

> *plonk*

Terms like "condescending jerk" tend to be subject to wildly variable
interpretation depending on the person evaluating them, but this would have
to rank up there as one of the more noteworthy examples of that.

Abigail has forgotten more about Perl, and programming, and SGML, and
any number of other important topics than I will ever learn if I live
to be 100. Her pronouncements on the more arcane technical points carry
an Old Testament authority you rarely encounter outside Charlton Heston
movies. It wasn't any accident that when Jon Orwant announced at the
last Quiz Bowl that "the next question is from Abigail," virtually the
whole audience went "oooh!" and gave a nervous laugh.

At the same time, in classic Usenet fashion, she reveals the darker
side of her personality just as transparently as she reveals her
prodigious learning when she posts stuff like this.

For someone like me, who gets a tremendous amount of enjoyment out of
the Perl-community-as-soap-opera carryings on of the more colorful
regulars around here, it's all very entertaining. I have to wonder,
though, if those who take the group's charter more seriously don't ever
get tired of her view that additions to her killfile are matters of
public interest.

Since those are probably the same people whose level of sophistication
allows them to enjoy the sigs that pass right over my head, it all
probably balances out. And as I've acknowledged before, in this
particular Animal Farm she's clearly one of the most equal animals
around, such that there probably is some justification for her belief
that she can speak on behalf of the entire group, or all of it that
matters.

Ultimately, though, on Usenet maybe more than elsewhere, we speak for
ourselves. Speaking for myself, I believe rude newbies are and will
remain a part of the landscape, for now and evermore, no matter how
harshly they are treated. Individual newcomers will be driven from the
group, certainly, but for every hydra's head you chop off two more will
sprout to take its place, and eventually the blood from all the
head-chopping will leave even the most unsympathetic to the newbie
cause wondering if this course of treatment isn't worse than the
disease itself.

The advice in news.announce.newusers cuts both ways. If you start at
the top of the Usenet Primer and work your way down, it doesn't take
long to come to a rule that, if applied impartially, would damn Abigail
no less than those she *plonks*.

In the Return of the King, Denethor would rather let himself and his
city burn than face the reality that the days he had known were gone
forever. I think there's a lot of Denethor in Abigail's bitter attitude
toward newbies.

-- 
John Callender
jbc@west.net
http://www.west.net/~jbc/


------------------------------

Date: Thu, 30 Sep 1999 17:35:53 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Bye Tom? (WAS: Re: injecting "my" varibales into callers scope)
Message-Id: <37F401E9.506F9A33@mail.cor.epa.gov>

Scratchie wrote:
> 
> Abigail <abigail@delanet.com> wrote:
[snip]
> : You don't have to pretend that, as he isn't.
> 
> Not compared to you, I guess?

Art, there's no point in arguing than _ad_hominem_ posts are
bad if you're going to resort to _ad_hominem_ posts yourself.

Or are you just trying to drive away every Perl guru here,
until this place resembles alt.perl ?  

Oops, I think that's _ad_hominem_ too.  I guess I'd better
call someone another Hitler and end this thread.  Got any
nominations?  :-)

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Thu, 30 Sep 1999 22:56:56 GMT
From: geotekjohn@my-deja.com
Subject: Re: Calling a subroutine held at one sever from another
Message-Id: <7t0pri$pqe$1@nnrp1.deja.com>

In article <Pine.GSO.4.10.9909301323450.17231-
100000@user2.teleport.com>,
  Tom Phoenix <rootbeer@redcat.com> wrote:
> On Thu, 30 Sep 1999, C. Gaunt wrote:
>
> > Is it possible to call a subroutine that is is the cgi-bin on one
> > sever from a perl script in the cgi-bin of a second server.
>
> Short answer: No, it's not possible. You probably want to download and
> install the software you need on your own server.
>
> Long answer:
>
> If it's possible at all, you'll need to use a protocol. If there
isn't one
> that already does what you want, you'll need to develop one. This
will be
> significantly more work than to download and install the software you
need
> on your own server.

However, you might not be able to get that code. You might be able to
do what you want using a script like this:

#!/usr/bin/perl -w
use strict;

use LWP::UserAgent qw(:ALL);
use HTTP::Request;
use HTTP::Response;

my $request = new HTTP::Request GET => 'http://www.yahoo.com/'; #URL
goes here

my $ua = new LWP::UserAgent;

$ua->request($request, \&callback, 4096);

print "Content-type: text/html\n\n";

sub callback
{
	print @_;
}



Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Thu, 30 Sep 1999 17:38:30 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Catching errors in anouther name space.
Message-Id: <37F40286.E4A68276@mail.cor.epa.gov>

Scott Beck wrote:
[snip of TomP's post]
> The only output from this is
> Script add.cgi
> running on Thu Sep 30 17:10:12 1999 (Perl version 5.00404)
> 
> This is probably because the script is dying in another name space, well at
> least that is my opinion but I am not sure since I have no error message to
> work with.

Then you missed Tom's point.  If you use his BEGIN block and
then scatter the usual 
    yadda(yadda,yadda) or die "Blech: $!";
kind of Perl code through your script, then you'll get error
checking which shows up on your webpage for easy viewing and
debugging.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: 30 Sep 1999 18:05:53 +0200
From: Benjamin Schweizer <SternSZ@gmx.de>
Subject: console program
Message-Id: <m3d7v0qt9a.fsf@anthrax.local.net>

Hello,

ist there a simple toolkit for the text mode? I want to make a kind of
select box...



regards
  -Benjamin

-- 
PC-Hardware HOWTO    ->     http://privt.schlund.de/SternSZ/hardware.htm


------------------------------

Date: Thu, 30 Sep 1999 17:45:17 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: console program
Message-Id: <37F4041D.BEFECD42@cisco.com>

[ Benjamin Schweizer wrote:

> ist there a simple toolkit for the text mode? I want to make a kind of
> select box...

There are several  character user interface modules available in CPAN.
Try  the perl5 extensions to Cdk.
--



------------------------------

Date: Thu, 30 Sep 1999 17:33:16 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: dates
Message-Id: <37F4014C.AC11A91D@mail.cor.epa.gov>

shrine420@my-deja.com wrote:
[snip]
> That is correct. Do I have a way to convert date into julian format in
> perl ? I have this calc where I have to use julian dates and subtract
> them to compare the result against a number. AND I do not know perl that
> well - where should I look for such a function , if at all ?

Ummm, if you try using perldoc to search the FAQ, you'll find 
your answer.  Typing 'perldoc -q julian' will direct you to
Time::JulianDay, and the way to get that module.

But Larry's underlying issue still stands.  You do *not*
need Julian Day in order to compare dates, unless you have
to compare dates against a number certified to be a true
Julian date.  But be aware that there is more than one
definition of Julian day, so direct comparison this way
can be trickier than just using the date comparison functions
in modules like Date::Manip and Date::Calc .

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Thu, 30 Sep 1999 17:29:25 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: forms and validation of strings...
Message-Id: <37F40065.9B6E2F06@mail.cor.epa.gov>

Andreas Posur wrote:
> 
> Hi Guys my name is Andreas and I am not a specialist in
> programming Perl/CGI...{not yet ;-) }.
> Does somebody know how I functionalize a simple string
> condition in a form???
> this can't be so heavy...

I think you'll want to look at the CGI.pm module, and
read through the documentation which comes with it.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Thu, 30 Sep 1999 17:24:36 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Hashes w/multiple values per key (Perl Cookbook) <REPOST>
Message-Id: <37F3FF44.B4AD2789@mail.cor.epa.gov>

Deb wrote:
[snip]
> to a file.  The file has lines meeting this regexp /^-*C/ & would be the
> key for the following lines (or values), until, but not including the
> next
> /^-*C/ line, which would be the next key.  What would I need to do to
> get
> this to work?  I thought of splitting on the /^--*C/, but I'd loose the
> header line, then.  <sigh>
[snip]

Have you considered using a zero-width assertion as your pattern
here?  Instead of using /^-*C/ you could use something like /^(?=-*C)/
so it wouldn't gobble up the first part of your line.

Although there doesn't seem to be anything else in your example
data which starts with a '-'.  So you could split on /^--/ and
just lose two unneeded hyphens...

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Thu, 30 Sep 1999 17:04:15 -0500
From: Steve Powell <spowell@usurf.com>
Subject: Re: Help with this Crazy script!
Message-Id: <37F3DE5F.E46405BE@usurf.com>

alex_rayan@my-deja.com wrote:
> 
> Hi friends,
>    Can anybody help me with the following script? Its not printing 2
> verfied messages!!!
> 
> my $y ="z";
> 
> if ($y =~ /z/gi){
>    print "\nVerified 1";
> }
> 
> if ($y =~/a|z/gi){
>    print "\nVerified 2 ";
> }
> 
> print "\n End";
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.



my $y ="z";
 
if ($y =~ /z/gi){
   print "\nVerified 1";
}
 
if ($y =~ /a|z/i){
   print "\nVerified 2";
 
}
print "\n End\n";

OR
#!/usr/bin/perl -w
 
my $y ="z";
 
if ($y =~ /z/gi){
   print "\nVerified 1";
}
 
$y ="z";
 
if ($y =~ /a|z/gi){
   print "\nVerified 2";
 
}
print "\n End\n";



But I am just a total amateur. There is probably a better way.

Steve Powell


------------------------------

Date: 30 Sep 1999 16:19:12 -0700
From: Jim Traugott <jtraug@seanet.com>
Subject: Re: Help with this Crazy script!
Message-Id: <ubtak9edr.fsf@seanet.com>


From perlop:
             In a scalar context, m//g iterates through the
             string, returning TRUE each time it matches, and
             FALSE when it eventually runs out of matches.  (In
             other words, it remembers where it left off last
             time and restarts the search at that point.  You can
             actually find the current match position of a string
             using the pos() function--see the perlfunc manpage.)
             If you modify the string in any way, the match
             position is reset to the beginning. 


>>>>> "alex" == alex rayan <alex_rayan@my-deja.com> writes:

    > Hi friends,
    >    Can anybody help me with the following script? Its not printing 2
    > verfied messages!!!

    > my $y ="z";

    > if ($y =~ /z/gi){
    >    print "\nVerified 1";
    > }
pos $y = 0;
    > if ($y =~/a|z/gi){
    >    print "\nVerified 2 ";
    > }

    > print "\n End";

HTH

jim



    > Sent via Deja.com http://www.deja.com/
    > Before you buy.


------------------------------

Date: 30 Sep 1999 23:19:27 GMT
From: lt lindley <ltl@rgsun5.viasystems.com>
Subject: Re: Help with this Crazy script!
Message-Id: <7t0r5v$ges$1@rguxd.viasystems.com>

alex_rayan@my-deja.com wrote:
:>   Can anybody help me with the following script? Its not printing 2
:>verfied messages!!!

:>my $y ="z";

:>if ($y =~ /z/gi){
:>   print "\nVerified 1";
:>}

:>if ($y =~/a|z/gi){
:>   print "\nVerified 2 ";
:>}

:>print "\n End";

Why are you using the /g modifier?  After a succesful match, pos()
is not reset (nor after an unsuccesful match if you add a /c modifier).
This allows chaining matches.  If you aren't trying to chain the matches
together, they why are you using /g in scalar context?

The following from "perldoc perlop" explains it better:
             In scalar context, each execution of m//g finds the
             next match, returning TRUE if it matches, and FALSE
             if there is no further match.  The position after
             the last match can be read or set using the pos()
             function; see the pos entry in the perlfunc manpage.
             A failed match normally resets the search position
             to the beginning of the string, but you can avoid
             that by adding the /c modifier (e.g. m//gc).
             Modifying the target string also resets the search
             position.

It doesn't say specifically that the next match with a /g will
start looking where the last one left off, but the rest of the
explanation in perlop about chaining them together leads you to
that understanding.

If you want to see it in operation, add the following to the beginning
of your test script:

use re 'debugcolor';

then change the line
my $y = "z" 
to
my $y = "zaz"

and run it again.

-- 
// Lee.Lindley   /// I used to think that being right was everything.
// @bigfoot.com  ///  Then I matured into the realization that getting
////////////////////   along was more important.  Except on usenet.


------------------------------

Date: Fri, 01 Oct 1999 00:01:24 +0000
From: Michael Dartt <jedin@twistedmatrix.com>
Subject: Help: Subroutines in Perl
Message-Id: <37F3F9D4.470B8DCC@twistedmatrix.com>

I'm trying to write three functions for use w/lists.  Here're the rough
prototypes.

numIsIn(array, num); #Returns true if the number's in the given array
strIsIn(array, num); #Returns true if the string's in the given array
randomThing(array); #returns a randomly-selected thing (array, scalar,
whatever) from the given array

Unfortunately, I haven't been able to glean much from the BCB or the man
pages :-(.  I have three main questions:

1) How do I pass an array to a subroutine?
2) How do I get the arguments into local variables?
3) How do I return an array from a function?

Here's some code I've tried:

# Returns true if the given num is in the given list
sub numIsIn (\@$) {
  my @array = $_[0];
  my $num = $_[1];
  
  foreach $thing (@array) {
    if ($thing == $num) { return 1; }
    return 0;
  }
}


#Returns true if the given string is in the given list
sub strIsIn (\@$) {
  my @array = $_[0];
  my $str = $_[1];

  foreach $thing (@array) {
    print "$thing\t";
    if ($thing eq $str) { return 1; }
    return 0;
  }
}

--------

And this is some test code:

if (strIsIn(\@ARGV, "bob")) {
  print "It's there!\n";
}
else { print "Not there. \n"; }

------------

Thanks in advance for any advice you can give.


--Mike


------------------------------

Date: Thu, 30 Sep 1999 17:33:11 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Help: Subroutines in Perl
Message-Id: <37F40147.D78DF720@cisco.com>

[ Michael Dartt wrote:

> 1) How do I pass an array to a subroutine?

Pass a reference to it

> Here's some code I've tried:
> # Returns true if the given num is in the given list
> sub numIsIn (\@$) {
>   my @array = $_[0];

Derefernce $_[0]  like this : my @array = @$_[0] ;

>   my $num = $_[1];
>   foreach $thing (@array) {
>     if ($thing == $num) { return 1; }
>     return 0;
>   }
> }
>
> #Returns true if the given string is in the given list
> sub strIsIn (\@$) {
>   my @array = $_[0];

Dereferencing required here: my @array = @$_[0] ;

>   my $str = $_[1];
>   foreach $thing (@array) {
>     print "$thing\t";
>     if ($thing eq $str) { return 1; }
>     return 0;
>   }
> }
>

Instead of making a local copy of the array inside your subs
you can just use the passed ref to the array to walk through it.

eg. foreach  $thing ( @$_[0] ) {
}
--



------------------------------

Date: Thu, 30 Sep 1999 17:28:35 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: newbie: preload .wav files question
Message-Id: <37F40033.E6AFABDD@mail.cor.epa.gov>

sophieloo@my-deja.com wrote:
> 
> I am new to perl and cgi
[snip]

So you may not yet know that there is a serious difference
between the two.  Let me help.  Your question is about getting
some CGI stuff done, without code in place to do the task.
That makes it much more of a CGI thingy than a Perl thingy.
So you'll probably get a better answer in
comp.infosystems.www.authoring.cgi than here.  If there is
an answer using Perl, someone there should be able to help.
If there is not, someone there will be able to tell you so,
and re-direct you to a more useful tool.

> ...am trying to preload .wav files onto a page.
[snip]

Do you need to do this to shorten load time of the page?
Then this may be more of a server issue than a language
issue.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Thu, 30 Sep 1999 16:27:33 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <MPG.125d91bbc4a38fe598a012@nntp.hpl.hp.com>

In article <x7g0zwuhz8.fsf@home.sysarch.com> on 30 Sep 1999 18:55:55 -
0400, Uri Guttman <uri@sysarch.com> says...

 ...

> i think you want something like this:
> 
> 	map  { [ $_, uc( (/\d+\s*(\S+)/)[0] ) ] } @array;

Well, sure.  But what has his second post to do with his first post?

> In article <37f3badd$0$229@nntp1.ba.best.com> on 30 Sep 1999 19:32:45 GMT,
> shiloh@shell9.ba.best.com <shiloh@shell9.ba.best.com> says...

 ...

> I want to do a numeric sort only on field 2 of an @array.
> 
> Here is the data file:

> fred 2
> wilma 3 
> larry 5
> tom 4
> barney 1
> betty 1

  	map  { [ $_, /(\d+)$/ ] } @array;

as I posted in a companion subthread.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Thu, 30 Sep 1999 16:33:24 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <MPG.125d931b67db7cc998a013@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <37F3EB6E.465E17D5@mail.cor.epa.gov> on Thu, 30 Sep 1999 
15:59:58 -0700, David Cassell <cassell@mail.cor.epa.gov> says...
> Dr. John Griffiths wrote:
> > rather than using built-in sort I write the array to a file,
> > pass it to bin/sort, and read it back in - its fast and
> > easy.
> 
> If I may say...  Ick.  You write to a file, open a shell and
> run another program, then read a file back in?  Seems a lot
> harder than sort(), and a *lot* slower.  I guess it won't make
> any difference with a small file.  But some people here
> regularly manipulate files more than a Gig in size.

Odd that you should talk about sorting 'Gig-size' files, because there 
Dr. John Griffiths is actually right!

/bin/sort will sort input until its RAM allotment, and spew intermediate 
sorted data onto temp files, then read them back doing an efficient 
merge-sort and write them out sequentially.  Perl will thrash the RAM 
beyond usability.  In a case like that, the process-spawning overhead 
and extra I/O is well worthwhile.

See the brief discussion of external sorts in our paper, 
http://www.hpl.hp.com/personal/Larry_Rosler/sort/

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Thu, 30 Sep 1999 16:41:51 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <MPG.125d951dec16f5db98a014@nntp.hpl.hp.com>

In article <37F3E3A7.E970A7FC@texas.net> on Thu, 30 Sep 1999 17:26:47 -
0500, Tom Briles <sariq@texas.net> says...
> "Dr. John Griffiths" wrote:
> > 
> > rather than using built-in sort I write the array to a file,
> > pass it to bin/sort, and read it back in - its fast and
> > easy.
> 
> You have the strangest notion of 'fast and easy' upon which I have ever
> stumbled...
> 
> To quote Abigail, et. al.:
> 
> *boggle*

If you like *boggle*, glom Dr. John Griffiths's website, posted in his 
 .sig: http://www.sni.net/~grifftoe/

The home page has absolutely the most irritating animated GIF I have 
ever seen, and I have seen plenty; the general clutter is, well, mind-
boggling.

I haven't found any Perl code to trash^H^H^H^H^Hevaluate, though.  Perl 
is mentioned, but no code is posted.

Larry Rosler

Oops --

Dr. Lawrence Rosler

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 30 Sep 1999 19:52:09 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <slrn7v81tn.8i.abigail@alexandra.delanet.com>

David Cassell (cassell@mail.cor.epa.gov) wrote on MMCCXXI September
MCMXCIII in <URL:news:37F3EB6E.465E17D5@mail.cor.epa.gov>:
!! 
!! If I may say...  Ick.  You write to a file, open a shell and
!! run another program, then read a file back in?  Seems a lot
!! harder than sort(), and a *lot* slower.  I guess it won't make
!! any difference with a small file.  But some people here
!! regularly manipulate files more than a Gig in size.

Uhm, I wouldn't be surprised then when you get into the gig size
range, /bin/sort will be faster than Perl sort. AFAIK, /bin/sort
is optimized for sorting large files. And with Perl's memory overhead,
/bin/sort is going to use an awful lot less memory than Perl.

In fact, many implementations of /bin/sort can sort files way larger
than the virtual memory of a system. Perls internal sort can't (unless
of course you write a very complicated sort sub).



Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


  -----------== 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: Thu, 30 Sep 1999 18:51:37 -0500
From: Clifford Meece <cliff@scs.uiuc.edu>
Subject: piping a variable to an external command
Message-Id: <37F3F789.F929B845@scs.uiuc.edu>

I have a program that I need to pipe input to, and on the command line I
would do something like:

shell>cat inputFile | program

Now in my perl script, I have the entire input file in a variable,
$input.  How do I pipe that to the external program?

I should also say that this is a cgi program, and I don't want to create
any temporary files.  I have tried opening the program like
open(PROGRAM, "|progam")
and then just printing to that file handle, but it doesn't seem to work.

Any suggestions?
-- 
===============================================================
Cliff Meece                      \\ Phone: (217) 333-1728
Unix Systems Administrator       \\ Email: cliff@scs.uiuc.edu 
School of Chemical Sciences      \\ 153 Noyes Lab    
University of Illinois           \\
===============================================================


------------------------------

Date: Thu, 30 Sep 1999 17:39:45 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: RegEx for html->plain text
Message-Id: <37F402D1.ABF02C3B@mail.cor.epa.gov>

Seth David Johnson wrote:
[snip]
> Not to be down on Perl, but is there any reason you're not simply using
> lynx with the -dump option?

Doesn't sound like you're down on Perl to me.  This technique
has been suggested here by a large number of people, including
a few you might think would be ready to roast you.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Fri, 1 Oct 1999 01:01:30 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Same problem for me
Message-Id: <Pine.HPP.3.95a.991001005921.423A-100000@hpplus01.cern.ch>

On Sat, 25 Sep 1999, Johan Stjernbecker wrote:

> Hi Andrew!
> 
> I have the same problem. If you find out how to do, please e-mail me!

Gosh, I haven't seen one of those for ages.  I suppose it's pointless to
ask you to put yourself in our position, and work out just how useful
that contribution was to the worldwide usenet community.
[jeopardendum excised - is that a jeopardectomy?]



------------------------------

Date: Fri, 01 Oct 1999 00:02:06 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: using tr?
Message-Id: <37F3FA03.918AF5F7@home.com>

[posted & mailed]

Abigail wrote:
> 
> Uri Guttman (uri@sysarch.com) wrote on MMCCXXI September MCMXCIII in
> <URL:news:x7ogekuwoa.fsf@home.sysarch.com>:
> ()
> () please select the next category and question.
> 
> $400 in world capitals please.

Please desist from your Jeopardy style posts. 

-- 
Rick Delaney
rick.delaney@home.com


------------------------------

Date: Thu, 30 Sep 1999 17:30:07 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Wrong value returned when accessing list using scalar variable?
Message-Id: <MPG.125da06c5cb3de0d98a016@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7t0mcn$n9b$1@nnrp1.deja.com> on Thu, 30 Sep 1999 21:57:50 
GMT, geotekjohn@my-deja.com <geotekjohn@my-deja.com> says...
> I'm trying to get the value of a particular item in a list using a
> straightforward $mylist[$myindex] syntax. I have 2 lists set up (to
> simulate rows and columns in a table), and given a cell number, I try
> to figure out the row and column for that cell, and then print the
> value for that cell.
> 
> But I sometimes get the wrong value when I use a scalar variable as an
> index to one of the lists. Here's the code:
> 
> #!/usr/bin/perl -w
> use strict;
> use diagnostics;
> 
> =pod
> 
> I'm trying to convert a cell number (1 .. n, where n is the # of cells
> in the table) to a 0-based row and column index.
> 
> =cut

A super start -- lots of help for the programmer and the reader.

> my @row_values=qw(row0 row1);
> my @col_values=qw(col0 col1 col2);
> $\ = "\n";
> 
> for (my $cell_number = 1; $cell_number <= 6; $cell_number++)

More Perlish than C:

  for my $cell_number (1 .. 6)

> {
> 	#temp variables and and b help clean up some of the code below
> 	my $a = $cell_number - 1;
> 	my $b = @col_values;
> 
> 	#The row index is a div b
> 	my $row_index = int($a / $b);
> 	my $col_index;
> 
> 	#	$col_index = a mod b  Since there is no MOD function in
> perl, I implemented one myself.

Here you have gone off the tracks completely.

First, posting long comments doesn't do to well on Usenet, because of 
line wrapping.  Someone who wanted to copy-and-paste your code to try it 
out would have to edit this problem away (as I did).

Second, you have overlooked the following in perlop:

Multiplicative Operators

 ...

Binary ``%'' computes the modulus of two numbers. 

> 	if (($a/$b) < 1)
> 	{
> 		$col_index = $a;
> 	}
> 	else
> 	{
> 	#	print "a = $a \t b = $b";
> 		$col_index = abs((int ($a/$b) - ($a/$b)) * $b);
> 	}

 ...

> Row index = 1    Col index = 1
> &RowValue=row1&ColumnValue=col0  <--- Why is this col0 ?? Should be col1

Try at this point

    printf '%.20f' => $col_index;

On my machine, it is:

    0.999999999999999780001

Which becomes 0 when used as an index.  Isn't floating-point arithmetic 
a bitch?

It works fine if one replaces your computation by:

    $col_index = %a % $b;

BUT:  Why are you not using a two-dimensional array in the first place?  
It is easy and natural for your problem.

perldoc perllol
perldoc perldsc

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

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 958
*************************************


home help back first fref pref prev next nref lref last post