[19417] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1612 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 25 21:05:36 2001

Date: Sat, 25 Aug 2001 18:05:09 -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: <998787908-v10-i1612@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 25 Aug 2001     Volume: 10 Number: 1612

Today's topics:
        $1 as subroutine parameter - problems <markus.laire@usa.net>
        $r->mtime not working on Windows NT Apache 1.3.20 and m (anthony staines)
    Re: 2-Open Directory problem (Eric Bohlman)
    Re: 2-Open Directory problem (John J. Trammell)
    Re: 2-Open Directory problem (Martien Verbruggen)
    Re: dynamic menu (efficiency) (Abigail)
    Re: Evaluation order of object methods <goldbb2@earthlink.net>
    Re: Extract the relative sorting of items from multiple <krahnj@acm.org>
    Re: Extract the relative sorting of items from multiple (Abigail)
        form post to https server, best method <niting@onebox.com>
    Re: IO::Select's can_read hanging forever. <dbe@wgn.net>
    Re: IO::Select's can_read hanging forever. <goldbb2@earthlink.net>
    Re: need help with regexp... (John Wentzcovitch)
    Re: one character at a time <bart.lateur@skynet.be>
    Re: one character at a time <dtweed@acm.org>
    Re: one character at a time (Logan Shaw)
    Re: one character at a time <godzilla@stomp.stomp.tokyo>
    Re: one character at a time <godzilla@stomp.stomp.tokyo>
    Re: one character at a time (Yves Orton)
    Re: open directory problem (Anno Siegel)
    Re: open directory problem <samneric@tigerriverOMIT-THIS.com>
    Re: Openning a file (Abigail)
    Re: Openning a file <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Performance : Shell X Perl (Abigail)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 25 Aug 2001 22:00:51 GMT
From: Markus Laire <markus.laire@usa.net>
Subject: $1 as subroutine parameter - problems
Message-Id: <Xns9109A5A7BF1markuslaire@192.89.123.233>


When I use $1 as parameter to subroutine, which does some regexp for that 
parameter and then tries to use parameter again, it is changed by that 
regexp because $_[0] seems to reference $1 which was given as parameter.

I can avoid this problem by calling subroutine as test(my $temp = $1) 
instead of test($1).

My question is then: Is there any other (more elegant/better ?) way to 
counter this problem than to create a temporary scalar ?

I know that 'my ($param) = @_;' in subroutine avoids this problem, but I 
want it to be optimized and tight.


This is illustrated by the following example.

use strict;
sub test($);

my $text = 'abcdefg';

test($text);

$text =~ /(.+)/;
test($1);    	    	# this won't work

$text =~ /(.+)/;
test(my $temp = $1);


# print first 3 letters of given argument
sub test($) {
  $_[0] =~ /(...)/;
  print "Begin: $1 of $_[0]\n";
}

Program prints
Begin: abc of abcdefg
Begin: abc of abc
Begin: abc of abcdefg



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

Date: 25 Aug 2001 16:18:27 -0700
From: anthony.staines@ucd.ie (anthony staines)
Subject: $r->mtime not working on Windows NT Apache 1.3.20 and mod-perl 1.26
Message-Id: <3a3997b6.0108251518.5349ef11@posting.google.com>

Hi,

I'm trying to use $r->mtime as to access the last modification
date of plain html files being served by Apache/mod-perl/Mason on
windows NT 4.0 SP6. These are real live filesystem files, containing
html and calls to Mason components. The $r->mtime call is in the body
of the file being called. So if the file was index.html, at the url
http://phm/index.html, the file would have the line % $r->mtime; in
it.

It returns 0 consistently, and the last-modified header, when I set it
directly with $r->set_last_modified, is also set to 0, that is to
00:00:00 January 1 1970, the start of the Unix epoch. stat works fine
within perl, and I get correct mtimes from it directly. I could use
stat, but I can't figure out what's wrong with $r->mtime

I just can't get $r->mtime to work. Note that the issue is not an
error on my part in interpreting the return value - it is actually 0,
and it ought to be something like 998781191 or so. I have included the
correct Apache module (Apache::File). There are no relevant error
messages anywhere..

