[12606] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 2 20:57:45 1999

Date: Fri, 2 Jul 1999 17:47:00 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 2 Jul 1999     Volume: 9 Number: 7

Today's topics:
    Re: Counting parenthesis (NT and Solaris) <swiftkid@bigfoot.com>
    Re: Counting parenthesis (NT and Solaris) (M.J.T. Guy)
    Re: Counting parenthesis (NT and Solaris) <swiftkid@bigfoot.com>
    Re: Counting parenthesis (NT and Solaris) (Bart Lateur)
    Re: Counting parenthesis (NT and Solaris) (M.J.T. Guy)
    Re: Counting parenthesis (NT and Solaris) (M.J.T. Guy)
    Re: Counting parenthesis (NT and Solaris) <uri@sysarch.com>
    Re: Counting parenthesis (NT and Solaris) (M.J.T. Guy)
    Re: Counting parenthesis (NT and Solaris) <uri@sysarch.com>
    Re: Counting parenthesis (NT and Solaris) (Abigail)
    Re: Counting parenthesis (NT and Solaris) (Abigail)
    Re: Date Bug??? (Philip 'Yes, that's my address' Newton)
    Re: Date Bug??? <gellyfish@gellyfish.com>
    Re: Date::Manip can't handle Arizona Time zone? (I R A Aggie)
    Re: Date::Manip can't handle Arizona Time zone? (I R A Aggie)
    Re: differentiate btw big-endian machine and small-endi (Philip 'Yes, that's my address' Newton)
    Re: differentiate btw big-endian machine and small-endi <garethr@cre.canon.co.uk>
        difficulty in reading a directory (Jason Q.)
    Re: difficulty in reading a directory (elephant)
    Re: difficulty in reading a directory <tchrist@mox.perl.com>
    Re: difficulty in reading a directory <swiftkid@bigfoot.com>
    Re: difficulty in reading a directory <dodger@dodger.org>
    Re: difficulty in reading a directory <tchrist@mox.perl.com>
    Re: difficulty in reading a directory <swiftkid@bigfoot.com>
    Re: difficulty in reading a directory <dodger@dodger.org>
    Re: difficulty in reading a directory (Tad McClellan)
    Re: difficulty in reading a directory <tchrist@mox.perl.com>
        Duplicate output from Proc::Daemon mikael_brandt@my-deja.com
    Re: Duplicate output from Proc::Daemon <uri@sysarch.com>
    Re: Embedding Perl in C++ on WIN32 <dgh77ans@casema.net>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Fri, 2 Jul 1999 15:24:27 +0500
From: "Faisal Nasim" <swiftkid@bigfoot.com>
Subject: Re: Counting parenthesis (NT and Solaris)
Message-Id: <7lj7ag$7p61@news.cyber.net.pk>

> This little code below seems to be working OK on NT (perl 5.005_02)
> but not on Solaris (perl 5.004).  On solaris it does not count the
> left parenthesis!!!
>
> Any ideas?

Are you trying to do something like this:

$str = "(faisal) is a cool (boy)";
$par = $str =~ tr/[()]//;

# $par is 4

--
Faisal Nasim (the Whiz Kid)
Web: http://wss.hypermart.net/
AOL: Whiz Swift  ICQ: 4265451
FAX: (815) 846-2877






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

Date: 2 Jul 1999 12:03:09 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Counting parenthesis (NT and Solaris)
Message-Id: <7li9pt$86v$1@pegasus.csx.cam.ac.uk>

Faisal Nasim <swiftkid@bigfoot.com> wrote:

[ You didn't write the next 5 lines.   Please include correct
  attributions when quoting.                                   ]

>> This little code below seems to be working OK on NT (perl 5.005_02)
>> but not on Solaris (perl 5.004).  On solaris it does not count the
>> left parenthesis!!!
>>
>> Any ideas?
>
>Are you trying to do something like this:
>
>$str = "(faisal) is a cool (boy)";
>$par = $str =~ tr/[()]//;
>
># $par is 4

1)   No, that's not what Frederic was trying to do.    He was counting
     the difference between the number of ( and the number of ).

2)   He was only counting ( and ), not [ and ].
     ( You *do* understand the syntax of the tr/// operator, don't you? )

3)   As written, you destroy the input string.   This may or may not
     matter in the particular application, but it would be better
     practice to copy the input.


