[19950] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2145 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 16 21:10:29 2001

Date: Fri, 16 Nov 2001 18:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005963012-v10-i2145@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 16 Nov 2001     Volume: 10 Number: 2145

Today's topics:
        Not Checking close `Pragmatic'? (Ralph Corderoy)
    Re: Not Checking close `Pragmatic'? <mgjv@tradingpost.com.au>
    Re: Perl on Windows <aaron@bosssystems.com>
    Re: Personal ad script? <kfisher@nyc.rr.com>
    Re: Pretty-printing CSS <darkon@one.net>
    Re: ranged arrays <djberge@qwest.com>
        Regex help (Jack Altradmon)
    Re: slicing multi dimensional arrays <mgjv@tradingpost.com.au>
    Re: slicing multi dimensional arrays <mgjv@tradingpost.com.au>
    Re: slicing multi dimensional arrays <tsee@gmx.net>
    Re: slicing multi dimensional arrays <tsee@gmx.net>
        Which ISPs support perl scripts? <mad-biker@couplands-well.freeserve.co.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 16 Nov 2001 23:37:58 GMT
From: ralph@inputplus.demon.co.uk (Ralph Corderoy)
Subject: Not Checking close `Pragmatic'?
Message-Id: <9t480m$2k1$1@inputplus.demon.co.uk>

Hi,

I've been having a occasional conversation with someone who insists
that checking the return value of Perl's close function isn't
necessary.

    My view:  check open, check close, don't typically bother with the
    writes, e.g. print, as any `error' will stick around until close
    time.

    His view:  check open, don't check writes or close.  close doesn't
    need checking because the code is just writing to a plain file.

Despite showing how print and close can fail, e.g. if the filesystem is
full, the guy persists:  `I don't agree it's a programming error'.  He
basically thinks `It's simply a pragmatic decision', and one that we
happen to disagree on.

Am I out of touch here, or is checking the return value of close good
practice?  I'd have certainly done it in C, and Perl's no different in
this respect (he argued at one point that Perl would catch any
close-related problems internally).

The fact that this code is published in a well-respected book makes
this all the worse.

Cheers,


Ralph.



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

Date: Sat, 17 Nov 2001 10:58:33 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Not Checking close `Pragmatic'?
Message-Id: <slrn9vba19.3j7.mgjv@martien.heliotrope.home>

On 16 Nov 2001 23:37:58 GMT,
	Ralph Corderoy <ralph@inputplus.demon.co.uk> wrote:
> Hi,
> 
> I've been having a occasional conversation with someone who insists
> that checking the return value of Perl's close function isn't
> necessary.

It all depends on what you opened, and whether you want to know if it
all finished ok.

>     My view:  check open, check close, don't typically bother with the
>     writes, e.g. print, as any `error' will stick around until close
>     time.

Again, it depends. For a log file, I don't tend to check the close. For
a file that contains critical data, or data that took a long time to
compute, I generally do check, and if there is a way to recover, I'll
even try to do that.

> 
>     His view:  check open, don't check writes or close.  close doesn't
>     need checking because the code is just writing to a plain file.

Then the data that he writes to this file must not be that important to
him that it warrants a check. Once he loses a few days of computation
thanks to a full disk, he'll change his views.

BTW, There are many places where checking the return code from a write
or print may be useful. For example when your program generates large
amounts of output, you might want to check now and again whether you're
not filling up the disk you write to (even when you print to STDOUT, it
could still end up on a disk). When you have a very long running
process, you should probably check now and again to see if disks haven't
filled up. When you write to something else than a file, you should
consider checking more often.

It depends very much on what you write to, how important your data is,
how much you write, whether you can recover from write errors, and
whether you should recover. There is no general answer, except:

Always check the return code of an open, unless you really don't care
about run time errors. Always check the result of a close if you opened
pipes or sockets, or if you need to make certain that your data got
written correctly.

> Despite showing how print and close can fail, e.g. if the filesystem is
> full, the guy persists:  `I don't agree it's a programming error'.  He
> basically thinks `It's simply a pragmatic decision', and one that we
> happen to disagree on.