I'm sure that I'm doing something stupid, but I cannot see what.
Help! Thanks in advance,
Anthony Staines


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

Date: 25 Aug 2001 18:16:03 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: 2-Open Directory problem
Message-Id: <9m8q13$b0g$2@bob.news.rcn.net>

Edd <edd@texscene.com> wrote:

> $isitopen="YES";
> opendir (LOGDIR, "/home/../..$path") || $isitopen="NO";
> if ($isitopen eq "NO") {
>    print "$path doesn't exit" ;
>    &subroutine1;
>    &subroutine2;
>    ...
> }

> The error it generates is :

> "scalar can't be modified near "NO";

It's a precedence problem.  || has higher precedence than =, so your 
statement is being parsed as an attempt to assign "NO" to the result of 
or'ing opendir's return value with the value of $isitopen, which doesn't 
make any sense.

I'd get rid of $isitopen completely, change your "if" to an "unless" and 
make the opendir the if condition.



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

Date: 25 Aug 2001 21:42:15 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: 2-Open Directory problem
Message-Id: <slrn9ogm3f.1j3.trammell@haqq.hypersloth.net>

On Sat, 25 Aug 2001 18:38:48 +0100, Edd <edd@texscene.com> wrote:
[snip] 
> $isitopen="YES";
> opendir (LOGDIR, "/home/../..$path") || $isitopen="NO";
> if ($isitopen eq "NO") {
>    print "$path doesn't exit" ;
>    &subroutine1;
>    &subroutine2;
>    ...
> }

How about:

 if ( opendir(LOGDIR,"...") ) # returns 'true' on success
 {
	# success
 }
 else
 {
	# failure
     print "error opening $path: $!\n";
	 ...
 }

-- 
If the organizational structure is threatening in any way, nothing is
going to be documented until it is completely defensible.
                                - F. Brooks, _The Mythical Man-Month_


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

Date: Sun, 26 Aug 2001 07:54:57 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: 2-Open Directory problem
Message-Id: <slrn9og7lh.3ga.mgjv@martien.heliotrope.home>

On Sat, 25 Aug 2001 18:38:48 +0100,
	Edd <edd@texscene.com> wrote:
> I want to do a series of tasks if a particular diurectory fails to open. To
> do this I wrote the code below. But it generates error. Why is that? Is
> there a way around it please?
> 
> $isitopen="YES";
> opendir (LOGDIR, "/home/../..$path") || $isitopen="NO";

This is parsed as

( opendir (LOGDIR, "/home/../..$path") || $isitopen ) = "NO";

either use or instead of ||, or use parentheses.

> if ($isitopen eq "NO") {
>    print "$path doesn't exit" ;
>    &subroutine1;
>    &subroutine2;
>    ...
> }

This is not the way these things are normally done in Perl. First of
all, using "NO" as a value indicating failure is a bit, let's say,
unconventional. Perl uses false values for that, which could be undef, 0
or "" or so.

Secondly, you can assign the return value of opendir directly:

$isitopen = opendir(LOGDIR, $dir);
if (!$isitopen)
{
    print "No such file path\n";
    ...
}

Thirdly, you don't even need that variable:

if (! opendir(LOGDIR, $dir))
{
    print "No such path '$dir'\n";
    ...
}

OR

opendir(LOGDIR, $dir) or do
{
    print "No such path '$dir'\n";
    ...
}


Fourthly, you can ask Perl about WHY the opendir failed, as long as you
do it quickly:

opendir(LOGDIR, $dir) or do
{
    print "opendir on '$dir' failed: $!\n";
    ...
}

And lastly, when printing error messages, you should send them to
STDERR. Either use STDERR as a print handle, or better, use warn:

opendir(LOGDIR, $dir) or do
{
    warn "opendir on '$dir' failed: $!\n";
    ...
}

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | What's another word for Thesaurus?
NSW, Australia                  | 


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

Date: 25 Aug 2001 22:44:01 GMT
From: abigail@foad.org (Abigail)
Subject: Re: dynamic menu (efficiency)
Message-Id: <slrn9ogahp.em5.abigail@alexandra.xs4all.nl>