Mike Guy


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

Date: Fri, 2 Jul 1999 17:24:54 +0500
From: "Faisal Nasim" <swiftkid@bigfoot.com>
Subject: Re: Counting parenthesis (NT and Solaris)
Message-Id: <7ljedj$7ek8@news.cyber.net.pk>

> 3)   As written, you destroy the input string.   This may or may not
>      matter in the particular application, but it would be better
>      practice to copy the input.

$str = "(faisal) is a cool (boy)";
$par = $str =~ tr/[()]//;

print "$str\n$par";


output:

(faisal) is a cool (boy)
4


How am I destroying the input string?




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

Date: Fri, 02 Jul 1999 13:30:41 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Counting parenthesis (NT and Solaris)
Message-Id: <377fbd27.8870442@news.skynet.be>

M.J.T. Guy wrote:

>2)   He was only counting ( and ), not [ and ].
>     ( You *do* understand the syntax of the tr/// operator, don't you? )
>
>3)   As written, you destroy the input string.   This may or may not
>     matter in the particular application, but it would be better
>     practice to copy the input.

You're saying tr/()// destroys the input? Are you sure you understand
the tr/// operator?  ;-)

	$diff = tr/(// - tr/)//;

Although I think it would make more sense to check for nested
parentheses. Hmmm... this must be a FAQ. Yup: perlfaq6.

  Can I use Perl regular expressions to match balanced text?

	Bart.


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

Date: 2 Jul 1999 15:31:26 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Counting parenthesis (NT and Solaris)
Message-Id: <7lim0e$it4$1@pegasus.csx.cam.ac.uk>

Frederic Rivoallon  <frederic@tavern.xsj.xilinx> wrote:
>This little code below seems to be working OK on NT (perl 5.005_02) 
>but not on Solaris (perl 5.004).  On solaris it does not count the 
>left parenthesis!!!
>
>Any ideas?
>
>#!/usr/local/bin/perl -w
>
>@datafile = <>;
>
>foreach (@datafile) {    
>    chomp;
>    $nb = count_par($_);
>    print "ORIG: $_ $nb\n";
>}
>
>
>#
># This sub counts parentheses in a string (on NT it does)
>#
>sub count_par {
>    my $chaine = shift;
>    my $c = 0;
>
>    while ($chaine =~ /([()])/gc) {	    
>	$c += {qw(\( 1 \) -1)}->{$1};
>    }
>    return $c;
>}
>
>Frederic

This seems to be a bug in perl5.004.   It fails under 5.004 and 5.004_01.
It is OK under 5.004_04 and 5.004_05.

So upgrade to perl5.005_03 (or perl5.004_05) as appropriate.


Mike Guy


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

Date: 2 Jul 1999 15:35:44 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Counting parenthesis (NT and Solaris)
Message-Id: <7lim8g$j1d$1@pegasus.csx.cam.ac.uk>

Faisal Nasim <swiftkid@bigfoot.com> wrote:
>> 3)   As written, you destroy the input string.   This may or may not
>>      matter in the particular application, but it would be better
>>      practice to copy the input.
>
>$str = "(faisal) is a cool (boy)";
>$par = $str =~ tr/[()]//;
>
>How am I destroying the input string?

D'oh!     I was reading that as if it were  tr///d .    Sorry.

Though there are obscure details:   it'll fail if $str happens to be
read-only (e.g. $1);   it'll reset pos($str).

So I tend to think of tr/// as destructive regardless.


Mike Guy


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

Date: 02 Jul 1999 11:53:45 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Counting parenthesis (NT and Solaris)
Message-Id: <x7pv2b120m.fsf@home.sysarch.com>