What uttern nonsense. So, he only ever checks the return code of
calls when there is the possibility of a programming error? That means
that he wouldn't check the return code on most opens either.

90% of error checking is to detect runtime errors, not programming
errors.

> Am I out of touch here, or is checking the return value of close good
> practice?  I'd have certainly done it in C, and Perl's no different in
> this respect

Checking the return value of close never hurts. I personally only do it
when I care.

>              (he argued at one point that Perl would catch any
> close-related problems internally).

He's wrong. I don't think he really knows what he's talking about.

> The fact that this code is published in a well-respected book makes
> this all the worse.

Which 'this code'? Note that most of the close() calls in Perl programs
go unchecked, and again, that is fine. I only ever check when I care
about the data having arrived on disk (or after having opened a socket
or pipe or so).

Martien
-- 
                                | 
Martien Verbruggen              | +++ Out of Cheese Error +++ Reinstall
                                | Universe and Reboot +++
                                | 


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

Date: Fri, 16 Nov 2001 15:59:54 -0500
From: "Aaron Hartley" <aaron@bosssystems.com>
Subject: Re: Perl on Windows
Message-Id: <J5fJ7.11967$V9.1344232@news.direcpc.com>

Cameron,

Thank you for your help!

Aaron





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

Date: Fri, 16 Nov 2001 19:09:49 GMT
From: "1" <kfisher@nyc.rr.com>
Subject: Re: Personal ad script?
Message-Id: <1wdJ7.89602$XA5.15599434@typhoon.nyc.rr.com>

Thanks for replying Jessica,

The script should allow people to search for other people by certain
criteria: Location, height, weight, age, sex, etc., as well as certain other
criteria that can be changed and/or refined as the site evolves. They should
also be able to browse profiles.It also should allow people to submit their
own profiles and upload photos, as well as modify/delete their personal
profiles. People should be able to contact one another, preferably by
anonymous e-mail, and I have seen many sites with e-mail blocking options as
well. I also need the script return results only with photos, and have a
login for registered users.

I need to be able to customize the look as needed.

I know it's a lot to ask for, but I really am looking for a script with even
more features kind of like the sites: match.com,  www.lavalife.com ,
www.ameriacansingles.com , love.aol.com , yahoo personals, and excite
personals. I guess in the end I am looking for as many features as possible,
and the more customization the better.

Anyone know where the good scripts are? Even if I cannot find a perl or php
script (Prefered.), I'll take what I can get.

Thanks,

Ken







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

Date: Fri, 16 Nov 2001 19:30:47 -0000
From: David Wall <darkon@one.net>
Subject: Re: Pretty-printing CSS
Message-Id: <Xns915B93708AB24darkononenet@207.126.101.97>

ebohlman@omsdev.com (Eric Bohlman) wrote on 16 Nov 2001:

> David Wall <darkon@one.net> wrote:
>> Actually I think I should just write a parser for CSS (unless there's
>> already one), but I'm still slacking off on learning more about
>> parsers. 
> 
> CSS::SAC.

Figures.  I'm sure it's better than anything I would write anyway -- at 
least yet.  :-)  (I can dream)

Oh well, my little bit of code is lightweight and suits my present 
purposes pretty well.  I'll be keeping an eye on CSS::SAC, though.

Thanks, Eric.

-- 
David Wall
darkon@one.net


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

Date: Fri, 16 Nov 2001 15:06:39 -0600
From: "Mr. Sunblade" <djberge@qwest.com>
Subject: Re: ranged arrays
Message-Id: <I9fJ7.983$sb6.134582@news.uswest.net>


"Steffen Müller" <tsee@gmx.net> wrote in message
news:9sue21$30a$06$2@news.t-online.com...
<snip>
>
> Sure I'm willing to install modules. I had a look at the two and
eventhough
> they're interesting (will keep them in mind for some experiments later
on),
> they have little to do with my problem - save the name.
> About the Tie::RangeArray module: Guess what I was trying to do? :)
>
> Steffen

Install Tie::IxHash and try this out.  It could probably use a little
refinement and some error checking but you'll get the idea.