four12and8up@unspam-me.yahoo.com (four12and8up@unspam-me.yahoo.com) wrote
on MMCMXIV September MCMXCIII in <URL:news:toaqli9e61ti1c@corp.supernews.com>:
<> I'm fooling around with keyboard input and wanted to create dynamic menu
<> choices similar to what Internet Explorer does on the address line.
<> 
<> For example, if I have a list of the 50 US states, and I type 'M'
<> on the input line, I would want to parse the list of states and find only
<> those beginning with 'M'. If the next letter I type is 'i', the
<> list should be narrowed down to the four states beginning with 'Mi'.
<> 
<> And so on, with the same thing happening in reverse (delete the 'i' and the
<> list goes back to all states beginning with 'M').
<> 
<> My question is about efficiency. I thought I'd iterate through an array of
<> all 50 states when the first character is entered, and put all matches into
<> a hash or arrays that corresponds with the number of characters entered.

For 50 states, efficiency shouldn't be high on your list of priorities.
Unless you're working on hardware from the 60s, but then you don't want
to do any interactive stuff anyway.

If you are talking about hundreds of thousands of strings, and doing a
gazillion of such queries on it, efficiency becomes important. Take your
favourite datastructures textbook and look up "trie" (no, I didn't misspel
"tree"). It's the datastructures that's made for tasks like this.



Abigail
-- 
perl -swleprint -- -_='Just another Perl Hacker'
#    A pair of dragons.
#    A pair of trout dart in the
#    pond. No ravens fly east.


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

Date: Sat, 25 Aug 2001 20:57:26 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Evaluation order of object methods
Message-Id: <3B884976.945B0223@earthlink.net>

Mr Sunblade wrote:
[snip]
> The ultimate goal is to emulate Ruby-style arrays, i.e. arrays as
> objects (not just one array in particular necessarily).  This is
> mainly for fun and readability.  It's easier to read and maintain
> '$ao->randomize()' than code and maintain an array randomizing
> subroutine.

Hmm.  If you want, you could write code which will work for *all*
arrays... just put the methods into the "ARRAY" package.

[snip]
> > > ###########################################
> > >
> > > Now, what I would like to be able to do is:
> > >
> > > my $so = Some::Object->new(1,2,3,4,5,2,3,4);
> > > my $length = $array->unique()->length(); # Want to return '5'
> >
> > Method chaining is possible, as long as every method returns an
> > object.  Since you plan to return various things, depending on
> > context, that approach won't work here.
> 
> Ok - I didn't have my Conway book handy at the time.  :) I see my
> mistake in this regard now.   I can get around this in a cheesy way by
> allowing an 'inline' hash-style argument that always returns $self so
> I chain any number of methods together
> 
> e.g. $length = $ao->randomize(inline=>1)->compact(inline=>1)->length()
> 
> I've tried it and it works fine, though it's annoying to have to
> specify that argument each time.  The other option is to always return
> $self, and force the user to specify that they want a return value.  I
> thought that was even more annoying.

That's why there's that fun wantarray() function.  Return $self or the
new object if wantarray is false, otherwise return an array.

Here's an example:
sub ARRAY::randomize {
	my $self = shift;
	# make a copy if we return a value, otherwise change $self
	my $array = defined(wantarray) ? [@$self] : $self;
	for (my $i = @$array; --$i; ) {
		my $j = int rand ($i+1);
		next if $i == $j;
		@$array[$i,$j] = @$array[$j,$i];
	}
	return wantarray ? @$array : $array;
}

sub ARRAY::unique {
	my $self = shift;
	my %seen;
	if( wantarray ) { # list context
		return grep !$seen{$_}++, @$self;
	} elsif( defined wantarray ) { # scalar context
		return [grep !$seen{$_}++, @$self];
	} else { # void context
		@$self = grep !$seen{$_}++, @$self;
	}
}

sub ARRAY::length {
	return scalar @$_[0];
}

sub ARRAY::lastindex :lvalue {
	return $#$_[0];
}

my @foo = ( 1, 2, 3, 4, 5, 2, 3, 4 );
my @bar = (\@foo) -> randomize;
my $length = (\@foo) -> unique -> length; # $length should be 5

See?  No need for adding an inline parameter of some sort.

If it's in list context, return a list with the result.  If it's in
scalar context, return a reference to a list with the result.  If it's
in void context, change the object the method is being called on.

