[17377] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4799 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 2 21:05:50 2000

Date: Thu, 2 Nov 2000 18:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973217110-v9-i4799@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 2 Nov 2000     Volume: 9 Number: 4799

Today's topics:
    Re: 1+(-1)=? can be 0 or 2, depending on context <ren.maddox@tivoli.com>
    Re: 1+(-1)=? can be 0 or 2, depending on context <joe+usenet@sunstarsys.com>
    Re: Alternative for server-push animation. <graham@coms.com>
    Re: Beginner help with code <ren.maddox@tivoli.com>
    Re: Communicating with a child process <tim@ipac.caltech.edu>
    Re: Do I need eval? <ren.maddox@tivoli.com>
    Re: Do I need eval? <ren.maddox@tivoli.com>
    Re: Duplicate lInes in File count and del routine <tim@ipac.caltech.edu>
    Re: Duplicate lInes in File count and del routine <ren.maddox@tivoli.com>
    Re: embedded variables in a file <m.nine.six@freesurf.ch>
    Re: embedded variables in a file (Tad McClellan)
    Re: Format Arrays ? Please assist <ren.maddox@tivoli.com>
    Re: indirect sub call with strict (Martien Verbruggen)
    Re: Is there a way to get all PID's within Perl ? <montuori@arrakisplanet.com>
    Re: Is there a way to get all PID's within Perl ? (John Stanley)
    Re: Is there a way to get all PID's within Perl ? (Tom Christiansen)
    Re: My brain hurts: another regex Q. <ren.maddox@tivoli.com>
        my giant hash <mcdonabNO@SPAMyahoo.com>
    Re: my giant hash (Tad McClellan)
    Re: my giant hash <mcdonabNO@SPAMyahoo.com>
    Re: Need suggestions on optimization MSherrill@compuserve.com
    Re: OT: Yes there _are_ stupid questions.  Anyone colle <rick.delaney@home.com>
    Re: pattern matching across two lines <chaotrope@jps.net>
    Re: Perl compiler robert_maul@my-deja.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 02 Nov 2000 16:04:53 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: 1+(-1)=? can be 0 or 2, depending on context
Message-Id: <m3n1fi114q.fsf@dhcp11-177.support.tivoli.com>

Joe Schaefer <joe+usenet@sunstarsys.com> writes:

> Ren Maddox <ren.maddox@tivoli.com> writes:
> 
> > Helmut.Richter@lrz-muenchen.de (Helmut Richter) writes:
> > 
> > > The output of the entire program is:
> 
> [...]
> 
> > Not for me.  I get:
> > 
> > +++++old: coeff{i}=
> > +++++coe=+1, coeff{i}=1
> > +++++old: coeff{i}=1
> > +++++coe=-1, coeff{i}=0
> > +++++old: coeff{i}=
> > +++++coe=+1, coeff{i}=1
> > +++++old: coeff{i}=1
> > +++++coe=-1, coeff{i}=0
> > 
> 
> Out of pure curiosity, what version of perl produced such an output?

This is perl, v5.6.0 built for i686-linux-thread-multi

> > I have no idea why you and I get different output.  It may seem silly,
> > but try cut-and-pasting from your own article to make sure you still
> > get the same behavior.
> 
> Sheesh !

What?  I said it was silly.  But I've seen it happen before that the
code posted was not actually the same as the code run.  Sometimes it's
something silly, like a missing command line option or something.  It
was really just intended as a sanity check.  If I had been the OP and
someone had replied saying that my code works for them, one of the
first things I would do would be to cut-and-paste my own code from the
article and make sure I really get the behavior I thought I did.  Of
course, I would have done this before posting, but you never really
know for sure unless you try.  For example, perhaps when the article
was posted an extra newline got inserted in a non-white-space friendly
place in the code.  That could certainly change the behavior.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 02 Nov 2000 20:07:07 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: 1+(-1)=? can be 0 or 2, depending on context
Message-Id: <m3r94tx3r8.fsf@mumonkan.sunstarsys.com>

Ren Maddox <ren.maddox@tivoli.com> writes:

> This is perl, v5.6.0 built for i686-linux-thread-multi
> 
> > > I have no idea why you and I get different output.  It may seem silly,
> > > but try cut-and-pasting from your own article to make sure you still
> > > get the same behavior.
> > 
> > Sheesh !
> 
> What?  I said it was silly.  But I've seen it happen before that the
> code posted was not actually the same as the code run.  Sometimes it's
> something silly, like a missing command line option or something.  It
> was really just intended as a sanity check.  If I had been the OP and
> someone had replied saying that my code works for them, one of the
> first things I would do would be to cut-and-paste my own code from the
> article and make sure I really get the behavior I thought I did.  Of
> course, I would have done this before posting, but you never really
> know for sure unless you try.  For example, perhaps when the article
> was posted an extra newline got inserted in a non-white-space friendly
> place in the code.  That could certainly change the behavior.

Ok, sorry- I see your point.  I do think he's found a bug in *his* perl
compiler, but it's probably not showing up in yours.  Try testing
the output of this code snippet and see what you get:

---------------------
#! /usr/bin/perl -w

my $coe = 1;
$coe = "-$coe";

print "String: $coe\n";
print "Numeric: ", $coe+0, "\n";
--------------------

On linux 5.005_03, here's my output:

String: -1
Numeric: -1

On 5.6, I get:

String: -1
Numeric: 1

% perl -v

This is perl, v5.6.0 built for i586-linux


My 5.6 is a few months old, so this issue might have 
been resolved in your version.


--- guess as to what the problem is follows ---

Perl maintains two internal representations of a string 
variable: a numeric version, and, well, a string version.  

My 5.6 seems to be confused about the numeric value of "-$coe";
it seems to have something with the interpolation of $coe here,
since 

---------------------
#! /usr/bin/perl -w

my $coe = 1;
$coe = "-1";

print "String: $coe\n";
print "Numeric: ", $coe+0, "\n";
--------------------

outputs (on 5.6)

String: -1
Numeric: -1

Is there any mention of such a problem in your changelogs?

-- 
Joe Schaefer


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

Date: Thu, 02 Nov 2000 23:48:30 +0000
From: "Graham Ashton" <graham@coms.com>
Subject: Re: Alternative for server-push animation.
Message-Id: <A4nM5.1031$L14.4104@news.colt.net>

In article <8tre20$qv8$2@news.tpi.pl>, "Maciej Gabryelski"
<m.gabryelski@psi-net.pl> wrote:

> 1.) Is this possible that server-push will work in all browsers ( if
> yes, how to do that ).

Not as far as I know, but I'm no expert.

> 2.) Is there alternative CGI technology for making animations ( I have
> heard about client-pull but I couldn't find any manuals, documentation
> or examples of it).

You can use an HTML meta tag, like this (stick it in the <head>..</head>
section of your page):

  <meta HTTP-EQUIV="Refresh" CONTENT="5;URL=http://foo/bar.html">

After 5 seconds the browser should load http://foo/bar.html.

--
graham


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

Date: 02 Nov 2000 16:22:46 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Beginner help with code
Message-Id: <m366m610ax.fsf@dhcp11-177.support.tivoli.com>

[Please place your comments after the text you are quoting as I have
rearranged it.]

Michael Segulja <michael.segulja@sgi-lsi.com> writes:

> In article <8ts80o$d3g$1@nnrp1.deja.com>,
>   Dick Latshaw <latsharj@my-deja.com> wrote:
> > In article <8ts1dt$6qv$1@nnrp1.deja.com>,
> >   Michael Segulja <michael.segulja@sgi-lsi.com> wrote:
> >
> > > I query the main table (mp3main) on artist.  This returns a list of
> > > all the artists if I print this out to STDOUT.  However, they are
> > > listed multiple times, so I then want to take those artists and
> > > insert them into a temporary table with a UNIQUE INDEX so duplicates
> > > will not be inserted.
> >
> > > my $statement = "SELECT artist FROM mp3main";
> > Try 'SELECT DISTINCT artist FROM mp3main'
> >
> Thanks so much for the help.  That cuts out a lot of work.  One thing
> I'm wondering about... This returns exactly what I need, but I guess
> since it is returning the array, it just outputs each artist on the
> smae line separated by a space.  Ultimately, I want to output each
> artist into a table vertically on a web page so that I can make it
> formatted and look nice and neat.  i.e.  [artist 1]