>>>>> "MJTG" == M J T Guy <mjtg@cus.cam.ac.uk> writes:

  MJTG> Faisal Nasim <swiftkid@bigfoot.com> wrote:
  >>> 3)   As written, you destroy the input string.   This may or may not
  >>> matter in the particular application, but it would be better
  >>> practice to copy the input.
  >> 
  >> $str = "(faisal) is a cool (boy)";
  >> $par = $str =~ tr/[()]//;
  >> 
  >> How am I destroying the input string?

  MJTG> D'oh!     I was reading that as if it were  tr///d .    Sorry.

  MJTG> Though there are obscure details:   it'll fail if $str happens to be
  MJTG> read-only (e.g. $1);   it'll reset pos($str).

the read only aspect is true of anything that modifies a var, not just
tr///, so it is not a tr/// problem but a coding one. and where did you
get the idea that tr/// and pos have anything to do with each other? tr
operates on the whole bound string (or $_) and never starts in the
middle whereas pos can be used to set the start of a regex which uses \G
and/or /g.

  MJTG> So I tend to think of tr/// as destructive regardless.

normally it is, except when it isn't. it is the best perl idiom for
counting newlines (non-destructive, of course).

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 2 Jul 1999 16:16:52 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Counting parenthesis (NT and Solaris)
Message-Id: <7liolk$l1c$1@pegasus.csx.cam.ac.uk>

In article <x7pv2b120m.fsf@home.sysarch.com>,
Uri Guttman  <uri@sysarch.com> wrote:
>>>>>> "MJTG" == M J T Guy <mjtg@cus.cam.ac.uk> writes:
>
>  MJTG> Though there are obscure details:   it'll fail if $str happens to be
>  MJTG> read-only (e.g. $1);   it'll reset pos($str).
>
>                                                          where did you
>get the idea that tr/// and pos have anything to do with each other? tr
>operates on the whole bound string (or $_) and never starts in the
>middle whereas pos can be used to set the start of a regex which uses \G
>and/or /g.

I didn't say they did.   Except for the side effect that tr/// resets
pos(), like any other update.   And I did say that was obscure.


Mike Guy


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

Date: 02 Jul 1999 12:30:13 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Counting parenthesis (NT and Solaris)
Message-Id: <x7k8sj10bu.fsf@home.sysarch.com>

>>>>> "MJTG" == M J T Guy <mjtg@cus.cam.ac.uk> writes:

  MJTG> In article <x7pv2b120m.fsf@home.sysarch.com>,
  MJTG> Uri Guttman  <uri@sysarch.com> wrote:
  >>>>>>> "MJTG" == M J T Guy <mjtg@cus.cam.ac.uk> writes:
  >> 
  MJTG> Though there are obscure details:   it'll fail if $str happens to be
  MJTG> read-only (e.g. $1);   it'll reset pos($str).
  >> 
  >> where did you
  >> get the idea that tr/// and pos have anything to do with each other? tr
  >> operates on the whole bound string (or $_) and never starts in the
  >> middle whereas pos can be used to set the start of a regex which uses \G
  >> and/or /g.

  MJTG> I didn't say they did.   Except for the side effect that tr/// resets
  MJTG> pos(), like any other update.   And I did say that was obscure.

well a quick test shows it does reset pos.

perl -le '$a="qwert";pos($a)=2;print pos($a); $a=~tr/q//; print pos($a)'

but as you say, any modification should reset it. but it is confusing to
bring up pos in a thread on tr///. it is not tr/// specifically reseting
pos, but as you say any modification of the var.

in any case, tr/// used for counting is non-destuctive of the data,
though it does seem to affect magic in the var. if you use pos, you
should know not to do anything other than m/// and s/// on the var for
the duration of that logic block.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 2 Jul 1999 19:33:25 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Counting parenthesis (NT and Solaris)
Message-Id: <slrn7nqmi2.31h.abigail@alexandra.delanet.com>

