[23219] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5440 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 4 14:07:12 2003

Date: Thu, 4 Sep 2003 11:05:14 -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           Thu, 4 Sep 2003     Volume: 10 Number: 5440

Today's topics:
    Re: [newbie] how to get just the first value of a hash? <tassilo.parseval@rwth-aachen.de>
    Re: [newbie] list elements <minceme@start.no>
    Re: [newbie] list elements <postmaster@castleamber.com>
    Re: Arbitrarily Complex Data Structure <minceme@start.no>
    Re: Calling perl built-in functions (Jon)
    Re: DBD::CSV questions and is there a DBD::XML? <yanoff@STOP-SPAMMINGyahoo.com>
    Re: expression specific search and replace <postmaster@castleamber.com>
        Formats re-setting top of page format <tony1911@hotmail.com>
        GD: Graph Data Array Issue (Chad Thomson)
    Re: Getting directory sizes on win32 (Jeffrey Ellin)
    Re: Getting directory sizes on win32 <postmaster@castleamber.com>
        Looping scalar and regex'ing it <klubbheads_NO_SPAM@rogers.com>
    Re: Looping scalar and regex'ing it <postmaster@castleamber.com>
    Re: Looping scalar and regex'ing it <klubbheads_NO_SPAM@rogers.com>
    Re: Looping scalar and regex'ing it <postmaster@castleamber.com>
    Re: Order of evaluation of expressions (Anno Siegel)
    Re: Output from external command under Win2K <jwillmore@cyberia.com>
    Re: Rounding up  anything past the decimal point sprint (Steve D)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 4 Sep 2003 16:03:01 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <bj7nnl$am0$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Jürgen Exner:

> Tassilo v. Parseval wrote:
>> Also sprach Jürgen Exner:
>>
>>> Guest1 wrote:
>>> [see subject]
>>>
>>> Hashes are mappings and by definition don't have an order, therefore
>>> there is no first element or first value.
>>> Or how would you select the first value of let's say the cubicroot
>>> function?
>>
>> Well, the first one is probably 0 (at least for real numbers). The
>> challenge is to find the second value since it has a non-discrete
>> carrier.
> 
> You fell for the trap ;-)
> For squareroot(x) you are probably right.
> But I was talking about cubicroot and I would think that -5 comes before 0.

Oups, right. :-) I somehow failed to see that the cubicroot is x^(1/3) and
not x^(1/2).

> You could also argue that in case of squareroot i comes before 0. But there
> are too many people who don't know complex numbers, therefore it makes a
> poor example.

Well, i would be part of the result anyway (when taking the squareroot
of a negative number). If you define the range of your result to be
within the real numbers, the smallest input that is allowed is 0.

But indeed, finding the first number is even harder for complex numbers
since you suddenly have two dimensions to consider.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 4 Sep 2003 15:07:14 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: [newbie] list elements
Message-Id: <bj7kf2$mbo$1@troll.powertech.no>

John Bokma <postmaster@castleamber.com> wrote:
> Vlad Tepes wrote:
>> You could perhaps use the fact that hashes have unique keys.
>> Try building a hash with the values from the array:
>> 
>>     map $hash{$_} = 1, @a; # this will be more efficient [...]
>
> how about
>
> 	my %hash;
> 	@hash{@a} = ( "" ) x @a;

Why store anything at all?      :-)
    
    @hash{@a} = ( undef ) x @a;

BTW, how can I find out how much memory a certain data-structure takes?

-- 
Vlad


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

Date: Thu, 04 Sep 2003 17:39:50 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: [newbie] list elements
Message-Id: <3f575d2a$0$199$58c7af7e@news.kabelfoon.nl>

Vlad Tepes wrote:

> John Bokma <postmaster@castleamber.com> wrote:
> 
>>Vlad Tepes wrote:
>>
>>>You could perhaps use the fact that hashes have unique keys.
>>>Try building a hash with the values from the array:
>>>
>>>    map $hash{$_} = 1, @a; # this will be more efficient [...]
>>
>>how about
>>
>>	my %hash;
>>	@hash{@a} = ( "" ) x @a;
> 
> 
> Why store anything at all?      :-)
>     
>     @hash{@a} = ( undef ) x @a;