By itself, it doesn't output anything.  That depends on what you do
with the results.  You didn't show the new code, so I'm not sure what
you are doing, but a guess would be something like:

   print "@array";

when you want something more like:

   print "$_\n" for @array;

> I guess what I need to do find each row one at a time and output it,
> then go and get the second row and output it, etc.  I guess I might
> need to use some sort of fetchrow_array but I can't figure out what.  I
> can get it to output one at a time line by line, but it comes out
> looking like this:  hash[043kd82jsu].

Not sure where you are getting a hash reference from.  Let's see your
code.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 02 Nov 2000 16:21:58 -0800
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Communicating with a child process
Message-Id: <3A020526.CA9AE9E8@ipac.caltech.edu>

Sean McAfee wrote:
> 
> This seems like it should be an elementary problem in IPC, but I just can't
> seem to come up with a (simple) solution.  Argh!
> 
> In essence, my problem is this.  I fork a child process to act as a filter
> by prepending all of its input lines with the line number:
[code snipped ...] 
> Now I want to change the code so that I can reset the line counter in
> the child process from the parent process:
> 
> print PIPE "foo\nbar\nbaz\n";     # prints "1 foo", "2 bar", "3 baz"
> # (do something)
> print PIPE "baz\nbletch\nquux\n"; # prints "1 baz", "2 bletch", "3 quux"
> 
> Is this possible?  If so, how?  Every approach I've tried rapidly becomes
> more complicated than my original solution (using a tied filehandle).

Why not make "(do something)" do this:

print "<<<RESET COUNTER>>>\n";

and add a line like this to the child:

$line = 0 if /^<<<RESET COUNTER>>>$/;

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: 02 Nov 2000 16:12:19 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Do I need eval?
Message-Id: <m3itq610sc.fsf@dhcp11-177.support.tivoli.com>

jack.dunnigan@ec.gc.ca writes:

> In article <slrn902om5.nbb.trammell@nitz.hep.umn.edu>,
>   trammell@nitz.hep.umn.edu (John J. Trammell) wrote:
> > On Thu, 02 Nov 2000 20:00:16 GMT, jack.dunnigan@ec.gc.ca
> > <jack.dunnigan@ec.gc.ca> wrote:
> > >I have an array for which some of the elements hold a keyword and a
> > >directory structure like so..
> > >
> > >eq/ one element of the array might be..
> > >Reception_Group_Definition = /users/goesadm/db/pdg/somefile
> > >
> > >another might be..
> > >Band4_Product = /disk1/goes_im/products/anotherfile
> > >
> > >Is there an elegant way to grep the array and somehow 'eval' to set a
> > >variable of the same keyword in my perlscript.
> >
> > It is possible, but it is the wrong approach.  See
> >
> >   http://www.plover.com/~mjd/perl/varvarname.html
> >
> > for a concise explanation, and the "right" answer.
> 
> Understood. So how would one just parse the directory (in one line) so I
> can store it to a hash?
> 
> ...I'm thinking of something like this..
> $hash{uniquekeyname} = (split("=",(grep/$_/,@array)))[1];
> 
> but it doesn't seem to work.

my %hash = map split(/\s*=\s*/, $_), @array;

-- 
Ren Maddox
ren@tivoli.com


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

Date: 02 Nov 2000 16:18:19 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Do I need eval?
Message-Id: <m3aebi10ic.fsf@dhcp11-177.support.tivoli.com>

Ren Maddox <ren.maddox@tivoli.com> writes:

> my %hash = map split(/\s*=\s*/, $_), @array;

Silly me... (well, it does work):

  my %hash = map { split /\s*=\s*/ } @array;

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 02 Nov 2000 17:03:13 -0800
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Duplicate lInes in File count and del routine
Message-Id: <3A020ED1.8F0C34F9@ipac.caltech.edu>

