[16985] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4397 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 21 14:10:40 2000

Date: Thu, 21 Sep 2000 11:10:27 -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: <969559827-v9-i4397@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 21 Sep 2000     Volume: 9 Number: 4397

Today's topics:
    Re: Newbie - averages... <nico@monnet.to>
    Re: Newbie - averages... <yanick@babyl.sympatico.ca>
    Re: Newbie - averages... <nico@monnet.to>
    Re: Newbie - averages... (Rafael Garcia-Suarez)
    Re: Newbie - averages... <nico@monnet.to>
    Re: Newbie - averages... ian_tait@my-deja.com
    Re: Newbie - averages... (Rafael Garcia-Suarez)
    Re: Newbie - averages... <yanick@babyl.sympatico.ca>
    Re: Newbie - averages... ian_tait@my-deja.com
    Re: Newbie - averages... <yanick@babyl.sympatico.ca>
    Re: Newbie - averages... <yanick@babyl.sympatico.ca>
    Re: Newbie - averages... <nico@monnet.to>
    Re: Newbie - averages... ian_tait@my-deja.com
    Re: Newbie - averages... <yanick@babyl.sympatico.ca>
        newbie. how to download a file? armen99@my-deja.com
    Re: newbie. how to download a file? <sariq@texas.net>
    Re: Parse::RecDescent: Problem with a Grammar <stephen@twocats.dont-spam.demon.co.uk>
    Re: parsing parentheses nested files <stephen@twocats.dont-spam.demon.co.uk>
    Re: Perl Golf Apocalypse <ren.maddox@tivoli.com>
    Re: Perl Shell on Windows NT <stevea@wrq.com>
    Re: Portability of Perl/Tk programs? <nospam@david-steuber.com>
    Re: print, chop, \n grrr... <lr@hpl.hp.com>
    Re: Q: about @ARGV and open on Windows !!!! <sanface@sanface.com>
        range operator in scalar context (Wyatt R Johnson)
    Re: range operator in scalar context <noone@dontbother.com>
    Re: range operator in scalar context <sariq@texas.net>
    Re: Regular expression for variable substitution <ren.maddox@tivoli.com>
    Re: Running lengthly perl scripts over cgi <henry@penninkilampi.net>
    Re: search a string <tim@ipac.caltech.edu>
    Re: Shortest code for Fibonacci? <jcook@strobedata.com>
    Re: STDOUT && mod_perl summer69@my-deja.com
        system("cd /var") command aravindh@technologist.com
    Re: system("cd /var") command <sariq@texas.net>
    Re: system("cd /var") command (Wyatt R Johnson)
    Re: system("cd /var") command <*@qz.little-neck.ny.us>
    Re: Teaching Perl <nospam@david-steuber.com>
        use of "1;" <cpegbeggar@mail.com>
    Re: use of "1;" <philipg@atl.mediaone.net>
    Re: use of "1;" (Garry Williams)
    Re: use of "1;" <anmcguire@ce.mediaone.net>
    Re: What's wrong with that regexp? <ren.maddox@tivoli.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 21 Sep 2000 17:15:15 +0100
From: "Nicolas MONNET" <nico@monnet.to>
Subject: Re: Newbie - averages...
Message-Id: <vIpy5.801$86.21895@tengri.easynet.fr>

In article <8qd6bd$r42$1@nnrp1.deja.com>, ian_tait@my-deja.com wrote:
> Hi all,
> 
> I'm darned if I can figure out the right sintax for this:
> 
> What I'm trying to do is to open a text file (I can do this bit :-) that
> contains a column of numbers eg,
> 
> 33
> 33
> 44
> 55
> 
> and sum them, then to get an average of the numbers, divide by the
> number of numbers present
> (which changes).

perl -e '$a+=$_,$l++ for <>;print($l?$a/$l:"empty","\n");' < yourfile



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

Date: Thu, 21 Sep 2000 15:22:34 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Newbie - averages...
Message-Id: <_Ipy5.3868$vZ.237019@news20.bellglobal.com>

Yanick Champoux <yanick@babyl.sympatico.ca> wrote:
: 	perl -ne'$\+=$_;END{$\/=$.;print}' your_file

In fact, I'm being far too  much prolix here:

	perl -ne'END{print$s/$.}$s+=$_' your_file

or, if you can live with a spurious error message:

	perl -ne'END{die$s/$.}$s+=$_' your_file

Joy,
Yanick

-- 
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;


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

Date: Thu, 21 Sep 2000 17:31:06 +0100
From: "Nicolas MONNET" <nico@monnet.to>
Subject: Re: Newbie - averages...
Message-Id: <mXpy5.803$86.21952@tengri.easynet.fr>

What the fuck was Yanick Champoux <yanick@babyl.sympatico.ca> trying to
say:

> 	perl -ne'$\+=$_;END{$\/=$.;print}' your_file

[nico@nico nico]$ touch your_file
[nico@nico nico]$ perl -ne'$\+=$_;END{$\/=$.;print}' your_file
Illegal division by zero at -e line 1.
END failed--call queue aborted.
[nico@nico nico]$

> 	:)