And what is undef? Is it not stored?

-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



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

Date: Thu, 4 Sep 2003 17:44:23 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: Arbitrarily Complex Data Structure
Message-Id: <bj7tln$pdr$1@troll.powertech.no>

JR <jrolandumuc@yahoo.com> wrote:

>jrolandumuc@yahoo.com (JR) wrote in message news:<b386d54b.0308291231.4ca368cd@posting.google.com>...
>>Brian McCauley <nobull@mail.com> wrote in message news:<u97k4xen8c.fsf@wcl-l.bham.ac.uk>...
>>> jrolandumuc@yahoo.com (JR) writes:
>>> 
>>>> Hi.  Is it possible to create a subroutine to handle an arbitrarily
>>>> complex data structure (for my purposes, complex only refers to hashes
>>>> and arrays)?

I just palyed some small with tarversing. Maybe yo like to have a loko:

    sub processitem($) {
        my $indent = shift;
        my $item   = shift || $_;
        print "$indent ", "    " x $indent, $item, "\n";
    }
    
    sub trav(@); # must declare sub to prototype recurs. func.

    sub trav {
        my $i = ref $_[0] ? 0 : 1 + shift; # indentation
        foreach ( @_ ) {
            /HASH/  &&  do{ trav $i, %$_;    next }; 
            /ARRAY/ &&  do{ trav $i, @$_;    next }; 
            /CODE/  &&  do{ trav $i, $_->(); next };
            /REF/   &&  do{ trav $i, $$_ ;   next };   
            processitem $i;
        }
    }

    trav  \%hoh, \\\\\%hah, \%hah, \%heh;

Cherio,
-- 
Vlad


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

Date: 4 Sep 2003 10:58:03 -0700
From: jhayden@usa.com (Jon)
Subject: Re: Calling perl built-in functions
Message-Id: <28769dad.0309040958.1f4b6a4f@posting.google.com>

Sorry for the delayed response...I ended up going out of town and just
got back.

Here is the problem I'm having.  Using Parse::RecDescent, I wrote a
simple language for my users to run tests without having to know Perl.
 For, example, a config file would look like:

parallel {
test1
test2
test3
}

serial {
test1
test2
test3
}

This then does all the perl stuff like forking to run tests in
parallel or serial without the user not having to know anything other
than my simple language.  Here is something I would like to add:

serial {
test1
print(running test2)
test2
}

Here's the kicker though...I want them to use any perl built in
function without me having to know ahead of time.  I don't want to
have a function called print that runs the built-in print function
when it sees it in my file.  I would like to parse the file and get
back $function($args) and then run it.  $function can be any built in
function, but I won't know what it is.

Does that make sense?

Thanks

"Janek Schleicher" <bigj@kamelfreund.de> wrote in message news:<pan.2003.09.02.09.20.16.713451@kamelfreund.de>...
> Jon wrote at Tue, 02 Sep 2003 04:12:37 -0700:
> 
> > my $function = "print";
> > my $args = "hello, world";
> > 
> > &$function $args;
> > 
> > 
> > It produces:
> > Undefined subroutine &main::print called
> > 
> > Is there a way to make this work?
> 
> Well, you can always do the eval workaround:
> 
> eval "$function $args";
> 
> with some more problems ...
> 
> But what's the problem behind the problem you've written to us?
> 
> 
> Greetings,
> Janek


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

Date: Thu, 04 Sep 2003 10:56:06 -0500
From: Scott Yanoff <yanoff@STOP-SPAMMINGyahoo.com>
Subject: Re: DBD::CSV questions and is there a DBD::XML?
Message-Id: <3f576097$0$43851$39cecf19@news.twtelecom.net>

Andrew Crook wrote:
> Also does anyone know of a DBD::XML module?

http://www.cpan.org did not show any hint of it.