jkipp@mbna.com wrote:
> 
> Myself and another admin are workin on the following script ( I will
> only post the routines I have the question on). The part of the script
> That I am dealing with here parses a file generated by another script.
> The file will have lines with one IP address on each line. It then
> makes a new file after it is done doing stuff to the file fed to it.
> here is the sub that takes the file and passes to another routine :

I hope you'll permit a few comments not directly related to your stated problem.

> ---------------
> elsif (defined($opts{f} && $opts{l})) {
>         my $file = $opts{f};
>         my $log  = $opts{l};
>         pfile_log(\$file, \$log);

Why are you passing references? No problem, I guess, just wondering.

> --------------
> the file is passed to another routine that parses the file and and pairs
> the IP adr with a hostname
> ---------------
> sub pfile_log {
>         my ($file, $log) = @_;
> 
>         open(FILE, "$$file") or die "Can't open $$file:$!" if -e $$file;

So what happens if the file doesn't exist? The following lines roll relentlessly
on, producing garbage. Perhaps you meant something like

return if ! -e $$file;
open(FILE, "$$file") or die ...

???

>         my @file = <FILE>;
>         close FILE or die "Can't close $$file:$!";

I admire your zealousness about including the 'or die' clause on the close, but
really the test you want to perform is on @file, unless it's allowed to be
empty;

warn("File $$file empty.\n"),return unless @file;

>         open(LOG, ">$$log") or die "Can't open $$log for writing:$!";
>         foreach (@file) {

Why slurp in the whole file? Why not use a

while(<FILE>) {

structure. Then you don't ever have to care about how big the file gets.

>                 chomp;
>                 if (/( \d{1,3} \. \d{1,3} \. \d{1,3} \. \d{1,3}  )/gx){

What's the 'g' there for?

> 
>                  my $name = gethostbyaddr(inet_aton($1), AF_INET);
>                  print LOG "$name => ",$1, "\n";
>                 } else {
>                         next;
>                 }
>                 next;

Perhaps I'm being overly picky, but the 'next's aren't necessary.

>         }
> -----------------
> Here is what we need it to now do.
> Read each line in the result log file(ip/hostname combo) if we find a
> dup line start counter at 2 and delete the dup line
>         if find again add 1 to count
>                 delete the dup line
> do until EOF
> print non dup lines just as "Ip -> Host"
> print dup lines "ip -> host" x "times"

Here's a solution to use if you know the list won't get too big (untested):

my @table;
my %counter;
while(<LOG>) {
  my ($name,$ip) = split /\s*=>\s*/;
  push @table,[$name,$ip] if ! $counter{$name}++;
}

for (@table) {
  print "$ip -> $host".
        ($counter{$name} > 1 ? " x $counter{$name}" : "").
        "\n";
}

Is that what you meant? Or did you mean

print "$ip -> $host\n"x$counter{$name};

?

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: 02 Nov 2000 16:51:21 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Duplicate lInes in File count and del routine
Message-Id: <m3snpayoly.fsf@dhcp11-177.support.tivoli.com>

jkipp@mbna.com writes:

> Here is what we need it to now do.
> Read each line in the result log file(ip/hostname combo) if we find a
> dup line start counter at 2 and delete the dup line
> 	if find again add 1 to count
> 		delete the dup line
> do until EOF
> print non dup lines just as "Ip -> Host"

Do you really mean to reverse the order?  The previous code (which I
did not include) printed "Host -> IP".

> print dup lines "ip -> host" x "times"

my %line_count;
my @lines;            # only needed if order matters

open FILE, $file or die "Could not open $file, $!";
while (<FILE>) {
  chomp;
  $line_count{$_}++;
  push(@lines, $_);   # I'm saving the order here.
}
close FILE;

foreach (@lines) {    # If order isn't important, use "keys %line"
  print;
  print " $line_count{$_} times" if $line_count{$_} > 1;
  print "\n";
}
__END__

-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 03 Nov 2000 00:16:45 +0100
From: "m.nine.six" <m.nine.six@freesurf.ch>
To: Tad McClellan <tadmc@metronet.com>
Subject: Re: embedded variables in a file
Message-Id: <3A01F5DD.1CDAF9B5@freesurf.ch>

Tad McClellan wrote:
> 
> On Thu, 02 Nov 2000 13:27:05 +0100, m.nine.six <m.nine.six@freesurf.ch> wrote:
> 
> >i have some vars embedded in the text file i wishes to read... and when
> >i print the contents, those vars are just printing as $var, rather than
> >the contents of $var...
> 
> You seem to be missing the distinction between what is code
> and what is data.
> 
> Perl FAQ, part 4:
> 
>    "How can I expand variables in text strings?"

this faq suggests me that i should use regex matching. and i thinks
that's not the best way to do this.

anyway i found a way and i have the opinion that this should go into
this faq. it's a better way.

$home = '/home/user';
$line = '$home/template';

$line = eval "qq/$line/";
print $line;


this will work and print the $line as "/home/user/template";



> 
> --
>     Tad McClellan                          SGML consulting
>     tadmc@metronet.com                     Perl programming
>     Fort Worth, Texas

-- 
bye,
alias m.nine.six.


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

Date: Thu, 2 Nov 2000 18:22:00 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: embedded variables in a file
Message-Id: <slrn903too.gjr.tadmc@magna.metronet.com>

On Fri, 03 Nov 2000 00:16:45 +0100, m.nine.six <m.nine.six@freesurf.ch> wrote:
>Tad McClellan wrote:
>> 
>> On Thu, 02 Nov 2000 13:27:05 +0100, m.nine.six <m.nine.six@freesurf.ch> wrote:
>> 
>> >i have some vars embedded in the text file i wishes to read... and when
>> >i print the contents, those vars are just printing as $var, rather than
>> >the contents of $var...
>> 
>> You seem to be missing the distinction between what is code
>> and what is data.
>> 
>> Perl FAQ, part 4:
>> 
>>    "How can I expand variables in text strings?"
>
>this faq suggests me that i should use regex matching. and i thinks
>that's not the best way to do this.


OK, perhaps.

But you can't just say "not the best way" without justifying it
somehow.

What is not good about it?

What is good about your proposed alternative?


>anyway i found a way and i have the opinion that this should go into
>this faq. 


Never in a hundred million years should that go in the FAQ.


>it's a better way.


No it isn't.

What is "better" about it?


>$home = '/home/user';
>$line = '$home/template';
>
>$line = eval "qq/$line/";


String eval is very very dangerous.

Won't matter in your particular example above, because everything
is hard coded into the program itself. No way for a cracker to
sneak in.

In the general case though, it may open the door for a cracker.

Go ahead and use it, maybe we'll hear about you on the 6 o'clock news...


>this will work and print the $line as "/home/user/template";


"will work" does not imply "better".



Give a reason or two for your assertions please.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 02 Nov 2000 16:26:21 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Format Arrays ? Please assist
Message-Id: <m31ywu104y.fsf@dhcp11-177.support.tivoli.com>

msalerno@my-deja.com writes:

> In article <8tsjvh$ohf$1@nnrp1.deja.com>,
>   msalerno@my-deja.com wrote:
> > I am working on a script and I would like to search through the PID's
> > of a system (for another purpose).  The only problem that I am having
> > is that the output has some extra spaces.  The first line of the
> output
> > starts with no spaces, but after the first line everything is
> indented.
> > I looked at the perldoc -q space but it doesn't do a thing.  Please
> let
> > me know what I am missing.

You mean you read the FAQ entitled "Why do I get weird spaces when I
print an array of lines?" but it didn't answer your question?  That's
odd, since it does.  Or do you mean that "perldoc -q space" did not
work for you?

> That part of the previous message that reads, the script returns: is
> incorrect, there really is an extra space placed on the left of all
> lines except the first.  I found out that adding
> my $test = join '' => @fin;
> and then printing @test works fine !

As the FAQ states, if you place an array inside of double-quotes, it
is expanded with spaces (strangely it doesn't mention $" in the FAQ).

In any event, the answer to your query is to leave out the quotes
around @test.
   
-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 03 Nov 2000 00:47:14 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: indirect sub call with strict
Message-Id: <slrn9042oj.l2.mgjv@verbruggen.comdyn.com.au>

On Thu, 02 Nov 2000 19:56:17 GMT,
	Mark-Jason Dominus <mjd@plover.com> wrote:
> In article <slrn8vqp2v.ac5.mgjv@martien.heliotrope.home>,
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> >> Thanks for the tip, Nick.  But with your code I still get:
> >>    syntax error at ./test_subcall.pl line 9, near "->("
> >
> >it runs fine. 
> 
> Perhaps the original poster is running Perl 5.003 and you are not.

I am most certainly not running a 4 year old Perl. How can you even
think I would! :)

If the poster is running a 5.003 Perl, they should probably upgrade. A
lot of the code produced nowadays won't run on 5.003, or even 5.004
Perls anymore. Alternatively, they should be prepared to back-port
modules and code snippets found in books and on this newsgroup.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | If at first you don't succeed,
Commercial Dynamics Pty. Ltd.   | destroy all evidence that you tried.
NSW, Australia                  | 


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

Date: Thu, 2 Nov 2000 18:52:44 -0500 
From: kevin montuori <montuori@arrakisplanet.com>
Subject: Re: Is there a way to get all PID's within Perl ?
Message-Id: <ydyn1fi2apc.fsf@kulon.arrakisplanet.com>

>>> Tom Christiansen writes:

  tc> % /usr/bin/ps -ef -o user -o pid -o args 
  tc> /usr/bin/ps: Command not found.

  tc> Moral of that story: don't use full paths. 

  well, use a full path unless you set $ENV{PATH} yourself.

  cheers,
  k.


-- 
kevin montuori

support independent booksellers -- http://www.booksense.com



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

Date: 3 Nov 2000 00:11:25 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Is there a way to get all PID's within Perl ?
Message-Id: <8tsvrd$es0$1@news.NERO.NET>

In article <3a01f2fe@cs.colorado.edu>,
Tom Christiansen <tchrist@perl.com> wrote:
>Moral of that story: you cannot count on exact details of 
>a command's arguments or its output format.

An alternate view is that you cannot count on the truth of any external
program, if what you are trying to do is detect hacking. 'ps' happens to
be one of those that a hacker tends to replace. 

>>But I would rather not have to call any external programs.
>
>Give up.  You basically have no choice, 

That depends on the OS you are on. If you have a friendly proc file
system, you can get the info you want from that. E.g., /proc/* is a
list of pids (plus other stuff), and /proc/9743/stat shows a bunch of
info about pid 9743.

>You should just call ps(1) and be done with it.  

Unless ps doesn't tell you what you need to know, or, as was the case
on the system where I started rummaging through the /proc fs, ps was
showing patently ridiculous data. For some reason, a system that had
been up for a week was showing process start times several months old.
When the process started was one of the things I really needed to
know.



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

Date: 2 Nov 2000 17:17:50 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Is there a way to get all PID's within Perl ?
Message-Id: <3a02042e@cs.colorado.edu>

In article <ydyn1fi2apc.fsf@kulon.arrakisplanet.com>,
kevin montuori  <montuori@arrakisplanet.com> wrote:
>  tc> Moral of that story: don't use full paths. 
>  well, use a full path unless you set $ENV{PATH} yourself.

Well, maybe, in a few rare cases.  If you're using something that's
not standard, then *perhaps*.  But otherwise, what's the use of a
path then, if you aren't going to allow the user to make their own
decisions?

One really cannot predict where things are installed, nor what order
the user prefers things in.  If they have /usr/local/nonfree/gnu/bin
in their path first, how can you argue with them?  Sure, people can
hose themselves.  Hard to make that illegal.

You *certainly* shouldn't just overwrite what they had.
You could, I suppose, do things like this:

    $ENV{PATH} .= ":" . join ":" => grep {-f && -d} qw{
	/bin/ /usr/bin /usr/libexec
	/sbin /usr/sbin /etc /usr/etc
	/usr/local/bin /usr/local/sbin /usr/local/libexec
    }; 

Yes, that can be much better.  I don't know that it's worth the
bother.  If someone's path is hosed, they've surely got other
problems, too.  That's not your problem.

--tom


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

Date: 02 Nov 2000 16:36:39 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: My brain hurts: another regex Q.
Message-Id: <m3wvemypag.fsf@dhcp11-177.support.tivoli.com>

"Doug Coppage" <dpc3k@virginia.edu> writes:

> Dearest Colleagues:
> 
> Preliminaries:
> 1. Yes, I have read the standard articles on regular expressions.
> 2. Yes, I have searched perldoc -q "[pick a relevant keyword]".
> 3. No, regular expressions are not "intuitive"; they are terser than terse
> and worse than Hungarian. My brain hurts.
> 4. If I really knew what I was doing, this would be easy. Please have pity.
> This should be cake for old Perl hands.
> 
> [Ahem.]
> 
> I would like to truncate a string at the first character that is NOT in
> [0-9a-zA-Z_]. For example...

Often, negating the problem makes it easier.  In this case, that
results in:

I only want the first series of characters that match [0-9a-zA-Z_].

That turns out to be exceedingly easy.  First, note that the character
class specified is the same as \w, so one solution is simply:

  s/^(\w*).*/$1/;

A much more efficient version, which is actually very much in line
with your original problem statement, is:

  s/\W.*//;

This simply says to find a non-word character and everything (except
newlines) after it, and remove all of that from the string.

If the incoming data can include newlines, you will also need the "s"
modifier on each of these substitutions.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 2 Nov 2000 16:41:22 -0800
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: my giant hash
Message-Id: <DRnM5.72$et1.114677@news.pacbell.net>


hi. first of all, i am new to the hash.

i am writing a text-to-xml parser that operates on a CSV raw data file. as
such, i have nearly 80 some-odd variable definitions/initializations...
defining tags, attributes, variables and data structures... that i would
like to put into a hash for inclusion in my script. presently, i have these
defs in two files...

    datadefs.pm
    lsdmltags.pm

i was including them via 'use vars'... as in:

    use vars qw( $var1 $var2 ... @array1 @array2 ... );
    require datadefs.pm
    require lsdmltags.pm

but that method meant that i had to have a super-long list of variables in
the 'use vars' declaration.

now i'm perplexed as to how i should retool these variable files in order to
get them into a hash. first, it seems like i won't be able to initialize
them; and second, it seems like i will have to go through the necessary, but
redundant, step of making up key names for each of the variables in the
hash...

i.e. if i have variables so named...

    # cat (old)datadefs.pm
    # initialize CSV field vars
    $csv_doccharacteristics = "";
    $csv_filename = "";
    $csv_filelocn = "";
    (ad nauseum...)

do i have to make up keys for them like

    # cat (new)datadefs.pm
    package datadefs;
    use Exporter;
    @ISA = qw(Exporter);
    @EXPORTER = qw(%G);

    %G = (
        docchars => $csv_doccharacteristics,
        filename => $csv_filename,
        filelocn => $csv_filelocn,
        authors => @authors,
        etc.
    );

TIA,
Brian





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

Date: Thu, 2 Nov 2000 19:24:11 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: my giant hash
Message-Id: <slrn9041db.gmd.tadmc@magna.metronet.com>

On Thu, 2 Nov 2000 16:41:22 -0800, Brian McDonald 
   <mcdonabNO@SPAMyahoo.com> wrote:
>
>hi. first of all, i am new to the hash.


    perldoc perldsc

will likely help with Perl's data-structure-building capabilities.


>now i'm perplexed as to how i should retool these variable files in order to
>get them into a hash. first, it seems like i won't be able to initialize
 ^^^^^^^^

Noooo.

You don't _have_ a scalar $csv_doccharacteristics anywhere in
your code. You instead have a 'csv_doccharacteristics' hash key.

i.e. you have _only_ the hash, not a bunch of individual variables
that have been copied into a hash.


>them; and second, it seems like i will have to go through the necessary, but
>redundant, step of making up key names for each of the variables in the
 ^^^^^^^^^


It is not redundant if you don't make them individuals only to
put them into an aggregate (hash).

Just put them into a hash in the first place.


>    %G = (
>        docchars => $csv_doccharacteristics,


Why not:

   csv_doccharacteristics = $csv_doccharacteristics,

??


>        authors => @authors,

That won't work.

That will make $authors[0] the value of $G{authors}  AND
$authors[1] will be another key in %G with an associated
value from $authors[2], and ...


Hash values can *only* be scalars.

To do what you're trying to do, you use a reference as the
scalar hash value.

You will need to learn Perl's references before you will
be able to do this in the general case.


   perldoc perlreftut
   perldoc perlref
   perldoc perllol
   perldoc perldsc


References are powerful. You'll want them in your Perl arsenal
anyway. Go find out about them.

Good luck!


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 2 Nov 2000 17:32:15 -0800
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: Re: my giant hash
Message-Id: <lBoM5.87$et1.125160@news.pacbell.net>


> >hi. first of all, i am new to the hash.
>
>
>     perldoc perldsc
>
> will likely help with Perl's data-structure-building capabilities.
>
>
><snip>
> You will need to learn Perl's references before you will
> be able to do this in the general case.
>
>
>    perldoc perlreftut
>    perldoc perlref
>    perldoc perllol
>    perldoc perldsc
>
>
> References are powerful. You'll want them in your Perl arsenal
> anyway. Go find out about them.
>

ok. i'm going to go away. when i come back all the lights in this basement
will be on.

(i don't know how i missed the existence of perldsc)

thanks again tad.

brian




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

Date: Fri, 03 Nov 2000 00:27:11 GMT
From: MSherrill@compuserve.com
Subject: Re: Need suggestions on optimization
Message-Id: <3a01f09c.31358581@news.compuserve.com>

On 02 Nov 2000 14:35:20 -0600, Ren Maddox <ren.maddox@tivoli.com>
wrote:

>I had a similar problem one time, and I eventually found that since
>the file was large the fastest solution was simply to `grep ...`.  
[snip]

Kernighan and Pike use their spam filter "isspam" as an example of
optimization in _The Practice of Programming_.  To hit their
performance target, they had to write the filter in C, *and* they had
to build a new version of strstr() tuned for their particular problem.

-- 
Mike Sherrill
Information Management Systems


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

Date: Fri, 03 Nov 2000 01:02:48 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: OT: Yes there _are_ stupid questions.  Anyone collect them?
Message-Id: <3A0211C8.6858892B@home.com>


Martien Verbruggen wrote:
> 
> There's no escape. The great Rick Spam Machine will find you wherever
> you are.

<<sigh>>  If only that *was* a joke.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Wed, 1 Nov 2000 19:26:24 -0800
From: "kim kubik" <chaotrope@jps.net>
Subject: Re: pattern matching across two lines
Message-Id: <EVmM5.8007$Q92.142990@nntp2.onemain.com>


If you have the sam text editor and you want to make
ALL "foo bar" into "foobar" whether there is a space
or a newline between the two words, you'd just do the
real real obvious, match the foo*bar and delete either
the space or the newline:

    /foo( |\n)bar/ . . . etc, where \n could be ^M

Duh . . .

Nitin wrote in message <8mb442$61l$1@nnrp1.deja.com>...
>I have text as follows:
>
>foo^M
>bar
>
>in several files. I need to replace this with:
>
>foobar
>
>How can I match patterns across two lines?
>
>Thanks,
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
>






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

Date: Thu, 02 Nov 2000 23:05:25 GMT
From: robert_maul@my-deja.com
Subject: Re: Perl compiler
Message-Id: <8tsrvg$5v$1@nnrp1.deja.com>

perlcc chokes for me too. my app uses perl tk, perl dbi and mysql.

maybe this is what is confusing it.

perl2exe looks promissing but i like free software.

any free perl compilers out there?

robert.maul@st.com      STMicroelectronics       CAD Engineer
Phone: (602) 485-2230   1000 East Bell Road      Region Americas
Fax: (602) 485-2839     Phoenix, AZ   85022      Design Center

In article <39E6DB14.6463607C@gmx.de>,
  "Werner, Wolfgang" <zakazan@gmx.de> wrote:
> öhöm, sorry, forgot the link...
> http://www.indigostar.com/perl2exe.htm
>
> vivek@cse.iitd.ernet.in wrote:
>
> > Can you please guide me to a perl compiler.
> > ( i would like to have a script having Tk compiled)
> >
> > Vivek Malik
> > icq: 57264676
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
>


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


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

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


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