I made one assumption - that nested arrays would also keep the same sort of
indexing as well.  In other words, if the the low bounds is set to -3, then
the low bounds is set to -3 for each and every array reference that's
contained within a multi-dimensional array.  See my multi-dimensional
example below.

Now, do *I* get the prize? :)

Regards,

Mr. Sunblade

use strict;
use BoundedArray;

# Single dimension
my $b1 = BoundedArray->new(-3,2);

my @array = qw(hello world foo bar perl rules);
$b1->push(@array);

my $val = $b1->at(-2);
print "Val was: $val\n"; # Prints "world"

# Two dimensional (see Camel, p. 269)
my @aoa = (
   ["fred","barney"],
   ["george","jane","elroy"],
   ["homer","marge","bart"],
);

my $ba2 = BoundedArray->new(-3,-1);
$ba2->push(@aoa);

my $val = $ba2->at(-1,-2);
print "Val was: $val\n"; # Prints "marge"

package BoundedArray;
use strict;
use Tie::IxHash;

my %tied;
my $range;

sub new{
   my($class,$lower,$upper) = @_;
   die "Too few parameters\n" unless $lower && $upper;
   die "Low bounds must be less than high bounds\n" unless $lower < $upper;

   tie %tied, 'Tie::IxHash';

   # I'm sure some hacker can combine these two lines into 1 line
   my @nums = ($lower..$upper);
   $range = scalar(@nums);

   for(my $n = 0; $n <= $range; $n++){
      $tied{$lower} = $n;
      $lower++;
   }

   my $self = [];
   bless($self,$class);
}

sub at{
   my($self,@indices) = @_;

   my $length = scalar(@indices);

   if($length == 1){
      return $self->[$tied{$indices[0]}];
   }
   elsif($length == 2){
      return $self->[$tied{$indices[0]}]->[$tied{$indices[1]}];
   }
   else{
      print "You get the idea...\n";
   }
}

sub push{
   my($self,@vals) = @_;
   push(@$self,@vals);
   die "Exceeded bounds\n" if(scalar(@$self) > $range);
   return $self;
}
1;




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

Date: 16 Nov 2001 13:35:48 -0800
From: gjchap99@my-deja.com (Jack Altradmon)
Subject: Regex help
Message-Id: <57899c63.0111161335.51b940dc@posting.google.com>

Hi,

Need a regex guru to help me on this one... 

I want to send a file name to my script (on Win32) so I can split it
into mode (read/write/append), drive, path and file name.

My script has to be able to handle the following variations:

"> test.log" 
"> test*"    
"> c:\temp\example\test.log"
"> c:\temp\example\test*"
"> \\server\c$\temp\example\test.log"
"> \\server\c$\temp\example\test*"
"> .\temp\example\test.log"
"> .\temp\example\test*"

The "*" on the end will signal me to create a date time stamped file
name eg: test-<date>-<time>.log

If no drive and path is supplied the file will be looked for in the
following path ".\logs\"

I've tried something like this but it doesn't quite work...

( $action, $root, $path, $file ) = ( $filename =~
/^(>*)\s+(\w:\\?|\\\\.+?\\.+?\\|\\)(.*?\\)*?(.*?)$/ );

Anyone help ?


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

Date: Sat, 17 Nov 2001 09:42:42 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: slicing multi dimensional arrays
Message-Id: <slrn9vb5j2.3j7.mgjv@martien.heliotrope.home>

On Fri, 16 Nov 2001 15:06:08 +0100,
        Steffen Müller <tsee@gmx.net> wrote:
> I tried to post this to clp.moderated on 11-12-2001, but it has been neither

I haven't seen it there, but that might just mean that I missed it.

> A simple example:
> 
> my @large_ary = ( [ 1 .. 5 ], [ 'a' .. 'e' ] );
> # may have arbitrary dimensions.
> 
> my @coords     = (1, 1);
> my @dimensions = (2, 2);
> 
> my @portion = multi_dim_slice( \@large_array, \@coords, \@dimensions );
> 
> @portion should then be:
> ( [ 2, 3 ], [ 'b', 'c' ] )