Now, normally, I wouldn't suggest putting methods into ARRAY, but in
this case, where what you want is for all perl arrays act like Ruby
arrays, it's probably ok.

-- 
I'm not a programmer but I play one on TV...


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

Date: Sat, 25 Aug 2001 19:04:50 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Extract the relative sorting of items from multiple lists
Message-Id: <3B87F742.402D8599@acm.org>

David Combs wrote:
> 
> In article <3B76147C.1FBD0B8B@acm.org>, John W. Krahn <krahnj@acm.org> wrote:
> >
> >Get the first section of volume four here:
> >
> >http://Sunburn.Stanford.EDU/~knuth/fasc2a.ps.gz
> >
> 
> THANK YOU!
> 
> How did you know this even existed -- unless
> you are *at* Stanford?
> 
> Was it by an email-list?  If so, I gotta
> get on it!

http://slashdot.org/article.pl?sid=01/08/09/2246221&mode=thread



John
-- 
use Perl;
program
fulfillment


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

Date: 25 Aug 2001 23:12:29 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Extract the relative sorting of items from multiple lists
Message-Id: <slrn9ogc74.em5.abigail@alexandra.xs4all.nl>

David Combs (dkcombs@panix.com) wrote on MMCMXVI September MCMXCIII in
<URL:news:9m7oe0$h0v$1@news.panix.com>:
,, In article <3B76147C.1FBD0B8B@acm.org>, John W. Krahn <krahnj@acm.org> wrote:
,, >
,, >Get the first section of volume four here:
,, >
,, >http://Sunburn.Stanford.EDU/~knuth/fasc2a.ps.gz
,, >
,, 
,, THANK YOU!
,, 
,, How did you know this even existed -- unless
,, you are *at* Stanford?


Knuth has been working at Stanford for decades. He has had a website
for eons. He has announced his plans for Volume 4 and how he will make
it available for at least 5 years on his website.

It's actually pretty hard to argue you have an interest in algorithms
while not knowing this and keep a straight face.



Abigail
-- 
package Z;use overload'""'=>sub{$b++?Hacker:Another};
sub TIESCALAR{bless\my$y=>Z}sub FETCH{$a++?Perl:Just}
$,=$";my$x=tie+my$y=>Z;print$y,$x,$y,$x,"\n";#Abigail


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

Date: Sat, 25 Aug 2001 16:21:35 -0700
From: "Nitin G" <niting@onebox.com>
Subject: form post to https server, best method
Message-Id: <998781830.487894@sj-nntpcache-3>

am looking at implementing a solution where I need to post some data to a
https server. Before I went down a path that led to nowhere, I wanted to get
input from people who might have implemented a similar solution. What's the
best recommended module to use for handling such a situation?

Thanks,
-Nitin




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

Date: Sat, 25 Aug 2001 13:40:22 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: IO::Select's can_read hanging forever.
Message-Id: <3B880D36.362F46A9@wgn.net>