There was some discussion on this years ago in the DB mailing lists.
http://www.geocrawler.com/archives/3/183/1998/10/100/1068137/

You might be able to retrieve XML via a SQL call and then use an XML 
parser on that data returned from your query.  Many XML parsers exist 
for Perl.

Good luck,

-- 
-Scott
yanoff@STOP-SPAMMINGyahoo.com | http://www.yanoff.org | AOL IM: SAY KJY



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

Date: Thu, 04 Sep 2003 17:37:56 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: expression specific search and replace
Message-Id: <3f575cb8$0$199$58c7af7e@news.kabelfoon.nl>

qanda wrote:

> Sorry for not being precise.
> 
> The expression I gave was an (obviously wrong) guess.
> 
> The pattern I want to look for is an uppercase letter C, followed by a
> forward slash, followed by alphanumeric characters, the pattern can
> start at the beginning of a field or in the middle and it ends at
> whitespace following alphanumeric characters of the end of field
> character.  The pattern can be in any field position such as field 1,
> field 3, field n, etc and can be in 0 or more fields in one record.


s|(C/[a-z0-9]+)| $hash{$1} |gie;

> The data itself is spread over 50,000 to 500,000 files, each
> containing several hundred thousand records.  These could contain say
> 100,000 unique strings that match this pattern, for example
> C/abc
> C/Abc
> C/1DE
> 
> Every occurance of C/abc should be replaced by string_1, every
> occurance of
> C/Abc should be replaced by string_2, etc.

I assume you mean a look up table?

> I think that I want the following (in pseudocode) but would appreciate
> an example of this
> or something better considering the performance running against
> millions of
> records.  I would assume it makes sense to use a hash to store each
> pattern
> found and then a search and replace with a counter ...
> 
>     for all files matching file specification
>         open a file
>         read a record
>         for each PATTERN in record
>             if PATTERN exists in the pattern hash
>                 replace the part that matched with
> string_patternNumber
>             else
>                 add PATTERN to hash

		  and then??

Ah, ok, something like:


open(FILE, ...) or die ...

my $number = 1;
while (defined($line = <FILE>)) {

	$line =~ s{(C/[a-z0-9]+)}{
		defined $hash{$1} ? $hash{$1} : $hash{$1} = $number++
         }gie;

	print $line;	# guess
}
close(FILE) or die ....

The g means global (for each on the current line)
The i means ignore case
The e means the "replace" part can be an expression

The string_1 is still not clear to me.


-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



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

Date: Thu, 04 Sep 2003 16:28:48 GMT
From: Tony <tony1911@hotmail.com>
Subject: Formats re-setting top of page format
Message-Id: <4LJ5b.83014$bo1.51568@news-server.bigpond.net.au>

Hi

This is a small version that shows the problem.
If it stays in the while loop it only prints
the top format the first time around then dosen't
print the top format for the next sixty odd iterations
which seems normal but not quite what I need.

If the program exits and is re-started it does the same
top only first time around. 
Each iteration it creates a new tempfile. 
Tried setting $- = 0; had no effect.

Seems I need to se-set the top format after
each iteration through the while loop.
Is this possible?

In the past I just used print instead of write
for the headings or exited and re-started the
program but would like to stay in it this time.

This is perl, v5.6.1 built for i386-linux

#!/usr/bin/perl
use warnings;
use strict;

use Fcntl;               # for temp file
use POSIX qw(tmpnam);    # for temp file

while (1) {

    print "Enter Name: ";
    chomp( my $name = <STDIN> );

    # -------------------------------------------------------------
    my $tempfile;

    do { $tempfile = tmpnam() }
      until sysopen( FH, $tempfile, O_RDWR | O_CREAT | O_EXCL );

    END { unlink($tempfile) or die "Couldn't unlink $tempfile : $!" }

    # -------------------------------------------------------------
    format FH_TOP =
   Page @<<<
        $%
 Name
-----------+
 .
    format FH =
@<<<<<<<<<<
$name
 .
    write FH;
    print FH "\n  q to continue\n";
    close FH;

    # -------------------------------------------------------------

    system("less $tempfile") && warn "Can't page tempfile";

    print "\nquit (y|N): ";
    chomp( my $quit = <STDIN> );
    if ( $quit eq 'y' ) { exit; }
}    # end while
exit;


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