Bart Lateur (bart.lateur@skynet.be) wrote on MMCXXXI September MCMXCIII
in <URL:news:377fbd27.8870442@news.skynet.be>:
** 
**   Can I use Perl regular expressions to match balanced text?


Yes. In pre Perl5.004, you would have to use a regex and some code:

     $c = 0;
     while ($text =~ /([()])/g) {
         $c += $1 eq '(' ? 1 : -1;
         die "Not balanced" if $c < 0;
     }
     die "Not balanced if $c;


With 5.005, you can do named regexes and recursively define them.
In that way, you can make a regex that matches balanced text.



Abigail
-- 
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'


  -----------== 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: 2 Jul 1999 19:35:09 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Counting parenthesis (NT and Solaris)
Message-Id: <slrn7nqmlb.31h.abigail@alexandra.delanet.com>

M.J.T. Guy (mjtg@cus.cam.ac.uk) wrote on MMCXXXI September MCMXCIII in
<URL:news:7lim8g$j1d$1@pegasus.csx.cam.ac.uk>:
-- Faisal Nasim <swiftkid@bigfoot.com> wrote:
-- >> 3)   As written, you destroy the input string.   This may or may not
-- >>      matter in the particular application, but it would be better
-- >>      practice to copy the input.
-- >
-- >$str = "(faisal) is a cool (boy)";
-- >$par = $str =~ tr/[()]//;
-- >
-- >How am I destroying the input string?
--
-- D'oh!     I was reading that as if it were  tr///d .    Sorry.
--
-- Though there are obscure details:   it'll fail if $str happens to be
-- read-only (e.g. $1);   it'll reset pos($str).