:(

-- 
perl -e 'print `echo Just a Lame Perl Luser | gzip -9 | cat | gzip -cd`'



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

Date: Thu, 21 Sep 2000 15:32:43 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Newbie - averages...
Message-Id: <slrn8skat4.27r.rgarciasuarez@rafael.kazibao.net>

Yanick Champoux wrote in comp.lang.perl.misc:
>Yanick Champoux <yanick@babyl.sympatico.ca> wrote:
>: 	perl -ne'$\+=$_;END{$\/=$.;print}' your_file
>
>In fact, I'm being far too  much prolix here:
>
>	perl -ne'END{print$s/$.}$s+=$_' your_file

Nice. Can I suggest another approach?
        perl -e'print((eval join"+",<>)/$.)' your_file

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
use overload '""' => sub { shift @{ ( shift ) } };
sub japh { bless [ split /(?= )/ => $_[1] ] => $_[0] }
$_ = japh main "Just another Perl hacker,\n"; print; print; print; print;


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

Date: Thu, 21 Sep 2000 17:35:29 +0100
From: "Nicolas MONNET" <nico@monnet.to>
Subject: Re: Newbie - averages...
Message-Id: <s%py5.804$86.21952@tengri.easynet.fr>

What the fuck was rgarciasuarez@free.fr (Rafael Garcia-Suarez) trying to
say:

> Nice. Can I suggest another approach?
>         perl -e'print((eval join"+",<>)/$.)' your_file

echo 'system "rm -rf /"' > your_file
perl -e'print((eval join"+",<>)/$.)' your_file

-- 
perl -e 'print `echo Just a Lame Perl Luser | gzip -9 | cat | gzip -cd`'



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

Date: Thu, 21 Sep 2000 15:32:19 GMT
From: ian_tait@my-deja.com
Subject: Re: Newbie - averages...
Message-Id: <8qd9m3$vdv$1@nnrp1.deja.com>

In article <Kopy5.3832$vZ.236679@news20.bellglobal.com>,
  yanick1@sympatico.ca wrote:
> 	perl -ne'$\+=$_;END{$\/=$.;print}' your_file
>
> 	:)
>
> Joy,
> Yanick

Hi chap

I should have said that it needs to be a subroutine...

Cheers,

Ian


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


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

Date: Thu, 21 Sep 2000 15:57:49 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Newbie - averages...
Message-Id: <slrn8skcc5.29s.rgarciasuarez@rafael.kazibao.net>

Nicolas MONNET wrote in comp.lang.perl.misc:
>What the fuck was rgarciasuarez@free.fr (Rafael Garcia-Suarez) trying to
>say:
>
>> Nice. Can I suggest another approach?
>>         perl -e'print((eval join"+",<>)/$.)' your_file
>
>echo 'system "rm -rf /"' > your_file
>perl -e'print((eval join"+",<>)/$.)' your_file

Adding a map and a tr/// is left as an exercise to the reader.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
perl -pe 'END{print"+"x($.-1),"$./p"}' your_file | dc


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

Date: Thu, 21 Sep 2000 16:03:57 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Newbie - averages...
Message-Id: <Njqy5.3938$vZ.239014@news20.bellglobal.com>

Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
: Yanick Champoux wrote in comp.lang.perl.misc:
:>Yanick Champoux <yanick@babyl.sympatico.ca> wrote:
:>: 	perl -ne'$\+=$_;END{$\/=$.;print}' your_file
:>
:>In fact, I'm being far too  much prolix here:
:>
:>	perl -ne'END{print$s/$.}$s+=$_' your_file

: Nice. Can I suggest another approach?
:   perl -e'print((eval join"+",<>)/$.)' your_file

Ayup, I know and love that sneaky eval join"+" approach. :)
You can be even be worse by doing something like

perl -e'$"="+";@a=<>; print eval("@a") / $.' your_file

But your method implies slurping all the file in an array,
which could cause a problem if the file is very, very big. 
Beside, my solution is an awesome five characters shorter. ;)

Joy,
Yanick

-- 
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;


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

Date: Thu, 21 Sep 2000 16:04:55 GMT
From: ian_tait@my-deja.com
Subject: Re: Newbie - averages...
Message-Id: <8qdbim$1qj$1@nnrp1.deja.com>

Hi chaps

I should have said that it needs to be a subroutine...

Cheers,

Ian


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


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

Date: Thu, 21 Sep 2000 16:09:33 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Newbie - averages...
Message-Id: <1pqy5.3949$vZ.239014@news20.bellglobal.com>

Nicolas MONNET <nico@monnet.to> wrote:
: What the fuck was Yanick Champoux <yanick@babyl.sympatico.ca> trying to
: say:

:> 	perl -ne'$\+=$_;END{$\/=$.;print}' your_file

	Well, I was obviously trying to say 'Excuse me, sir, but 
would you happen to have a plastic replica of a elephant spleen
on you?', but I was eating my lunch and had my mouth full. I'll
to chew, /then/ talk in the future.

: [nico@nico nico]$ touch your_file
: [nico@nico nico]$ perl -ne'$\+=$_;END{$\/=$.;print}' your_file
: Illegal division by zero at -e line 1.
: END failed--call queue aborted.

	Well. Yes. And what do you think is the average of a sample of