I am not sure, simply because I don't really see How the @coords and
@dimensions@ for translated to the result. How should we interpret those
things? Something like

The nth element of @coords is the offset into the nth array
reference, and the nth element of @dimensions the length of the slice?

Could you try to describe it a bit better? If it is indeed the above,
then a few tests for lengths, an iteration, and some slices should do
it. 

sub multi_dim_slice
{
    my ($lar, $coords, $dim) = @_;
    my @return;

    for my $i (0 .. $#{$lar})
    {
        # Here we should check $coords->[$i] and $dim->{$i] are valid
        # to avoid runtime errors maybe something like:

        die "Gargle" unless defined $coords->[$i] && defined $dim->[$i];

        my $start = $coords->[$i];
        my $end   = $coords->[$i] + $dim->[$i] - 1;

        # not strictly needed..
        die "Gurgle" unless $start <= $end;

        push @return, [@{$lar->[$i]}[$start .. $end]];
    }

    return @return;
}

If you need to do a lot of this sort of thing, or you ave very large
arrays, you should probably have a look at the 

> 
>     This is demonstration code, untested and not the actual application. I
> chose to pass array refs because the number of coords and dimensions is
> arbitrary and perhaps unknown at compile time.
>     I am not plainly asking you to do my work, instead I am thankful for any
> hint or idea on how to do this. Perhaps there is some simple mechanism I am
> missing? Just FYI, I am trying to find all occurrances of a small matrix
> within a larger one and would compare slices of the large one to the smaller
> (pattern) matrix. The program works with a bunch of workarounds, but I would
> be able to use Data::Compare if I had the slices.
> 
> Thanks for your time and effort.
> 
> Steffen
> --
> $_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
> b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
> $1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
> 8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
> 
> 
> 

Martien
-- 
                                | 
Martien Verbruggen              | System Administration is a dirty job,
                                | but someone said I had to do it.
                                | 


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

Date: Sat, 17 Nov 2001 10:41:53 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: slicing multi dimensional arrays
Message-Id: <slrn9vb921.3j7.mgjv@martien.heliotrope.home>

On Fri, 16 Nov 2001 15:06:08 +0100,
        Steffen Müller <tsee@gmx.net> wrote:
> I tried to post this to clp.moderated on 11-12-2001, but it has been neither

I haven't seen it there, but that might just mean that I missed it.

> A simple example:
> 
> my @large_ary = ( [ 1 .. 5 ], [ 'a' .. 'e' ] );
> # may have arbitrary dimensions.
> 
> my @coords     = (1, 1);
> my @dimensions = (2, 2);
> 
> my @portion = multi_dim_slice( \@large_array, \@coords, \@dimensions );
> 
> @portion should then be:
> ( [ 2, 3 ], [ 'b', 'c' ] )

I am not sure, simply because I don't really see How the @coords and
@dimensions@ for translated to the result. How should we interpret those
things? Something like

The nth element of @coords is the offset into the nth array
reference, and the nth element of @dimensions the length of the slice?

Could you try to describe it a bit better? If it is indeed the above,
then a few tests for lengths, an iteration, and some slices should do
it. 

sub multi_dim_slice
{
    my ($lar, $coords, $dim) = @_;
    my @return;

    for my $i (0 .. $#{$lar})
    {
        # Here we should check $coords->[$i] and $dim->{$i] are valid
        # to avoid runtime errors maybe something like:

        die "Gargle" unless defined $coords->[$i] && defined $dim->[$i];

        my $start = $coords->[$i];
        my $end   = $coords->[$i] + $dim->[$i] - 1;

        # not strictly needed..
        die "Gurgle" unless $start <= $end;

        push @return, [@{$lar->[$i]}[$start .. $end]];
    }

    return @return;
}

If you need to do a lot of this sort of thing, or you have very large
arrays, you should probably have a look at the PDL (Perl Data language).
You should also have a look at that when I have interpreted the idea of
what you're tryin to do wrong.

Martien
-- 
                                | 
Martien Verbruggen              | System Administration is a dirty job,
                                | but someone said I had to do it.
                                | 


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

Date: Sat, 17 Nov 2001 01:38:40 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: slicing multi dimensional arrays
Message-Id: <9t4bh2$d0p$07$1@news.t-online.com>

"Martien Verbruggen" <mgjv@tradingpost.com.au> schrieb im Newsbeitrag
news:slrn9vb921.3j7.mgjv@martien.heliotrope.home...
| On Fri, 16 Nov 2001 15:06:08 +0100,
|         Steffen Müller <tsee@gmx.net> wrote:
| > A simple example:
| >
| > my @large_ary = ( [ 1 .. 5 ], [ 'a' .. 'e' ] );
| > # may have arbitrary dimensions.
| >
| > my @coords     = (1, 1);
| > my @dimensions = (2, 2);
| >
| > my @portion = multi_dim_slice( \@large_array, \@coords, \@dimensions );
| >
| > @portion should then be:
| > ( [ 2, 3 ], [ 'b', 'c' ] )
|
| I am not sure, simply because I don't really see How the @coords and
| @dimensions@ for translated to the result. How should we interpret those
| things? Something like
|
| The nth element of @coords is the offset into the nth array
| reference, and the nth element of @dimensions the length of the slice?

Well, both Anno and you asked for some clarification, so I chose bad names
and didn't explain enough. However, @coords contains offsets just as you
said. One for each dimension. @dimension, however, is a very bad name and
should have been @lengths or @sizes or whatever. It contains the number of
elements to slice from the original starting from and including the offset
value - one for each dimension.


| sub multi_dim_slice
| {
|     my ($lar, $coords, $dim) = @_;
|     my @return;
|
|     for my $i (0 .. $#{$lar})
|     {
|         # Here we should check $coords->[$i] and $dim->{$i] are valid
|         # to avoid runtime errors maybe something like:
|
|         die "Gargle" unless defined $coords->[$i] && defined $dim->[$i];
|
|         my $start = $coords->[$i];
|         my $end   = $coords->[$i] + $dim->[$i] - 1;
|
|         # not strictly needed..
|         die "Gurgle" unless $start <= $end;
|
|         push @return, [@{$lar->[$i]}[$start .. $end]];
|     }
|
|     return @return;
| }

Maybe a good image for a 3-d example would be picturing a large cube (what's
the English term for the more general form with variable side lengths?) and
the slice will return a portion of this, say, another "cube". @coords has
the coordinates of the "upper leftmost front" data element (here: the one
with the lowest indices) of the slice. @dimensions (or better: size)
contains the side lengths.

This description/example is horrible, too, but that's mostly because of my
English.

| If you need to do a lot of this sort of thing, or you have very large
| arrays, you should probably have a look at the PDL (Perl Data language).
| You should also have a look at that when I have interpreted the idea of
| what you're tryin to do wrong.

PDL? FAIL: MSWin32-x86-multi-thread
Too bad, I'm a prisoner of Bill (most time).

Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm




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

Date: Sat, 17 Nov 2001 01:52:47 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: slicing multi dimensional arrays
Message-Id: <9t4cbh$emk$03$1@news.t-online.com>

"Steffen Müller" <tsee@gmx.net> schrieb im Newsbeitrag
news:9t4bh2$d0p$07$1@news.t-online.com...
| PDL? FAIL: MSWin32-x86-multi-thread
| Too bad, I'm a prisoner of Bill (most time).

Got the binary version. Looking into it now.
I never heard of it before, but it seems wildly interesting!

Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm





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

Date: Sat, 17 Nov 2001 01:19:40 -0000
From: "Chris Clarke" <mad-biker@couplands-well.freeserve.co.uk>
Subject: Which ISPs support perl scripts?
Message-Id: <9t4duk$f9k$1@news8.svr.pol.co.uk>

As an absolute perl beginner... how do I find an ISP which supports perl
scripts?  I am currently with Freeserve, and the ISP would have to be free.
I tried a search with Ask Jeeves for ISPs, to no avail.  I know you guys are
WAY ahead of me technical-wise, but I've done some programming, and would
like to learn perl. Freeserve doesn't have the facility for CGI or perl
scripts.  Are there any (free) ISPs that you know of who do?

TIA,

Chris.




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

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


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