Date: 4 Sep 2003 08:45:39 -0700
From: chad_thomson18@hotmail.com (Chad Thomson)
Subject: GD: Graph Data Array Issue
Message-Id: <ebe52c7.0309040745.9e49377@posting.google.com>

Hi All.

I'm relatively new to Perl, and have been somewhat successful using
the GD::Graph and Graph3d modules.

I'm using this procedure as a CGI app to generate graphs.
I've got an issue where, I'm setting up the @data array and when my
image renders in the browser, it has a width, and height, but still
appears as a broken link.

I've tried CARP and multiple other techniques to figure out what's
happening.  Obviously unsuccessful.

I believe the issue is directly related to the @data array, and/or
it's reference.

I've attached a "scaled-down" snipped of what I'm working with, any
advice is appreciated.

Chad.

<snip>

use CGI ':standard';
use GD::Graph::bars3d;

# Create CGI Object
my $q = new CGI;

my $alpha = "abcdefghijklmnopqrstuvwxyz";
my $ii = 0;
my $paramname;

# a sample url would be:
# ?xlabels=this,that,theother&groups=joe,ed,frank&a=1,2,3&b=4,5,6&c=7,8,9

# get X labels
my @labels = [ split (/\,/, $q->param ("xlabels")) ];

# get data groups
my @datagroups =  split (/\,/, $q->param("groups"));

# @data is supplied to the generator @plot-time
my @data = ( @labels );

# get data sets
# data is on query string as: a=1,2,3&b=4,5,6
my @datasets;
foreach (@datagroups) {
  $paramname = substr $alpha, $ii, 1;
  push @datasets, [ split ( /\,/ , $q->param($paramname) ) ];
  $ii++;
}
# @datasets should have a structure like this now.
# @datasets = ( [ 12,15,20 ]
#              ,[ 30,10,25 ]
#              ,[ 15,25,55 ]
#             );

=DEBUGcomments
 need to transpose datasets into @data:
    @data = ( [ labels ] 
             ,[ 12,30,15 ]
             ,[ 15,10,25 ]
             ,[ 15,25,55 ]
            );
=cut

foreach (@datasets) {
   # will have an array here
   
   # get each entry in the array
   # add/push it to an array on @data
   for ($i=0;$i<= $#{$_}; $i++) {
      push @{$data[$i+1]}, $_->[$i];      
      carp @{$data[$i+1]};
   } 
}

my $my_image = $my_graph->plot(\@data) or die $my_graph->error;

print "Content-type: image/png\n\n";
binmode ( STDOUT );
print $my_image->png;

</snip>


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

Date: 4 Sep 2003 08:29:24 -0700
From: deaduser@hotmail.com (Jeffrey Ellin)
Subject: Re: Getting directory sizes on win32
Message-Id: <e8a45386.0309040729.98b3350@posting.google.com>

> 
> When you say slow, how slow?  And how much data are we talking about? 
> I mean, if your talking terrabytes, it's going to take some time to
> get that information.  Plus, consider the platform and how it handles
> memory, resources, etc.  More memory will mean some better
> performance, etc.
> 

I think the slow portion is the actual quering of each file for size
and the fact that it is occuring over the lan, albiet 1gibit lan,
slows it down. We are talking 2000 users with about 100-200 files in
each directory. It took 4hrs to run last night.

On the up side the requirements have changed so I don't have to
exclude the two file types (dat and uaf) so now I am using the nt
diruse to calculate size.

        $res = `diruse /m $path`;
	@res = split(/\n/,$res);
	@dirsize = split(/\s+/,@res[3]);
	$dirsize = "@dirsize[1]";

Runs in 5minutes now.


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