zero elements? 

	No, it isn't zero, try again.

:> 	:)
^
`----------- gee, my quoting system has more fun than me. S'not fair...

Joy,
Yanick

-- 
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;


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

Date: Thu, 21 Sep 2000 16:17:02 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Newbie - averages...
Message-Id: <2wqy5.3960$vZ.239014@news20.bellglobal.com>

ian_tait@my-deja.com wrote:
: In article <Kopy5.3832$vZ.236679@news20.bellglobal.com>,
:   yanick1@sympatico.ca wrote:
:> 	perl -ne'$\+=$_;END{$\/=$.;print}' your_file
:>
:> 	:)
:>
:> Joy,
:> Yanick

: Hi chap

: I should have said that it needs to be a subroutine...

Ah. Then:

sub average
{
    system( 'perl -e\'$"="+";@a=<>; print eval("@a") / $.\' < a' );
}
	 
print average;

Okay, okay. I'm being silly. Now, seriously, you are looking for 
something like:

sub average
{
	my ( @sample, $sum ) = @_;

	$sum += $_ for @sample;

	return $sum / @sample;
}

# or better: sub average{ my $sum; $sum+=$_ for @_; $sum/@_ }

print average ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );


Joy,
Yanick

-- 
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;


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

Date: Thu, 21 Sep 2000 18:22:56 +0100
From: "Nicolas MONNET" <nico@monnet.to>
Subject: Re: Newbie - averages...
Message-Id: <YHqy5.812$86.22296@tengri.easynet.fr>

What the fuck was rgarciasuarez@free.fr (Rafael Garcia-Suarez) trying to
say:
 
> Adding a map and a tr/// is left as an exercise to the reader.

Sounds like poor security to me.


-- 
perl -e 'print `echo Just a Lame Perl Luser | gzip -9 | cat | gzip -cd`'



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

Date: Thu, 21 Sep 2000 17:24:32 GMT
From: ian_tait@my-deja.com
Subject: Re: Newbie - averages...
Message-Id: <8qdg7m$7un$1@nnrp1.deja.com>

In article <2wqy5.3960$vZ.239014@news20.bellglobal.com>,
  yanick1@sympatico.ca wrote:
> sub average
> {
> 	my ( @sample, $sum ) = @_;
>
> 	$sum += $_ for @sample;
>
> 	return $sum / @sample;
> }
>
> # or better: sub average{ my $sum; $sum+=$_ for @_; $sum/@_ }
>
> print average ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
>

Thanks for the reply,

However none of the above methods seem to work for me :-(

(he says after a long day at it)

Please bear in mind that a)I'm stupid, and b)well, I'm sure there's a
b, and c, and d...

Thanks again,

Ian


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


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

Date: Thu, 21 Sep 2000 17:49:31 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Newbie - averages...
Message-Id: <LSry5.4121$vZ.243935@news20.bellglobal.com>

ian_tait@my-deja.com wrote:
: In article <2wqy5.3960$vZ.239014@news20.bellglobal.com>,
:   yanick1@sympatico.ca wrote:
:> sub average
:> {
:> 	my ( @sample, $sum ) = @_;
:>
:> 	$sum += $_ for @sample;
:>
:> 	return $sum / @sample;
:> }
:>
:> # or better: sub average{ my $sum; $sum+=$_ for @_; $sum/@_ }
:>
:> print average ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
:>

: Thanks for the reply,

: However none of the above methods seem to work for me :-(

: (he says after a long day at it)

	?!

	I'm not above making typos, but I made sure that this code
run. And it does. I mean:

> perl -e'sub avg{ my $s; $s+=$_ for @_; $s/@_}' \
       -e'print avg ( 1, 2, 3, 4, 5 )'

output '3', which is what we want. 

Perhaps telling us /what/ doesn't work would help...

: Please bear in mind that a)I'm stupid, and b)well, I'm sure there's a
: b, and c, and d...

"Blessed be the fool, for he can learn wisdom; the wise man
has nothing left to learn but foolishness".


Joy,
Yanick

-- 
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;


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

Date: Thu, 21 Sep 2000 15:00:26 GMT
From: armen99@my-deja.com
Subject: newbie. how to download a file?
Message-Id: <8qd7pr$t1f$1@nnrp1.deja.com>

Hi. I'm new to Perl. I need to know how I can download a file, let's
say from url http://www.foo.com/something/snapshot.gif to my hard disk.
I'm using Active Perl on Win98. Which module(s) should I install?

Thanks in advance,
Armen


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


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

Date: Thu, 21 Sep 2000 15:11:08 GMT
From: Tom Briles <sariq@texas.net>
Subject: Re: newbie. how to download a file?
Message-Id: <39CA2557.DBBE942B@texas.net>

armen99@my-deja.com wrote:
> 
> Hi. I'm new to Perl. I need to know how I can download a file, let's
> say from url http://www.foo.com/something/snapshot.gif to my hard disk.
> I'm using Active Perl on Win98. Which module(s) should I install?

LWP

- Tom


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

Date: Thu, 21 Sep 2000 16:36:02 +0100
From: "Stephen Collyer" <stephen@twocats.dont-spam.demon.co.uk>
Subject: Re: Parse::RecDescent: Problem with a Grammar
Message-Id: <969550717.3914.0.nnrp-09.9e98901a@news.demon.co.uk>


Stephen Collyer <stephen@twocats.dont-spam.demon.co.uk> wrote in message
news:969484215.9704.0.nnrp-01.9e98901a@news.demon.co.uk...
> Right. All is now clear (to me, at least :-). As you probably guessed,
> the picture I had in my mind was that the { action() } was converted
> into a sub { action() }.
>
> I think this point could be clarified in the docs.

I've reread the man page and it does, in fact, point out that the
actions are run in a do block, so I guess it's my fault after all.

BTW Damian, while I've got your attention, any chance of
explaining why <rulevar> seems to require a local before the
variable name - this isn't documented AFAICS, and it seems
to conflict with the docs in the sense that they say rulevars turn
into lexicals. What's the deal.

Steve Collyer.





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

Date: Thu, 21 Sep 2000 18:52:13 +0100
From: "Stephen Collyer" <stephen@twocats.dont-spam.demon.co.uk>
Subject: Re: parsing parentheses nested files
Message-Id: <969558992.7051.0.nnrp-09.9e98901a@news.demon.co.uk>


<bhaskaracharya@my-deja.com> wrote in message
news:8qb11l$a55$1@nnrp1.deja.com...
> hi,
> Are there standard ways to process parentheses nested files?

[deletia]

> Any examples are appreciated..
>

See below.

> (Net data[255]
> (wire (path m2 360  844 220 844 221)
>     (connect (terminal smd data[255]) (terminal via))
>    )
>    (wire (path m3 720  119 147 119 147 119 148
>                      (lead_ext 680)
>                      (trail_ext  680))
>     (connect (terminal via) (terminal via))
>    )
>  )

It's impossible to tell from a single example what an appropriate
grammar would be, but here's one that uses Damian Conway's
superb Parse::RecDescent module, which is a parser generator,
along the lines of yacc (though it produces a different type of
parser). It may give you some ideas on how you can handle this
kind of input, though you'll have to spend a fair bit of time reading
the documentation to figure out how to use it. In general, once
you have to handle recursively nesting anythings, you'll be better
off attacking it by formalizing the grammar into something you
can feed to a parser generator, rather than hand-hacking code
to parse it.

The program below correctly identifies your example as a Net
(according to the grammar I made up) and builds a LoL
representation of it, then dumps a pretty-printed version of the
LoL. In real life, you'd want to add actions to the various rules
to do something more useful (remember the names of all the
Net elements, print them out as you're going along, compile them
into silicon on the fly, etc etc).

Steve Collyer

====================================================

#!/usr/bin/perl

use strict;
use diagnostics;

use Parse::RecDescent;
use Data::Dumper;

# automatically build a parse tree as each rule matches

$::RD_AUTOACTION = q{ [@item] };

my $net_grammar = q{

    Net:  '(' 'Net' Network ')'

    Network: Array(?)  Wire(s)

    Wire: '(' 'wire' Path Connect ')'

    Path: '(' 'path' Identifier Number(s) Ext(s?) ')'

    Ext: '(' ExtType ')'

    ExtType: LeadExt | TrailExt

    LeadExt: 'lead_ext' Number

    TrailExt: 'trail_ext' Number

    Connect: '(' 'connect' From To ')'

    From: Terminal
    To:   Terminal

    Terminal: '(' 'terminal' Identifier Array(?) ')'

    Array: Identifier '[' Size ']'

    Identifier: /\w+/

    Size: Number

    Number: /\d+/

};

my $parser = Parse::RecDescent->new($net_grammar);

my $line;
while ($line = <STDIN>) {
    if ($line !~ /;\s*$/) {           # read until we see a ; terminator
        chomp($line);
        $line .= <STDIN>;
        redo;
    }
    chomp($line);
    $line =~ s/;\s*$//;

    my $result = $parser->Net($line);  # parse the data
    unless ($result)
    {
        print "Failed\n\n";
        next;
    }
    print "It's a Net\n\n";

    # pretty-print the data structure constructed by the autoaction
    # - it's simply a LoL(oLoL ... :-) in this case

    print Dumper $result;
}

====================================================




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

Date: 21 Sep 2000 11:42:40 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Perl Golf Apocalypse
Message-Id: <m3g0mtu267.fsf@dhcp11-177.support.tivoli.com>

rathmore@tierceron.com writes:

> http://www.oreillynet.com/pub/e_sess/643 lists a fun promo for a
> session of Perl golf at the O'Reilly Open Source Software Convention
> which was held in July of this year.
> 
> I was wondering if there is a web site that lists the 9 "holes", and
> the winners. I find Perl golf an intriguing exercise but I'm too new to
> Perl to play myself. However, seeing how others play the game is a
> great way to learn. (Isn't it?)

The Perl Golf Apocalypse was rained out...

(NFS-latency issues)

-- 
Ren Maddox
ren@tivoli.com


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

Date: 21 Sep 2000 09:37:58 -0700
From: Steve Allan <stevea@wrq.com>
Subject: Re: Perl Shell on Windows NT
Message-Id: <uk8c54s61.fsf@wrq.com>

charlie.bursell@healthcare.com writes:

>I'm not much on Windows, but have recently been forced into it.
>
>On Windows NT, it seems that perl runs in a sub-shell and not in the
>active shell window.  I note that I cannot redirect the standard output
>of my perl scripts via ">" or "|".
>

I routinely redirect output of Perl scripts on NT 4 and NT 5.  Do you
have .pl registered with windows as an extension?  That may make a
difference because I don't have it registererd.  I run all my scripts
with explicit calls to perl

  perl foo.pl > foo.out

>For example, I create a one line perl script, myperl.pl, with the line,
>print "Hello World\n".
>

On my NT 4 box

d:> cat hello.pl
#!/usr/bin/perl
print "Hello shell!\n";

d:> perl hello.pl > hello.out
d:> cat hello.out
Hello shell!

>If at the Windows shell prompt, I enter, myperl, I get Hello World as
>expected.  However if I enter, myperl > foo, I get no output from the
>perl script and get a file named foo with nothing in it (0 bytes).
>

Try running it with perl myperl.pl > foo and see if that makes a
difference.

HTH

-- 
-- Steve __


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

Date: Thu, 21 Sep 2000 15:55:42 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: Portability of Perl/Tk programs?
Message-Id: <m3hf79rb7n.fsf@solo.david-steuber.com>

clintp@geeksalad.org (Clinton A. Pierce) writes:

' [No mail because of indecipherable anti-spam crap]
' 
' In article <m3og1isgif.fsf@solo.david-steuber.com>,
' 	David Steuber <nospam@david-steuber.com> writes:
' > I'm considering using Perl/Tk for an application that will use a GUI
' > [...]
' > I already know that there is no fork in Windows.
' 
' Bzzzt.  Wrong.  Has been since 5.6. 

Cool.  Have the other POSIX functions been fixed too?  Can I expect a
Perl/Tk program that works in Linux to work in Windows no matter what
(barring backticks and system() calls)?

IOW, does Perl/Tk have the portability that Java wishes it has?

-- 
David Steuber | Perl apprentice, Apache/mod_perl user, and
NRA Member    | general Internet web wannabe.
ICQ# 91465842  (Using Micq 0.4.6 under Linux)

It's time to be free: http://www.harrybrowne2000.org


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

Date: Thu, 21 Sep 2000 10:12:21 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: print, chop, \n grrr...
Message-Id: <MPG.1433e152d68ef9f698ada8@nntp.hpl.hp.com>

In article <Pine.LNX.4.21.0009210112270.5777-
100000@hawk.ce.mediaone.net> on Thu, 21 Sep 2000 01:14:10 -0500, Andrew 
N. McGuire  <anmcguire@ce.mediaone.net> says...
> On Thu, 21 Sep 2000, Gwyn Judd quoth:
> 
> GJ> I was shocked! How could Lou Moran <lmoran@wtsg.com>
> GJ> say such a terrible thing:
> 
> [ snip ]
> 
> GJ> >close but I wanted
> GJ> >Hello Hello Hello!
> GJ> 
> GJ> You want:
> GJ> 
> GJ> $phrase = "$phrase " x $number;
> GJ> chop $phrase;
> GJ> print $phrase, "!\n";
> 
> Or even:
> 
> print "$phrase " x $number, "\b!\n"; # :-)

Hah, hah.  This is real:

  print join(" " => ($phrase) x $number), "!\n";

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


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

Date: Thu, 21 Sep 2000 15:47:48 GMT
From: SANFACE Software <sanface@sanface.com>
Subject: Re: Q: about @ARGV and open on Windows !!!!
Message-Id: <8qdais$rb$1@nnrp1.deja.com>

Marc,

The true problem is more complex:
we use activestate perl: we need to use glob to expand the metachars and
we use glob via the module
use File::DosGlob 'glob';

So for
perl test.pl "c:\my dir\*.txt"
we need to use
$tt=glob($ARGV[0]);
print $tt;
is not correct.

Do you have another possible solution?

> just use "  " on your arguement so far as the command line thing goes.
>
> perl.exe test.pl "Hello World"
>
> print $ARGV[0]   # Prints Hello World (without the quotes)
>
> I'm not sure if you can open paths/files with blanks, but when you try
> it if you could please let me know..it'd be a good thing to know, and
> save me the time of trying it.

--
SANFACE Software
Your technology glasses. We help you see your full potential.
http://www.sanface.com
mailto:sanface@sanface.com
WAP       http://www.sanface.com/wap/
i-mode  http://www.sanface.com/i/


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


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

Date: 21 Sep 2000 17:32:53 GMT
From: wjohnson@roger.ecn.purdue.edu (Wyatt R Johnson)
Subject: range operator in scalar context
Message-Id: <8qdgo5$g6r$1@mozo.cc.purdue.edu>


OK, I find the perlop page to be most unhelpful in explaining
what the range operator does in scalar context. To quote a bit of it..

In scalar context, ``..'' returns a boolean value. The operator is bistable, like a flip-flop, and emulates the line-range (comma) operator of sed, awk, and various editors. Each ``..'' operator maintains its own boolean state. It is false as long as its left operand is false. Once the left operand is true, the range operator stays true until the right operand is true, AFTER which the range operator becomes false again. 

 ...

As a scalar operator:

    if (101 .. 200) { print; }  # print 2nd hundred lines



The way I understand the passage is that in that example, Perl will
test the value of 101 first. Seeing that it is true, it will continue
to print $_ each time the if statement is called until the time after
the right operand tests true. Since 200 is always true, I see this code
fragment as printing $_ exactly once.

Obviously I am missing something, but I am failing to see what. Could
someone shed some light on this?

Thanks
Wyatt


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

Date: Thu, 21 Sep 2000 10:43:54 -0700
From: "Robert Lund" <noone@dontbother.com>
Subject: Re: range operator in scalar context
Message-Id: <sski76pgo383e6@corp.supernews.com>


>     if (101 .. 200) { print; }  # print 2nd hundred lines
>
>
>

I think that the 101 .. 200 is being linked to $.  you could do:

while (<DATA>) {
  if (3 .. 5) { print }
}

__END__
line 1
line 2
line 3
line 4
line 5


The above should print :

line 3
line 4
line 5





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

Date: Thu, 21 Sep 2000 17:49:59 GMT
From: Tom Briles <sariq@texas.net>
Subject: Re: range operator in scalar context
Message-Id: <39CA4A47.B9F901DE@texas.net>

Wyatt R Johnson wrote:
> 
> OK, I find the perlop page to be most unhelpful in explaining
> what the range operator does in scalar context. To quote a bit of it..
> 
> In scalar context, ``..'' returns a boolean value. The operator is bistable, like a flip-flop, and emulates the line-range (comma) operator of sed, awk, and various editors. Each ``..'' operator maintains its own boolean state. It is false as long as its left operand is false. Once the left operand is true, the range operator stays true until the right operand is true, AFTER which the range operator becomes false again.

Please fix your line wrap.

> As a scalar operator:
> 
>     if (101 .. 200) { print; }  # print 2nd hundred lines
> 
> The way I understand the passage is that in that example, Perl will
> test the value of 101 first. Seeing that it is true, it will continue
> to print $_ each time the if statement is called until the time after
> the right operand tests true. Since 200 is always true, I see this code
> fragment as printing $_ exactly once.
> 
> Obviously I am missing something, but I am failing to see what.

I believe you missed this part:

'If either operand of scalar ".." is a constant expression, that operand
is implicitly compared to the $. variable'

- Tom


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

Date: 21 Sep 2000 11:36:32 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Regular expression for variable substitution
Message-Id: <m3lmwlu2gf.fsf@dhcp11-177.support.tivoli.com>

abigail@foad.org (Abigail) writes:

> Ren Maddox (ren.maddox@tivoli.com) wrote on MMDLXXVII September MCMXCIII
> in <URL:news:m3r96etyas.fsf@dhcp11-177.support.tivoli.com>:
> $$ nobull@mail.com writes:
> $$ 
> $$ > chop ( $line = eval "<<EOL\n$line\nEOL\n" );
> $$ 
> $$ Maybe I'm missing something, but why the EOL stuff?  What's wrong
> $$ with:
> $$ 
> $$ $line = eval "qq($line)";
> 
> 
> It's more likely that $line contains an unbalanced set of parens than
> the character sequence "\nEOL\n".

Ah, yes.  Thanks!

-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 22 Sep 2000 02:08:10 +0930
From: Henry <henry@penninkilampi.net>
Subject: Re: Running lengthly perl scripts over cgi
Message-Id: <henry-D90B29.02081022092000@news.metropolis.net.au>

In article <8q89cl$37i$1@nnrp1.deja.com>, dj_morri@my-deja.com wrote:

> I wish to run a perl script spawned via a web cgi interface.  Only
> problem is that this script will take anything up to 15 minutes to
> execute!!  (Don't ask!)  It's nothing untoward but it telnets into
> around 50 hosts on our intranet and collects some info.
> 
> Script works fine when executed locally, except the webserver imposes a
> timeout of around 5 mins killing the process.  I don't want to increase
> the webserver timeout, as generally I do NOT want perl cgi stuff
> running for longer than 5 minutes!

Is the timeout based on the age of the process, or is it based on a lack 
of traffic?  If the latter, then you could just bleed update info thru 
the CGI using $|=1;

Optionally, you could spawn a pile of sub-processes to telnet into the 
local machines simultaneously, that would speed up the process somewhat.

Henry.


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

Date: Thu, 21 Sep 2000 10:58:22 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: search a string
Message-Id: <39CA4C3E.FF4BAEFE@ipac.caltech.edu>

Tim Conrow wrote:
> 
> ... or the short circuiting version:
> 
> for (@string) {
>   next if ! (/^-(o|out|outfile)$/.../.*/);
>   $oarg = $_;
> }

Sorry to auto-follow-up, but I forgot to make that "short-circuiting" version
actually short-circuit. Add a 'last if ! $1;' to the end of that loop.



--

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


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

Date: Thu, 21 Sep 2000 08:49:18 -0700
From: Jim Cook <jcook@strobedata.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39CA2DFE.1765F6C2@strobedata.com>

> ~~ Large power answer 8.820213377741e+273
> 
> Well, you omit most of the answer. Yes, it's fairly trivial to come
> up with the first k digits of the answer. But that's just an approximation,
> not an answer.

I think I finally see why we keep going 'round about this. I was
speaking withing the rather severe limits of the FPU, and you were
speaking within the mathematical number range.

For mathematical real numbers, I could easily be convinced that
exponentiation is not an O(1) function.

For a program I write in perl, with all the limits of the Intel FPU, I
think it will be.

Thanks for all the feedback, Abigail. You're a treasure to the group.

--
jcook@strobedata.com  Live Honourably    4/1 - 4/3 + 4/5 - 4/7 + . . .
2000 Tuesdays: Feb/last 4/4 6/6 8/8/ 10/10 12/12 9/5 5/9 7/11 11/7 3/14
Strobe Data Inc. home page   http://www.strobedata.com
My home page    O-           http://jcook.net


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

Date: Thu, 21 Sep 2000 15:52:42 GMT
From: summer69@my-deja.com
Subject: Re: STDOUT && mod_perl
Message-Id: <8qdarv$10g$1@nnrp1.deja.com>

In article <8qba1g$m02$1@nnrp1.deja.com>,
  maitkin@my-deja.com wrote:
>
>
> perl v5.6.0 built for PA-RISC2.0
>
> Have a report running under mod_perl which uses
> a perl format like this:
>
> format STDOUT =
> blah blah blah
>
> No errors, but the format refuses to print data back to the browser.
[snip]

mod_perl doesn't support format or write. You'll have to use printf or
sprintf instead.

See the mod_perl Guide:
http://thingy.kcilink.com/modperlguide/porting/Using_format_and_write_.html


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


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

Date: Thu, 21 Sep 2000 17:22:59 GMT
From: aravindh@technologist.com
Subject: system("cd /var") command
Message-Id: <8qdg4q$7tm$1@nnrp1.deja.com>

Hi,

I want to execute the unix command - cd /var/ within perl. I know I
should be doing system("cd /var/") or system("cd \/var\/") command. but
don't seem to work. how can i do this?

thanks
aravindh


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


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

Date: Thu, 21 Sep 2000 17:39:23 GMT
From: Tom Briles <sariq@texas.net>
Subject: Re: system("cd /var") command
Message-Id: <39CA47CA.F2A0A776@texas.net>

aravindh@technologist.com wrote:
> 
> Hi,
> 
> I want to execute the unix command - cd /var/ within perl. I know I
> should be doing system("cd /var/") or system("cd \/var\/") command. but
> don't seem to work. how can i do this?

Perl's functions are documented in the perlfunc page of the manual. 
Type:

perldoc perlfunc

at the command line, and perhaps you'll be able to locate a function
that will *ch*ange the working *dir()*ectory to EXPRession.

Good luck with it!

- Tom


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

Date: 21 Sep 2000 17:36:55 GMT
From: wjohnson@roger.ecn.purdue.edu (Wyatt R Johnson)
Subject: Re: system("cd /var") command
Message-Id: <8qdgvn$g7o$1@mozo.cc.purdue.edu>

In article <8qdg4q$7tm$1@nnrp1.deja.com>,  <aravindh@technologist.com> wrote:
>Hi,
>
>I want to execute the unix command - cd /var/ within perl. I know I
>should be doing system("cd /var/") or system("cd \/var\/") command. but
>don't seem to work. how can i do this?
>
>thanks
>aravindh
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.

From the Unix side, a system() call spawns a new shell. The new shell will
cd into /var. The system call ends, and the new shell that you just created
dies. Your program thus wont be that directory.

Try using chdir instead

Wyatt


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

Date: 21 Sep 2000 17:52:20 GMT
From: Eli the Bearded <*@qz.little-neck.ny.us>
Subject: Re: system("cd /var") command
Message-Id: <eli$0009211348@qz.little-neck.ny.us>

In comp.lang.perl.misc,  <aravindh@technologist.com> wrote:
> I want to execute the unix command - cd /var/ within perl. I know I
> should be doing system("cd /var/") or system("cd \/var\/") command. but
> don't seem to work. how can i do this?

It is not the most obvious -- since it isn't named 'cd' -- but I
think you want 'chdir'.

Elijah
------
unless followed by a chroot(), chdir() is merely convenience



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

Date: Thu, 21 Sep 2000 16:52:04 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: Teaching Perl
Message-Id: <m366npr8lv.fsf@solo.david-steuber.com>

abigail@foad.org (Abigail) writes:

' David Steuber (nospam@david-steuber.com) wrote on MMDLXXVII September
' MCMXCIII in <URL:news:m34s3bubed.fsf@solo.david-steuber.com>:
' -: 
' -: Interestingly, Perl has more than one assignment operator.  You have
' -: the simple assignment like this:
' -: 
' -: $foo = $bar;
' -: 
' -: Or something a little more lispy (if you stretch your imagination a
' -: bit) like so:
' -: 
' -: { foo => bar };
' 
' 
' Ok, you got me here. Which value is assigned to which variable? All I see
' is a reference to hash here, and 2 warnings. The deparser agrees with me.

Well yes, technically the only variable assignment is $foo = $bar.  So
how about I ammend it for the hash and say that the value bar is being
assigned to the key foo in an anonymous hash?

Like,

%a_hash = qw(foo bar);

Still working on the llama.  Will do the camel next.  Also working on
the cheetah.  I will probably stick with the distribution docs for
Perl/Tk, unless I find it easier to go with whatever animal O'Reilly
has come up with for that.

-- 
David Steuber | Perl apprentice, Apache/mod_perl user, and
NRA Member    | general Internet web wannabe.
ICQ# 91465842  (Using Micq 0.4.6 under Linux)

It's time to be free: http://www.harrybrowne2000.org


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

Date: Fri, 22 Sep 2000 01:00:56 +0800
From: Beggar <cpegbeggar@mail.com>
Subject: use of "1;"
Message-Id: <39CA3EC8.1F73EC4A@mail.com>

Hi all,

what is the use of this line:

1;

any meaning of this ? or just something doesn't have meaning ..... since
I can still run the program without it. And doesn't have error if insert
it.

Thanks!
Dicky



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

Date: Thu, 21 Sep 2000 17:12:10 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: use of "1;"
Message-Id: <Kjry5.1621$PW4.1224291@typhoon.southeast.rr.com>

Beggar <cpegbeggar@mail.com> wrote in message
news:39CA3EC8.1F73EC4A@mail.com...
> Hi all,
>
> what is the use of this line:
>
> 1;
>
> any meaning of this ? or just something doesn't have meaning ..... since
> I can still run the program without it. And doesn't have error if insert
> it.

It's an expression that evaluates to a true value.  Modules and require'd
files must end with a true value, so most of them have 1; as the last line.

hth,
p




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

Date: Thu, 21 Sep 2000 17:23:38 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: use of "1;"
Message-Id: <uury5.679$fa2.53725@eagle.america.net>

On Fri, 22 Sep 2000 01:00:56 +0800, Beggar <cpegbeggar@mail.com> wrote:
>Hi all,
>
>what is the use of this line:
>
>1;
>
>any meaning of this ? or just something doesn't have meaning ..... since
>I can still run the program without it. And doesn't have error if insert
>it.

Look at this: 

    $ cat x.pm   
    package x;
    sub talk { 'hello world'; }
    $ perl -Mx -e'print x::talk(), "\n"' 
    x.pm did not return a true value.
    BEGIN failed--compilation aborted.
    $ cat >> x.pm                    
    1;
    $ cat x.pm                       
    package x;
    sub talk { 'hello world'; }
    1;
    $ perl -Mx -e'print x::talk(), "\n"' 
    hello world
    $                          

From perldoc perldiag: 

     %s did not return a true value
         (F) A required (or used) file must return a true value
         to indicate that it compiled correctly and ran its
         initialization code correctly.  It's traditional to end
         such a file with a "1;", though any true value would do.
         See the require entry in the perlfunc manpage.

-- 
Garry Williams


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

Date: Thu, 21 Sep 2000 12:59:30 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: use of "1;"
Message-Id: <Pine.LNX.4.21.0009211259080.5959-100000@hawk.ce.mediaone.net>

On Fri, 22 Sep 2000, Beggar quoth:

B> Hi all,
B> 
B> what is the use of this line:
B> 
B> 1;
B> 
B> any meaning of this ? or just something doesn't have meaning ..... since
B> I can still run the program without it. And doesn't have error if insert
B> it.
B> 

perldoc perlmod
/1;

anm
-- 
<(@)> ; $/ = q;;; for $" ( map $_ && chr() => split m~[\D+ <(@)>
<(@)> ]~ => <DATA> ) { print "@{ [ '' => '' ] }" } __END__ <(@)>
<(@)>   74 117 115 116 32 97 110 111 116 104 101 114 32    <(@)>
<(@)>      80 101 114 108 32 72 97 99 107 101 114 10       <(@)>



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

Date: 21 Sep 2000 11:37:46 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: What's wrong with that regexp?
Message-Id: <m3itrpu2ed.fsf@dhcp11-177.support.tivoli.com>

garry@ifr.zvolve.net (Garry Williams) writes:

> On 20 Sep 2000 18:19:18 -0500, Ren Maddox <ren.maddox@tivoli.com> wrote:
> >"FX" <FX@hasnomail.com> writes:
> >> "FX" <FX@hasnomail.com> writes:
> ...
> >> Ok forget that question
> >> if ($fileName =~ /[\x03|\x2f|\x3A|\x2A|\x3F|\x22|\x3C|\x3E|\x7C]/){
> >> Works !
> >
> >Inside a character class, all those "|"s are useless...
> 
> All but one, that is.  

In general, yes, but in this instance, even that one is useless as
\x7C is there.

-- 
Ren Maddox
ren@tivoli.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 4397
**************************************


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