Benjamin Goldberg wrote:
> 
> I have a bit of code which needs to distribute some computation between
> to proccesses, and I use IO::Select to help tell what is happening when.
> 
> Unfortunatly, I've a call to it's can_read method, which seems to never
> return.
> 
> Here's the problem code:
> 
> # this is executed in a child proccess created by fork()
>         my $rsel = IO::Select->new($reader);
>         MAIN: while( 1 ) {
>                 print STDERR "$$: entering select...\n";
>                 () = $rsel->can_read(undef)
>                         or die "select: $!";
>                 print STDERR "$$: select returned.\n";
> 
> # The parent calls this
>         print STDERR "Sending [$cmd, $args]...\n";
>         store_fd( [$cmd, $args], $$self{writer} )
>                 or $self->serialize_error;
>         print STDERR "Sent.\n";
> 
> # Then this
>         print STDERR "Getting a $state message\n";
>         while( $status = fd_retrieve $reader ) {
>                 print STDERR "Got a message of some sort.\n";
>                 die $status->{error} if $status->{error};
>                 if( exists $status->{$state} ) {
> 
> # here's the relevant debug output:
> 6841: entering select...
> Sending [connect, ARRAY(0x405d4df4)]...
> Sent.
> Getting a connect message
> 
> And then it hangs there... can_read should return at this point, but it
> doesn't... it just sits there.

You can use a timeout or poll select if you require your program to continue 
processing when no data is present.  If that's not your problem, you're 
probably asking why you got no response and the answer is there are too many 
reasons possible to answer that without more info.

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: Sat, 25 Aug 2001 20:37:39 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: IO::Select's can_read hanging forever.
Message-Id: <3B8844D3.EA32CC50@earthlink.net>

$Bill Luebkert wrote:
[snip]
> You can use a timeout or poll select if you require your program to
> continue processing when no data is present.  If that's not your
> problem, you're probably asking why you got no response and the answer
> is there are too many reasons possible to answer that without more
> info.

If it blocks/hanges, that indicates that it thinks there isn't any data
ready.  Why would changing to a zero timeout fix that problem?  Yes,
obviously it will be able to continue, rather than stupidly sitting
there, but if it doesn't think there's data when it's a blocking select,
it will never think there's data if I change it to a non-blocking
select.

In point of fact, this particular $sel->can_read(undef) is just before a
blocking read... so it's extraneous.  But further on in the code [not
shown] I have a long running loop which I want to break out of if
$sel->can_read(0) returns a non-empty list.  If $sel->can_read(undef)
never returns, and just hangs, that seems to indicate to me that when I
call $sel->can_read(0), it will *always* return an empty list, and
*never* break out of the loop.

$sel->can_read(undef) hanging is a symptom of whatever problem I have,
not the problem itself.  I can fix the symptom by adding a timeout, but
don't know what the actual problem is, and until I do, I can't fix it.

-- 
I'm not a programmer but I play one on TV...


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

Date: 25 Aug 2001 12:26:24 -0700
From: wentzcovitch@hotmail.com (John Wentzcovitch)
Subject: Re: need help with regexp...
Message-Id: <405f748b.0108251126.3ef14ac2@posting.google.com>

larrybar@eng.auburn.edu (Larry A Barowski) wrote in message news:<76e741cc.0108250512.6034ab84@posting.google.com>...
> The full jGRASP syntax has a prefix that indicates you are
> specifying the filename and line number in that order. The
> full spec would be:
>            f1-.*IN LINE (\d+) OF (\S(?:\s*\S)*): .*
> 

Thanks Larry, and thanks also for the very nice tool you created
(Grasp).

Curiosly, altough the expression passes the test (OROMatcher), it does
not work on Jgrasp (prefix adjusted to 1f).

I ended up using successfuly:
             1f-(?:.*IN LINE (\d+) OF (\S+|[A-Z]:[^:]+):.*)

John


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

Date: Sat, 25 Aug 2001 21:04:01 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: one character at a time
Message-Id: <ui4gotc8e34ur8dquaetd2accneei20fn9@4ax.com>

Godzilla! wrote:

>$string = "my little string";

	$string = '543210';

>do
> { print substr ($string, 0, 1, ""), "¦"; }
>until (!$string);

So where's my zero?

Checking length($string) is safer.

-- 
	Bart.


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

Date: Sat, 25 Aug 2001 21:15:22 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: one character at a time
Message-Id: <3B881426.12703264@acm.org>

Ken wrote:
> I have the string "my little string".  I need to loop through and pull
> out first the 'm', then the 'y', then the ' ', then the 'l', etc.

TIMTOWTDI:

   for $ch (unpack ('C*', $string)) {
      # do whatever with $ch
   }

This is probably the most efficient option.

-- Dave Tweed


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

Date: 25 Aug 2001 16:27:26 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: one character at a time
Message-Id: <9m957u$sop$1@charity.cs.utexas.edu>

In article <ui4gotc8e34ur8dquaetd2accneei20fn9@4ax.com>,
Bart Lateur  <bart.lateur@skynet.be> wrote:
>Godzilla! wrote:
>	$string = '543210';
>
>>do
>> { print substr ($string, 0, 1, ""), "¦"; }
>>until (!$string);
>
>So where's my zero?
>
>Checking length($string) is safer.

Also, "do { } until (not $condition)" is a little goofy when you can
write "do { } while ($condition)" instead.

  - Logan
-- 
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)


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

Date: Sat, 25 Aug 2001 15:03:03 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: one character at a time
Message-Id: <3B882097.75967D96@stomp.stomp.tokyo>

Bart Lateur wrote:
 
> Godzilla! wrote:
 
> >$string = "my little string";
 
>         $string = '543210';
 
> >do
> > { print substr ($string, 0, 1, ""), "¦"; }
> >until (!$string);
 
> So where's my zero?
 
> Checking length($string) is safer.
 

Irrelevant. Your comments do not comply with
the originating author's stated parameters.

Godzilla!


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

Date: Sat, 25 Aug 2001 15:07:01 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: one character at a time
Message-Id: <3B882185.15D06073@stomp.stomp.tokyo>

Logan Shaw wrote:
 
> Bart Lateur wrote:
> >Godzilla! wrote:

> >       $string = '543210';

> >>do
> >> { print substr ($string, 0, 1, ""), "¦"; }
> >>until (!$string);

> >So where's my zero?

> >Checking length($string) is safer.
 
> Also, "do { } until (not $condition)" is a little goofy when you can
> write "do { } while ($condition)" instead.


My coding style is not yours to dictate, Adolf.


* believes Code Cops to be anal retentive annoyances *


Godzilla!


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

Date: 25 Aug 2001 17:33:30 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: one character at a time
Message-Id: <74f348f7.0108251633.38518ae8@posting.google.com>

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message news:<3B87C433.EEA3A559@stomp.stomp.tokyo>...
> Yves Orton wrote:
>  
> > Benjamin Goldberg wrote:
> > > Ken wrote:
>  
> > > my $string = "my little string";
> > > while( /(.)/gs ) {
> > >       print $1, "\n";
> > > }
>  
> > print $1."\n" while ($string=~/(.)/gs );
>  
> 
> 
> $string = "my little string";
> do
>  { print substr ($string, 0, 1, ""), "¦"; }
> until (!$string);

Hah! Zilla youve learned to benchmark and leave out the invective? 
Shocking!  Well it _is_ good to know that there is a use for your
substr() tricks somewhere isnt it?

BTW  I didnt post the code cause I thought it was efficient, I posted
it cause it fixed a minor bug in Bens code...  Did you spot it?

Oh yes as well, you dont need the do block.  You might shave a few
more milliseconds off that way... :-)