Date: Thu, 04 Sep 2003 17:52:02 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Getting directory sizes on win32
Message-Id: <3f576007$0$199$58c7af7e@news.kabelfoon.nl>

Jeffrey Ellin wrote:

>>When you say slow, how slow?  And how much data are we talking about? 
>>I mean, if your talking terrabytes, it's going to take some time to
>>get that information.  Plus, consider the platform and how it handles
>>memory, resources, etc.  More memory will mean some better
>>performance, etc.
>>
> 
> 
> I think the slow portion is the actual quering of each file for size
> and the fact that it is occuring over the lan, albiet 1gibit lan,
> slows it down. We are talking 2000 users with about 100-200 files in
> each directory. It took 4hrs to run last night.
> 
> On the up side the requirements have changed so I don't have to
> exclude the two file types (dat and uaf) so now I am using the nt
> diruse to calculate size.
> 
>         $res = `diruse /m $path`;
> 	@res = split(/\n/,$res);
> 	@dirsize = split(/\s+/,@res[3]);
> 	$dirsize = "@dirsize[1]";

please change the latter to:

$dirsize = $dirsize[1];  # no array slice, no "".

And the @res[3] to $res[3]...

Put use strict; somewhere on top of your script and use -w: ie:
#!....perl -w

-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



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

Date: Thu, 04 Sep 2003 15:46:37 GMT
From: Moltar <klubbheads_NO_SPAM@rogers.com>
Subject: Looping scalar and regex'ing it
Message-Id: <Xns93EC77EB6A39C86745413465432435464@66.185.95.104>

Hi,


I want to go through a scalar in a loop and find strings that match a certain regex.
For example:

$string = 'Hi there *foo*, some stuff *bar* followed by more stuff and another *foo*.';

I need to loop through and get all the occurances of  two asterics and "remember" the stuff in between 
them. I can get the regex going, but I can't figure out how to do it in a loop.


Please help!

TIA!


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

Date: Thu, 04 Sep 2003 17:57:53 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Looping scalar and regex'ing it
Message-Id: <3f576165$0$199$58c7af7e@news.kabelfoon.nl>

Moltar wrote:

> Hi,
> 
> 
> I want to go through a scalar in a loop and find strings that match a certain regex.
> For example:
> 
> $string = 'Hi there *foo*, some stuff *bar* followed by more stuff and another *foo*.';
> 
> I need to loop through and get all the occurances of  two asterics and "remember" the stuff in between 
> them. I can get the regex going, but I can't figure out how to do it in a loop.
> 
> 
> Please help!

my(@stuff) = $string =~ /\*([^*]+)\*/g;

Assuming at least one none-* should be between **. (Otherwise replace + 
with *)

-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



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

Date: Thu, 04 Sep 2003 16:14:34 GMT
From: Moltar <klubbheads_NO_SPAM@rogers.com>
Subject: Re: Looping scalar and regex'ing it
Message-Id: <Xns93EC7CA90545B86745413465432435464@66.185.95.104>

Thank you John,

Hmm.. I was actually thinking of looping. Because I need to do other stuff with it later. I will describe it 
in more details:

I have a text file of the following structure:

*Header 1*
- item 1
- item 2
- item 3

*Header 2
- item 1
- item 2
- item 3

I want to go through the text file and find a header. After I found the header - store it in a hash as a key. 
After I want to process all the items untill the next header and store them all in the pointer array in the 
hash with key "header whatever". Then I come to the next header, etc...

Then $headers{Header1}->[1] will have value of 'item 1'.

I can figure out how to do all that. What stalls me is going in a loop through scalar. Maybe there is 
some 2 step solution? Going through scalar twice? Three times?

Thank you!


John Bokma <postmaster@castleamber.com> wrote in
news:3f576165$0$199$58c7af7e@news.kabelfoon.nl: 