pos will be set by using // too. I guess you would prefer to use substr?



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: Fri, 02 Jul 1999 18:59:30 GMT
From: nospam.newton@gmx.net (Philip 'Yes, that's my address' Newton)
Subject: Re: Date Bug???
Message-Id: <377c40e6.129839232@news.nikoma.de>

On Thu, 01 Jul 1999 15:30:57 GMT, fliboy@my-deja.com wrote:

>Does anyone know why Perl on my systems (tested
>5.004 and 5.005, on Solaris and NT) reports the
>date one month prior to the current date?

Oh my goodness! And it gives the year as 99, when we all know that
it's really 1999! Maybe I should add 1900 to it, so that next year,
when it gives 100, adding 1900 will produce 2000, the correct year.

Cheers,
Philip

P.S. As many others have suggested -- you should read the docs for
localtime (perldoc -f localtime should do it).
-- 
Philip Newton <nospam.newton@gmx.net>


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

Date: 2 Jul 1999 12:52:18 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Date Bug???
Message-Id: <7licm2$1a4$1@gellyfish.btinternet.com>

On 1 Jul 1999 17:41:32 GMT I R A Aggie wrote:
> On Thu, 01 Jul 1999 15:30:57 GMT, fliboy@my-deja.com <fliboy@my-deja.com>, in
> <7lg1jh$gk8$1@nnrp1.deja.com> wrote:
> 
> + There is probably some simple explanation, but it eludes me!
> 
> I've seen several polite answers to this. And they say that clpm is
> populated by surly people...
> 

Yeah but I didnt see the question until it had been answered.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 2 Jul 1999 18:46:53 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Date::Manip can't handle Arizona Time zone?
Message-Id: <slrn7nq2da.6ie.fl_aggie@thepentagon.com>

On Fri, 02 Jul 1999 00:01:29 GMT, kgentes@gentek.net <kgentes@gentek.net>, in
<7lgvgk$sja$1@nnrp1.deja.com> wrote:

+   the Arizona timezone (Arizona has its own time zone,
+   in case you all didn't know

No, I didn't know, even tho I lived there 13 years. I presumed it was
*always* on Mountain Standard Time.

James


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

Date: 2 Jul 1999 22:47:58 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Date::Manip can't handle Arizona Time zone?
Message-Id: <slrn7nqgha.7qs.fl_aggie@thepentagon.com>

On 2 Jul 1999 18:46:53 GMT, I R A Aggie <fl_aggie@thepentagon.com>, in
<slrn7nq2da.6ie.fl_aggie@thepentagon.com> wrote:
+ On Fri, 02 Jul 1999 00:01:29 GMT, kgentes@gentek.net <kgentes@gentek.net>, in
+ <7lgvgk$sja$1@nnrp1.deja.com> wrote:
+ 
+ +   the Arizona timezone (Arizona has its own time zone,
+ +   in case you all didn't know
+ 
+ No, I didn't know, even tho I lived there 13 years. I presumed it was
+ *always* on Mountain Standard Time.

Being consumed by all things time-related, I went to the canonical
US Time Authority - the US Naval Observatory. As I suspected, there
*is* no Arizona timezone.

<url:http://aa.usno.navy.mil/AA/faq/docs/us_tzones.html>

To wit:

To obtain U.S. civil time from UTC, use the following table.

To obtain   

Atlantic Daylight Time		subtract 3 hours from UTC
Atlantic Standard Time		subtract 4 hours from UTC
Eastern Daylight Time		subtract 4 hours from UTC
Eastern Standard Time		subtract 5 hours from UTC
Central Daylight Time		subtract 5 hours from UTC
Central Standard Time		subtract 6 hours from UTC
Mountain Daylight Time		subtract 6 hours from UTC
Mountain Standard Time		subtract 7 hours from UTC
Pacific Daylight Time		subtract 7 hours from UTC
Pacific Standard Time		subtract 8 hours from UTC
Alaska Daylight Time		subtract 8 hours from UTC
Alaska Standard Time		subtract 9 hours from UTC
Hawaii-Aleutian Daylight Time	subtract 9 hours from UTC
Hawaii-Aleutian Standard Time	subtract 10 hours from UTC
Samoa Standard Time		subtract 11 hours from UTC

<end quote>

So there's no reason for Date::Manip to handle Arizona Standard Time... :)

James


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

Date: Thu, 01 Jul 1999 19:02:37 GMT
From: nospam.newton@gmx.net (Philip 'Yes, that's my address' Newton)
Subject: Re: differentiate btw big-endian machine and small-endian machine
Message-Id: <377bb8b5.94969644@news.nikoma.de>

On Thu, 01 Jul 1999 11:44:10 +0800, bennycc@pacific.net.sg wrote:

>    How can i differentiate  btw big and small endian machine in my
>codes?

You could compare pack("L", 0x12345678) with pack("N", 0x12345678). If
they compare equal, stringwise, you're on a network byte order
machine, hence big-endian. Otherwise, it's little-endian.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.net>


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

Date: Fri, 2 Jul 1999 10:07:40 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: differentiate btw big-endian machine and small-endian machine
Message-Id: <sin1xfuzyr.fsf@cre.canon.co.uk>

bennycc@pacific.net.sg wrote:
> How can I differentiate between big and small endian machines in my
> code?

You don't want to.  (Remember that there are more ways of ordering the
bytes in a word than just big- and small-endian.)  Trying to write code
to deal with particular byte orders makes your program gratuitously
buggy and non-portable.  When exchanging data with other programs, use
text if you can, or network byte order (see `perldoc -f pack') if you
can't.

-- 
Gareth Rees


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

Date: Fri, 02 Jul 1999 11:24:20 GMT
From: pigs_can_fly@mindless.com (Jason Q.)
Subject: difficulty in reading a directory
Message-Id: <3780a138.31288026@news.cyberway.com.sg>

Hi

In a directory, there are these 6 files:

	product.txt
	product1.txt
	product2.txt
	mike's_product.txt
	mike's_product1.txt
	mike's_product2.txt

To read the directory for "product*.txt", this is what I do:

$file = "product";
@dir = `ls /home/usr/$file*.txt`;

The above works fine and pulls out
	product.txt
	product1.txt
	product2.txt

However, the command fails to read the directory when there is a '
(singlequote) quote in $file like this example:

$file = "mike's_product";

I have also tried the following to no avail.

@files = system("ls", /home/usr/$file*.txt);

Is there something so simple I'm missing it?

Any help would be appreciated. Thanks.


JQ


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

Date: Fri, 2 Jul 1999 21:40:30 +1000
From: e-lephant@b-igpond.com (elephant)
Subject: Re: difficulty in reading a directory
Message-Id: <MPG.11e7503a94501c50989ad8@news-server>

Jason Q. writes ..
>	product.txt
>	product1.txt
>	product2.txt
>	mike's_product.txt
>	mike's_product1.txt
>	mike's_product2.txt
>
>Is there something so simple I'm missing it?

ever so slightly adjusted from the perlfunc page

#--begin
opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
@dots = grep { /^mike's_product.*/ && -f "$some_dir/$_" } readdir(DIR);
closedir DIR;
#--end

-- 
 jason - remove all hyphens for email reply -


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

Date: 2 Jul 1999 05:49:55 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: difficulty in reading a directory
Message-Id: <377ca763@cs.colorado.edu>

In comp.lang.perl.misc, pigs_can_fly@mindless.com (Jason Q.) writes:
:$file = "product";
:@dir = `ls /home/usr/$file*.txt`;

Wrong.

    @dir = glob("/home/usr/$file*.txt");

:However, the command fails to read the directory when there is a '
:(singlequote) quote in $file like this example:
:
:$file = "mike's_product";
:
:I have also tried the following to no avail.
:@files = system("ls", /home/usr/$file*.txt);

Wrong.  Wrong wrong wrong wrong.

1) You didn't quote the trailing argument.
2) You apparently do not know how to use the 
   function named system().  It returns you
   the command completion status.  This is 
   in the FAQ.

--tom
-- 
    "They'll get my perl when they pry it from my cold, dead /usr/local/bin."
	    Randy Futor in  <1992Sep13.175035.5623@tc.fluke.COM>


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

Date: Fri, 2 Jul 1999 17:20:36 +0500
From: "Faisal Nasim" <swiftkid@bigfoot.com>
Subject: Re: difficulty in reading a directory
Message-Id: <7lje5g$7ek7@news.cyber.net.pk>

>     @dir = glob("/home/usr/$file*.txt");

@dir = </home/usr/$file*.txt>;

;-)




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

Date: Thu, 1 Jul 1999 06:21:46 -0700
From: "Dodger" <dodger@dodger.org>
Subject: Re: difficulty in reading a directory
Message-Id: <7liciv$5nj$1@ancalagon.dragon-net.net>

Tom Christiansen wrote in message <377ca763@cs.colorado.edu>...
>In comp.lang.perl.misc, pigs_can_fly@mindless.com (Jason Q.) writes:
>:I have also tried the following to no avail.
>:@files = system("ls", /home/usr/$file*.txt);
>
>Wrong.  Wrong wrong wrong wrong.
>
>1) You didn't quote the trailing argument.
>2) You apparently do not know how to use the
>   function named system().  It returns you
>   the command completion status.  This is
>   in the FAQ.


Is it just me or isn't this the kind of thing Larry Wall rants about being
evil and inherently counterproductive to endless measure?

shouldn't it just be:
opendir (DIR, '/home/usr') or die "Yecch! Couldn't open /home/usr: $!\n";
@files = grep /^$file.*\.txt$/, readdir DIR;
# gratuitous insulting error message follows if @files is empty #
scalar @files or die "Silly freak! There are no files starting with $file in
there!\n";
closedir DIR;

And who names a directory usr inside the home drive anyway? That's a pretty
confuzzling filesystem to say the least... I hope there's not a /usr/home,
too...

Dodger




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

Date: 2 Jul 1999 08:40:01 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: difficulty in reading a directory
Message-Id: <377ccf41@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    "Dodger" <dodger@dodger.org> writes:
:Is it just me or isn't this the kind of thing Larry Wall rants about being
:evil and inherently counterproductive to endless measure?

I have no idea what you're talking about.  Calling glob?  Gosh no.
If you aren't supposed to glob, Perl would not have it.

:And who names a directory usr inside the home drive anyway? 

Drive? 
Drive??
Drive???
Drive????
Drive?!?!?

A drive is not a disk drive.
Sometimes it's is a tape drive.
Sometimes is a CD drive.
A drive is not a disk.
A disk is not a partition.
A partition is not a filesystem.

What's next, filling up the air in your wheels?

Sigh.  Curse the Bill.

--tom
-- 
Love your enemies: they'll go crazy trying to figure out what you're up to.


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

Date: Fri, 2 Jul 1999 19:19:46 +0500
From: "Faisal Nasim" <swiftkid@bigfoot.com>
Subject: Re: difficulty in reading a directory
Message-Id: <7ljl3b$7ek10@news.cyber.net.pk>

> shouldn't it just be:
> opendir (DIR, '/home/usr') or die "Yecch! Couldn't open /home/usr: $!\n";
> @files = grep /^$file.*\.txt$/, readdir DIR;
> # gratuitous insulting error message follows if @files is empty #
> scalar @files or die "Silly freak! There are no files starting with $file
in
> there!\n";
> closedir DIR;

opendir DIR , '/' or die "Yecch! Couldn't open /home/usr: $!\n";
@files = grep /^$file.*\.txt$/, readdir DIR or
  die "no files starting with $file and ending in .txt in there!\n";
closedir DIR;

?




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

Date: Thu, 1 Jul 1999 16:57:25 -0700
From: "Dodger" <dodger@dodger.org>
Subject: Re: difficulty in reading a directory
Message-Id: <7ljhsb$dts$1@ancalagon.dragon-net.net>

No, I meant slinging system calls and backticks and such in a script when
there's an internal way of doing a better job of it. It seems there's just
something inherently wrong with calling ls when you can get the information
in a more perlish and non-system-specific way.

As far as 'drive' goes, I use that as slang for filesystem and will continue
to do so, no matter how many times you say it back at me with question marks
affixed to the end. So there.

Dodger




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

Date: Fri, 2 Jul 1999 14:34:49 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: difficulty in reading a directory
Message-Id: <9o0jl7.6r3.ln@magna.metronet.com>

Faisal Nasim (swiftkid@bigfoot.com) wrote:
: >     @dir = glob("/home/usr/$file*.txt");

: @dir = </home/usr/$file*.txt>;

: ;-)


   What is your point?


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


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

Date: 2 Jul 1999 18:09:45 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: difficulty in reading a directory
Message-Id: <377d54c9@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    "Dodger" <dodger@dodger.org> writes:
:No, I meant slinging system calls and backticks and such in a script when
:there's an internal way of doing a better job of it. It seems there's just
:something inherently wrong with calling ls when you can get the information
:in a more perlish and non-system-specific way.

Use the toolkit, or we'll just have to remove its access in the next
release! :-)

Perl is a glue language.  Glue, baby, glue!

Don't call mail!  Do you own queuing!
Don't call ps!  Do you own kmem dives!
Don't call lpr!  Diddle the daemon on your own!


#!/usr/bin/perl -w

use strict;

my $PROCDIR = "/proc";
my %Pidinfo;

fetch_proc_info();
visit(1);
exit;

###############

sub fetch_proc_info {
    chdir $PROCDIR      || die "can't cd to $PROCDIR: $!";
    opendir(PROC, ".") || die "can't opendir . ($PROCDIR): $!";
    my $pid;
    while ( defined($pid = readdir(PROC))) {
	next unless $pid =~ /^\d+$/;
	my $statfile = "$PROCDIR/$pid/status";
	unless (open(STATUS, $statfile)) {
	    warn "can't open $statfile: $!";
	    next;
	} 
	while (<STATUS>) {
	    next unless /^([^:]+):\s*(.*)$/;
	    $Pidinfo{$pid}{$1} = first($2);
	    push @{$Pidinfo{$2}{child_procs}}, $pid if $1 eq 'PPid';
	} 
    }
}

BEGIN {
    # static vars for &visit
    my $Depth = 0;
    sub visit {
	my $pid = shift;

	printf "%-8s %5d %6s %1s %s%s\n",
		&uid($Pidinfo{$pid}{Uid}),
		$pid, $Pidinfo{$pid}{VmRSS} || 0,
		$Pidinfo{$pid}{State},
		"  " x $Depth, 
		&cmdline($pid);

	return unless $Pidinfo{$pid}{child_procs};
	$Depth++;
	for my $kid ( @{$Pidinfo{$pid}{child_procs}} ) { visit($kid) } 
	--$Depth;
    } 
}

BEGIN {
    # static vars for &uid
    my %uidcache;
    sub uid {
	my $uid = shift;
	unless (defined $uidcache{$uid}) {
	    $uidcache{$uid} = getpwuid($uid) || "#$uid";
	} 
	return $uidcache{$uid};
    } 
}

sub cmdline {
    my $pid = shift;
    my $cmdfile = "$PROCDIR/$pid/cmdline";
    my $line;
    unless ( open(CMD, $cmdfile) ) {
	warn "can't read $cmdfile: $!";
    } else {
	if (defined($line = <CMD>)) {
	    $line =~ s/[\s\0]+$//;
	    $line =~ s/\0/ /g;
	}
	close CMD;
    }
    if (!defined $line) {
	$line = $Pidinfo{$pid}{Name} || "[NONE]";
	$line = "($line)";
    } 
    return $line;
}

sub first {
    return '' unless defined $_[0];
    my $word = '';
    $word = (split ' ', $_[0])[0] ;
    return $word;
} 
-- 
    "What is the sound of Perl?  Is it not the sound of a wall that
     people have stopped banging their heads against?"
		--Larry Wall in <1992Aug26.184221.29627@netlabs.com>


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

Date: Fri, 02 Jul 1999 05:29:54 GMT
From: mikael_brandt@my-deja.com
Subject: Duplicate output from Proc::Daemon
Message-Id: <7lhioa$2io$1@nnrp1.deja.com>

I'm trying to create a small cgi-application whose
major purpose is to start a long running task with
input from a forms page. Since I can't hold up the
browser for long, I use Proc::Daemon to fork a
daemon subprocess after the HTML output has been
written to the browser. In the daemon process, the
long running task is performed and when it has run
to completion, an email receipt is sent.

My problem is that when I call Proc::Daemon::Init
the HTML output is duplicated. I don't have the
same problem when running the script from the
command line. By the way it's Sun Solaris and
Netscape's Web server.

Anyone's got a suggestion?

/MiKe


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 02 Jul 1999 01:50:43 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Duplicate output from Proc::Daemon
Message-Id: <x7908z38i4.fsf@home.sysarch.com>

>>>>> "mb" == mikael brandt <mikael_brandt@my-deja.com> writes:

  mb> My problem is that when I call Proc::Daemon::Init
  mb> the HTML output is duplicated. I don't have the
  mb> same problem when running the script from the
  mb> command line. By the way it's Sun Solaris and
  mb> Netscape's Web server.

sounds like a buffer flushing problem. you have to flush your output
buffers before the fork, or they get duplicated and flushed twice. set
$| to 1 in your main code which should solve the problem. this article
is also useful to read.

http://www.plover.com/~mjd/perl/FAQs/Buffering.html

i am cc'ing to mjd since this problem (duplicate output after a fork) is
not covered in the article and i think it merits addition.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Fri, 2 Jul 1999 23:15:05 +0200
From: "Dennis Janssen" <dgh77ans@casema.net>
Subject: Re: Embedding Perl in C++ on WIN32
Message-Id: <7lj9la$rjg$1@news.casema.net>

Could you be so kind to mail me link where to download all this stuff?  I
want to try to use perl as program part for automatic tagging.

thx in advance.

Dennis






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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". 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 V9 Issue 7
***********************************


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