print substr ($string, 0, 1, ""), "¦" 
   until (!$string);


Yves


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

Date: 25 Aug 2001 18:26:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: open directory problem
Message-Id: <9m8qk2$rns$2@mamenchi.zrz.TU-Berlin.DE>

According to Edd <edd@texscene.com>:
> 
> I want to do a series of tasks if a particular diurectory fails to open. To

You shouldn't be opening diurectories.  It's messy :)

> do this I wrote the code below. But it generates error. Why is that? Is

It would have been helpful if you had said *what* error.

> there a way around it please?
> 
> $isitopen="YES";
> opendir (LOGDIR, "/home/../..$path") || $isitopen="NO";
                                       ^^
The "||" operator as high precedence in Perl, higher than "=".  So
this is parsed as

    ( opendir (LOGDIR, "/home/../..$path") || $isitopen) = "NO";

You can either use parentheses to regroup:

    opendir (LOGDIR, "/home/../..$path") || ( $isitopen="NO");

or (preferably) use low-precedence "or" instead:

    opendir (LOGDIR, "/home/../..$path") or $isitopen="NO";

Anno


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

Date: Sat, 25 Aug 2001 20:16:55 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: open directory problem
Message-Id: <MPG.15f209d0489d644a989698@news.onemain.com>

Jens Luedicke wrote:
> opendir (LOGDIR, "/home/../..$path") || &diropen_failed; 

Moving "do-everything-but-die()" statements to a sub does allow other code to 
be invoked if opendir() fails, but it doesn't fix the OP's lack of error-
handling.

Should be "&diropen($path)". You're assuming that $path has global scope.

> sub diropen_failed {

my $path = shift;

> 	print "$path doesn't exit" ;

[dubiously]: ...okay... why not?... :)

> 	&subroutine1;
> 	&subroutine2;
> 	# ...