> Moltar wrote:
> 
>> Hi,
>> 
>> 
>> I want to go through a scalar in a loop and find strings that match a
>> certain regex. For example:
>> 
>> $string = 'Hi there *foo*, some stuff *bar* followed by more stuff
>> and another *foo*.'; 
>> 
>> I need to loop through and get all the occurances of  two asterics
>> and "remember" the stuff in between them. I can get the regex going,
>> but I can't figure out how to do it in a loop. 
>> 
>> 
>> Please help!
> 
> my(@stuff) = $string =~ /\*([^*]+)\*/g;
> 
> Assuming at least one none-* should be between **. (Otherwise replace
> + with *)
> 



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

Date: Thu, 04 Sep 2003 19:18:21 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Looping scalar and regex'ing it
Message-Id: <3f577441$0$200$58c7af7e@news.kabelfoon.nl>

Moltar wrote:

> Thank you John,
> 
> Hmm.. I was actually thinking of looping. Because I need to do other stuff with it later. I will describe it 
> in more details:
> 
> I have a text file of the following structure:
> 
> *Header 1*
> - item 1
> - item 2
> - item 3
> 
> *Header 2
> - item 1
> - item 2
> - item 3
> 
> I want to go through the text file and find a header. After I found the header - store it in a hash as a key. 
> After I want to process all the items untill the next header and store them all in the pointer array in the 
> hash with key "header whatever". Then I come to the next header, etc...
> 
> Then $headers{Header1}->[1] will have value of 'item 1'.
> 
> I can figure out how to do all that. What stalls me is going in a loop through scalar. Maybe there is 
> some 2 step solution? Going through scalar twice? Three times?

my %headers;
my $line;
my $header;
my $value;
while (defined($line = <FILE>)) {

	chomp($line);
	if (($value) = $line =~ /\*([^*)\*/) {
		$header = $value;
		next;
	}
	push(@{$headers->{$header}}, $line);
}

if your lines indeed consist of - item 1 and you want it change the push 
line to:

	if (($value) = $line =~ /- (.*)/) {
		push(@{$headers->{$header}}, $value);
		next; # we are done (optional)
	}


-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



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

Date: 4 Sep 2003 15:29:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Order of evaluation of expressions
Message-Id: <bj7lo9$7v$1@mamenchi.zrz.TU-Berlin.DE>

Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMDCLVI
> September MCMXCIII in <URL:news:bj7ace$kha$1@mamenchi.zrz.TU-Berlin.DE>:
> !!  Mark Jason Dominus <mjd@plover.com> wrote in comp.lang.perl.misc:
> !! > In article <slrnbk10md.srs.abigail@alexandra.abigail.nl>,
> !! > Abigail  <abigail@abigail.nl> wrote:
> !! > >Where is its order of evaluation documented? Where in the documentation
> !! > >does it say that:
> !! > 
> !! > Yes, that's what I would like to know.
> !! > Or, if it doesn't say that, I would like to know that it doesn't.
> !! > 
> !! > Does anyone have any actual facts?
> !! > 
> !! > I wasn't able to find anything about it in the manuals, but the
> !! > manuals are pretty badly organized on basic matters like this, so I'm
> !! > not sure I was looking in the right places.
> !!  
> !!  Like you, I was never able to find a general commitment in the docs.
> !!  While Perl documentation is huge, and a moving target, I think it's
> !!  safe to say that it is silent about the point.  I mean, *someone*
> !!  would have found it by now :)
> !!  
> !!  Only some (few) operators are described individually as having left-right
> !!  evaluation order.  Some that come to mind are the short-circuiting boolean
> !!  operators, the list- and comma operators (both ","), and (I think)
> !!  assignment ("="), though I'm not entirely sure of the latter.
> 
> Where in the documentation do you read that about comma in list context?
> Perlop says:
> 
>        Comma Operator
> 
>        Binary "," is the comma operator.  In scalar context it
>        evaluates its left argument, throws that value away, then
>        evaluates its right argument and returns that value.  This
>        is just like C's comma operator.
> 
>        In list context, it's just the list argument separator,
>        and inserts both its arguments into the list.
> 
> which is explicite for the scalar case, but doesn't say anything about
> evaluation order in list context.

Hmm...  Your quote above is what I had in mind, but it doesn't say what
I thought it says about the comma as list separator.

Looking for other evidence, I found (in the Camel, p. 109)

        Once a list operator starts chewing up comma-separated arguments,
        the only things that will stop it are tokens...

which seems to imply a left-to-right progress, but that's about parsing,
not evaluation order.  Also, the part has been reworded in the current
perldoc to avoid exactly the left-to-right suggestion.  It now talks of
"all comma-separated expressions found there (the right side of a list
operator)".

>                                   Elsewhere in the same manual page,
> it is written:
> 
>        In the absence of parentheses, the precedence of list
>        operators such as "print", "sort", or "chmod" is either
>        very high or very low depending on whether you are looking
>        at the left side or the right side of the operator.  For
>        example, in
> 
>            @ary = (1, 3, sort 4, 2);
>            print @ary;         # prints 1324
> 
>        the commas on the right of the sort are evaluated before
>        the sort, but the commas on the left are evaluated after.
> 
> which suggest that if there's an evaluation order, it's from right
> to left!

I don't understand the argument in this bit of documentation.  It would
print "1234", no matter in which order the three list elements are evaluated.

But I can't be bothered now.  I must mourn for my lost belief in left-to-
right evaluation of (argument-)lists.

Anno


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

Date: Thu, 04 Sep 2003 15:24:44 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: Output from external command under Win2K
Message-Id: <20030904112442.78c50197.jwillmore@cyberia.com>

On 4 Sep 2003 07:33:15 -0700
perl@fdisk.org (Neil Palmer) wrote:
<snip>
> What I want to do is have any output that the external app might
> produce be displayed as it is produced, rather than be held until
> everything is finished, to serve as a visual feedback that the
> script is in fact running as it should.  I don't care about STDERR,
> only STDOUT.
> 
> Any suggestions?  Any other information I can provide?
> 
> ActiveState perl v5.6.1, build 631, running under Win2K

Try using IPC::Open2 or IPC::Open3.  The documentation has some pretty
clear examples.
You could also use Google and search for 'ipc' or 'pipe'or 'error' 
for more examples.  I know there's a thread out there, because I asked
something similar some time back :)  Last, but not least, try
searching for 'Benjamin Goldberg'.  The man has answered quite a few
questions of this type on this news group - he the man!

HTH
-- 
Jim
---
Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.
---
a real quote ...
Linus Torvalids: "They are somking crack ...."  
(http://www.eweek.com/article2/0,3959,1227150,00.asp)
---
a fortune quote ...
Illinois isn't exactly the land that God forgot -- it's more like
the land He's trying to ignore. 


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

Date: 4 Sep 2003 09:47:42 -0700
From: google.deller@smsail.com (Steve D)
Subject: Re: Rounding up  anything past the decimal point sprintf
Message-Id: <e41b2b3b.0309040847.6dd35ed6@posting.google.com>

Vlad Tepes <minceme@start.no> wrote in message news:<bj761g$hnl$1@troll.powertech.no>...
> Blnukem <Blnukem@hotmail.com> wrote:
> 
> > How can I round a number up if there is any value other than 00 after the
> > decimal point here is what I have:
> 
> > my $result = ($item / $count);
> 
> if ( $item % $count ) { $result = 1 + int $result; }
> > my $answer = sprintf ('%.2f', $result);
>  
> > print $answer;
> >
> > This returns a value of 2.20 I would like it to return a value of 3.00

This function is more properly called the "ceiling" function.

Perl Cookbook p 47 suggests the POSIX "ceil" function:
  use POSIX;
  my $result = ceil( $item/$count ) ; # $result == 3

Also, you could just add 0.5 to the value before printing with %f if
you just want to print it.

Of course, using printf with "%f" gives true rounding for printing.

Now if you want true rounding without using printf, use POSIX "floor":
  use POSIX;
  my $result = floor( ($item/$count) + 0.5 ) ; # $result == 2

Regards,
Steve D


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 5440
***************************************


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