die "\nCan't open directory $path: $!";

Otherwise, program flow falls through on return to wherever <LOGDIR> is going 
to be used.

> }

The OP should also fix the directory being passed to opendir().

"/home/../" resolves to "/".
That leaves: "/..$path" as the directory to open.
I somehow doubt it will open...


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

Date: 25 Aug 2001 22:36:11 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Openning a file
Message-Id: <slrn9oga32.em5.abigail@alexandra.xs4all.nl>

Tassilo v. Parseval (tassilo.parseval@post.rwth-aachen.de) wrote on
MMCMXIV September MCMXCIII in <URL:news:3b85838c.3097690@news.rwth-aachen.de>:
[] 
[] As for what Abigail said about no lists in scalar context, I admit it
[] is the first time I would not instantly agree with her. I do, however,
[] understand what I confused in my post which she was referring to. But
[] in my understanding there can be lists in scalar context.

Perhaps there can be. You know, in a debate "no, it can't", "yes, it can",
the person argueing the "yes, it can" case has a real big advantage over
the "no, it can't" person.

All the person needs to do is come with an example. Just one.

I'm waiting.



Abigail
-- 
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_=sub{print/::(.*)/};
$\=$/;q<Just another Perl Hacker>->();


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

Date: Sun, 26 Aug 2001 00:44:07 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Openning a file
Message-Id: <3B882A37.70806@post.rwth-aachen.de>

Abigail wrote:

[lists allegedly in scalar context]

> Perhaps there can be. You know, in a debate "no, it can't", "yes, it can",
> the person argueing the "yes, it can" case has a real big advantage over
> the "no, it can't" person.
> 
> All the person needs to do is come with an example. Just one.
> 
> I'm waiting.

Well, there was this qw() example. You can assign that to a scalar 
variable. This eventually assigns the last element of this list to this 
variable. But, alas, I am no longer so sure about it whether one could 
call this scalar context after flicking through some perldocs and doing 
some quick tests.

But, as for what you said about people saying "no, it can't" and those 
stating "yes, it can", I do know about this phenomenon. That's why I 
usually try to find moderate words. It is much harder to contradict to 
those. ;-)

Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: 25 Aug 2001 22:30:33 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Performance : Shell X Perl
Message-Id: <slrn9og9oh.em5.abigail@alexandra.xs4all.nl>

Brian Cantin (bcc@eswssol001.elsegundoca.ncr.com) wrote on MMCMXV
September MCMXCIII in <URL:news:7nlmk9tmzb.fsf@eswssol001.elsegundoca.ncr.com>:
== mjd@plover.com (Mark Jason Dominus) writes:
== > In my experience it's a lot easier to write a portable Perl program
== > than a portable shell script.  In 1995 you might have had to worry
== > that the target system didn't have Perl, but these days Perl is almost
== > everywhere.
== 
== True, Perl is available nearly everywhere, but it may not be the same
== version.  I run into problems all the time with machines running 5.001
== on scripts that were coded and tested against later versions.  The
== Bourne shell and the UNIX toolkit definition is pretty much static, so
== it is easier to test on a bunch of different platforms and assure
== things will run.

*Which* Unix toolkit definition are you talking about? That's the problem
- there are many "standards" for the Unix toolkit definitions. Big vendors
like HP and SUN have to problem committing themselves to standards, too
bad they don't always agree to take the same one. And on top of that,
tools for Linux at best follow a POSIX standard, but not always.

And for Windows, you have to depend on some Unix toolkit to be installed
- that doesn't come with the OS.

== So, pick your poison: the ever changing virtual machine that Perl
== provides versus the relatively static but platform dependent UNIX
== toolkit.  However, if you have to support something as impoverished as
== NT, you are definitely better off with Perl.

So, which tool from the "Unix toolkit" are you going to use to open a
socket, or to lock a file?



Abigail
-- 
sub A::TIESCALAR{bless\my$x=>A};package B;@q[0..3]=qw/Hacker Perl
Another Just/;use overload'""'=>sub{pop @q};sub A::FETCH{bless\my
$y=>B}; tie my $shoe => qq 'A';print "$shoe $shoe $shoe $shoe\n";


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

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


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