[25595] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7839 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 28 14:05:42 2005

Date: Mon, 28 Feb 2005 11:05:20 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 28 Feb 2005     Volume: 10 Number: 7839

Today's topics:
        can someone help? <lie_huo@hotmail.com>
    Re: can someone help? <alexj@floor.ch>
    Re: can someone help? <mritty@gmail.com>
    Re: can someone help? <phaylon@dunkelheit.at>
    Re: can someone help? <noreply@gunnar.cc>
    Re: can someone help? <matternc@comcast.net>
    Re: cannot open and write file <lie_huo@hotmail.com>
    Re: cannot open and write file <mritty@gmail.com>
    Re: cannot open and write file <lawshouse.public@btconnect.com>
    Re: cannot open and write file <matternc@comcast.net>
    Re: CGI System Call in perl <ganchrow@gmail.com>
    Re: dynamic update <jgibson@mail.arc.nasa.gov>
        Encoding "deflate" -- how to handle? [WWW, client-side] <bantu@SKASUJTOpoczta.FM>
    Re: How to tell if a subroutine arg is a constant <tony@skelding.co.uk>
    Re: maximum size of a hash table <postmaster@castleamber.com>
    Re: maximum size of a hash table <postmaster@castleamber.com>
        NEED MONEY FOR FAMILY MATTERS <mlescault91967@aol.com>
    Re: newbie: Perl IDE available?? <lawrence.tierney@bipcontracts.com>
    Re: Performance questions (SQL-statements) <emschwar@pobox.com>
    Re: Performance questions (SQL-statements) <emschwar@pobox.com>
    Re: Perl Hash problem (with registry) <ThomasKratz@REMOVEwebCAPS.de>
    Re: sequences of numbers (Anno Siegel)
        system (date) in perl <alexj@floor.ch>
    Re: system (date) in perl <mritty@gmail.com>
    Re: thread trouble <matternc@comcast.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 28 Feb 2005 11:14:56 -0500
From: "Roll" <lie_huo@hotmail.com>
Subject: can someone help?
Message-Id: <fd125ce70c8f9c657fca771c9f5ce376@localhost.talkaboutprogramming.com>

#!/usr/bin/perl
use warnings;
use strict;
my $out = '/root/a.conf';
open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
print OUTF "anc";
close OUTF or die "Cannot close $out:$!";

how come when i use this code i got a 500 internal server error ? how do i
solve this?



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

Date: Mon, 28 Feb 2005 17:16:06 +0100
From: Alexandre Jaquet <alexj@floor.ch>
Subject: Re: can someone help?
Message-Id: <cvvg40$ga8$2@news.hispeed.ch>

Roll a écrit :
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $out = '/root/a.conf';
> open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
> print OUTF "anc";
> close OUTF or die "Cannot close $out:$!";
> 
> how come when i use this code i got a 500 internal server error ? how do i
> solve this?
> 
  check out the rigth with ls -al


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

Date: Mon, 28 Feb 2005 16:33:12 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: can someone help?
Message-Id: <cJHUd.72927$g16.47449@trndny08>

"Roll" <lie_huo@hotmail.com> wrote in message
news:fd125ce70c8f9c657fca771c9f5ce376@localhost.talkaboutprogramming.com...
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $out = '/root/a.conf';
> open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
> print OUTF "anc";
> close OUTF or die "Cannot close $out:$!";
>
> how come when i use this code i got a 500 internal server error ? how
do i
> solve this?

1) Put the subject of your post in the Subject of your post
2) Do not post the same message twice within minutes of each other.
Usenet messages take time to propogate.

Paul Lalli




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

Date: Mon, 28 Feb 2005 17:49:48 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: can someone help?
Message-Id: <pan.2005.02.28.16.49.48.24883@dunkelheit.at>

Roll wrote:

> how come when i use this code i got a 500 internal server error ? how do i
> solve this?

Look in your Webserver-logs for the real error.

-- 
http://www.dunkelheit.at/
codito, ergo sum.



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

Date: Mon, 28 Feb 2005 17:59:12 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: can someone help?
Message-Id: <38h0s7F5ot0qmU1@individual.net>

Roll wrote:
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $out = '/root/a.conf';
> open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
> print OUTF "anc";
> close OUTF or die "Cannot close $out:$!";
> 
> how come when i use this code i got a 500 internal server error ? how do i
> solve this?

Study a beginners tutorial for CGI scripts.

http://cgi.resourceindex.com/Documentation/CGI_Tutorials/

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Mon, 28 Feb 2005 14:02:24 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: can someone help?
Message-Id: <erudncPlX7Zd977fRVn-3g@comcast.com>

Roll wrote:

> #!/usr/bin/perl
> use warnings;
> use strict;
> my $out = '/root/a.conf';
> open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
> print OUTF "anc";
> close OUTF or die "Cannot close $out:$!";
> 
> how come when i use this code i got a 500 internal server error ? how do i
> solve this?

What, because somebody didn't reply in four minutes, it
wasn't fast enough for you?
-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: Mon, 28 Feb 2005 11:10:21 -0500
From: "Roll" <lie_huo@hotmail.com>
Subject: Re: cannot open and write file
Message-Id: <19a31f769d44ebd64678206b3ab4ebf1@localhost.talkaboutprogramming.com>

#!/usr/bin/perl
use warnings;
use strict;
my $out = '/root/a.conf';
open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
print OUTF "anc";
close OUTF or die "Cannot close $out:$!";

can someone tell me how come after typing this code i got a 500 internal
server error ??
how do i solve this?



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

Date: Mon, 28 Feb 2005 16:29:51 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: cannot open and write file
Message-Id: <3GHUd.41506$s16.31701@trndny02>

"Roll" <lie_huo@hotmail.com> wrote in message
news:19a31f769d44ebd64678206b3ab4ebf1@localhost.talkaboutprogramming.com...
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $out = '/root/a.conf';
> open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
> print OUTF "anc";
> close OUTF or die "Cannot close $out:$!";
>
> can someone tell me how come after typing this code i got a 500
internal
> server error ??
> how do i solve this?

Have you read
perldoc -q 500
?

More specifically, have you actually read the entire message you
receive?  The bit that tells you to check your server logs for the
error?  Have you done this?

Paul Lalli




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

Date: Mon, 28 Feb 2005 18:29:32 +0000
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: cannot open and write file
Message-Id: <ujo6211bt1d112asbiv3qn5gqkq9ecpqgo@4ax.com>

On Mon, 28 Feb 2005 11:10:21 -0500, "Roll" <lie_huo@hotmail.com>
wrote:

>#!/usr/bin/perl
>use warnings;
>use strict;
>my $out = '/root/a.conf';
>open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
>print OUTF "anc";
>close OUTF or die "Cannot close $out:$!";
>
>can someone tell me how come after typing this code i got a 500 internal
>server error ??

This code works fine for me; it writes the line "anc" onto the end of
the file named in $out (I changed it to something that made sense on
my Windows machine).

F:\WIP>type test.pl
#!/usr/bin/perl
use warnings;
use strict;
my $out = 'F:\\WIP\\a.conf';
open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
print OUTF "anc";
close OUTF or die "Cannot close $out:$!";
F:\WIP>test.pl

F:\WIP>type a.conf
**
ancanc
F:\WIP>

I dont see the problem.


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

Date: Mon, 28 Feb 2005 14:01:36 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: cannot open and write file
Message-Id: <erudncDlX7YN977fRVn-3g@comcast.com>

Henry Law wrote:

> On Mon, 28 Feb 2005 11:10:21 -0500, "Roll" <lie_huo@hotmail.com>
> wrote:
> 
>>#!/usr/bin/perl
>>use warnings;
>>use strict;
>>my $out = '/root/a.conf';
>>open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
>>print OUTF "anc";
>>close OUTF or die "Cannot close $out:$!";
>>
>>can someone tell me how come after typing this code i got a 500 internal
>>server error ??
> 
> This code works fine for me; it writes the line "anc" onto the end of
> the file named in $out (I changed it to something that made sense on
> my Windows machine).
> 
> F:\WIP>type test.pl
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $out = 'F:\\WIP\\a.conf';
> open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
> print OUTF "anc";
> close OUTF or die "Cannot close $out:$!";
> F:\WIP>test.pl
> 
> F:\WIP>type a.conf
> **
> ancanc
> F:\WIP>
> 
> I dont see the problem.

Henry is being a bit cruel, but his point is accurate, if you
understand it.  There is nothing wrong with your Perl code;
it does what you want it to do.  The problem is what you
didn't see fit to tell us, namely, that you're running 
this via CGI.  And your problem is with your CGI, not your
Perl.
-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: 28 Feb 2005 07:51:49 -0800
From: "Ganchrow Harris Peck" <ganchrow@gmail.com>
Subject: Re: CGI System Call in perl
Message-Id: <1109605909.282203.175460@o13g2000cwo.googlegroups.com>

Thanks for your reply, Greg. For my purposes the following BEGIN block
added to my child process worked just fine:

# start code sample
BEGIN {
	if ( (defined $ARGV[0]) and ($ARGV[0] =~ m/-?cgi$/i) ) {
		# program was called from cgi script
		# so close out out buffer to let cgi script terminate
		close STDOUT;
	}
}
# end code sample

Of course this necessitated both being able to call the child from the
parent with the -cgi switch as the first arg and furthermore not caring
that any data sent to STDOUT by the child would be discarded.

Worked fine even if inelegantly.


GHP.



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

Date: Mon, 28 Feb 2005 10:26:06 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: dynamic update
Message-Id: <280220051026067376%jgibson@mail.arc.nasa.gov>

In article <1109459340.628463.47660@g14g2000cwa.googlegroups.com>,
<enigma261@yahoo.com> wrote:

> Hi,
> 
> I am trying to accomplish the following ...
> I have a form via which I want to execute 10 tasks (processes)
> The 10 processes are execute sequentially.
> 
> I want the web page to reflect the status as each task is being run ..
> For Ex...
> 
> Task 1 : Running ...
> Task 2 : Waiting launch
> .
> .
> .
> .
> 
> And, the status will change depending on the current status of the
> task.

Check out Randal's article in Linux Magazine on this topic:

http://www.stonehenge.com/merlyn/LinuxMag/col39.html

(This seems to be a frequently-asked question these days.)


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


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

Date: Mon, 28 Feb 2005 14:54:35 +0100
From: Maciej Pilichowski <bantu@SKASUJTOpoczta.FM>
Subject: Encoding "deflate" -- how to handle? [WWW, client-side]
Message-Id: <k98621d2j0fnuk6fn287n79if2be7umnq4@4ax.com>

Hello,

  I am fetching some WWW pages via LWP::UserAgent with Accept-Encoding
set to "gzip, deflate". When the page is uncompressed
/content_encoding not defined/ I just get the content, when the
content_encoding is set to "gzip" I use Compress::Zlib::memGunzip, but
what should I do when content_encoding is set to "deflate"?
  I tried to use "uncompress" method but it didn't work.

  Any ideas?

have a nice day
bye

PS. Yes, I looked for the answer at Google but all I found was
handling "gzip".

-- 
Maciej "MACiAS" Pilichowski                     http://bantu.fm.interia.pl/

               M A R G O T   -->   http://www.margot.cad.pl/
     automatyczny t³umacz (wczesna wersja rozwojowa) angielsko-polski


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

Date: 28 Feb 2005 07:21:02 -0800
From: "Mintcake" <tony@skelding.co.uk>
Subject: Re: How to tell if a subroutine arg is a constant
Message-Id: <1109604062.772544.146560@f14g2000cwb.googlegroups.com>

If the caller wanted to pass -abc as a variable (as in your example)
then it wold be treated as such.  What would not be allowed is if the
caller did not want the -abc to to be treated as a special case - in
which case simply not accidently passing -abc as a literal should do
the trick.  What I'm saying is that -abc would only be treated as a
special case if it was coded as a literal - and that is entirely under
the programmers control.



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

Date: 28 Feb 2005 18:19:26 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: maximum size of a hash table
Message-Id: <Xns960B7D5BE6673castleamber@130.133.1.4>

Sherm Pendley wrote:

> John Bokma wrote:
> 
>> Sherm Pendley wrote:
>> 
>>> That's not the result of having a lot of *data* - it's the result of
>>> having a lot of *collisions*.
>> 
>> Caused by a lot of data.
> 
> Is too... Is not... Is too... Is not! :-)

It is. I was talking about a situation that a hash table that hashes to 
32 bit values can stop being efficient by a lot of data which cause too 
many collisions.

Of course there are situations that you can cause a lot of collisions by 
putting the "right" data into a hash table, but that's not what I was 
talking about.

> As I (mis?)understand it, the size of a list - *in and of itself* -
> does not cause collisions. Perl's hash codes are native ints. The
> exact width varies with architecture, but it's always wide enough to
> assign a unique code to each and every byte of memory.

That was originally unclear, I pinned it at 32 bits, always (but 
remarked that I didn't know if this was the case). And if that was the 
case (which it was not) *then* it is possible to reach the limits of a 
hash table with enough data, at least to me. A hash table that doesn't 
do O(1) look ups is to me not a useful one.

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: 28 Feb 2005 18:32:49 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: maximum size of a hash table
Message-Id: <Xns960B7FA18630Fcastleamber@130.133.1.4>

Anno Siegel wrote:

> John Bokma  <postmaster@castleamber.com> wrote in comp.lang.perl.misc:
>> Anno Siegel wrote:
>> 
>> > John Bokma  <postmaster@castleamber.com> wrote in
>> > comp.lang.perl.misc: 
>> >> Anno Siegel wrote:
>> >> 
>> >> > John Bokma  <postmaster@castleamber.com> wrote in
>> >> > comp.lang.perl.misc: 
>> >> >> Anno Siegel wrote:
>> >> >> 
>> >> >> > John Bokma  <postmaster@castleamber.com> wrote in
>> >> >> > comp.lang.perl.misc: 
>> > 
>> > [hashes]
>> > 
>> >> >> I am happy with constant avg length of c, and hence O(1) look
>> >> >> up. 
>> >> > 
>> >> > Fine.  My point is that there are useful applications of hash
>> >> > tables also in the O(n) range.
>> >> 
>> >> Uhm, like? (Ok, memory stress testing is one).
>> > 
>> > It's a simple space/time tradeoff.  You only get constant access
>> > time when collisions are rare, so the number of buckets must be
>> > larger than the number of keys.
>> 
>> All depends on the hash function of course, but if the size is big
>> (n) and the number of collisions is small (constant), you still have
>> O(1) access. 
> 
> Collisions *can't* be rare when the number of keys exceeds the number
> of buckets, no matter what the hash function.

You wrote (see above): that "the number of buckets must be larger than
the number of keys" to make collisions rare. With perfect hashing you
can hash n elements in n slots without having any collision. 

Moreover, it is possible to have relatively a lot of collision and still
have O(1) look up. As long as the average number of collisions is a
(small) constant wrt n, the look up is O(n). 

>> > Say you expect a million keys and linear search
>> > is too slow by a factor of 100.  Use a hash with 100 buckets (some
>> > more to compensate overhead).
>> 
>> It all depends on what you want. If linear search is slow, and you
>> need a lot of access it might be way smarter to sort ( O(n log n) )
>> and use binary search for the look ups ( O( log n ) ). 
>>
>> With 100 buckets you get 100 lists of 10,000 items each. So it takes
>> average 5,000 steps to find something. 
>> 
>> Compare that with binary search :-D.
> 
> You must keep the list sorted. When insertions and/or deletions are
> frequent, you lose the advantage.

search, insertion and deletion are all O(log n). ( at most 20 steps )

Your proposal has O(n) look up (5,000 steps avg), O(1) insertion, and
O(n) deletion (of a specific element, since you have to look it up
first, 5,000 steps avg, otherwise O(1)). 

Technically you are using a hash table with 100 buckets, each bucket
containing a list. Implementing it that way, and sorting each list would
give a major speed up (max 14 steps to find an item with binary search,
max 14 steps for insert/delete). [1] 

> What's the point?  I'm not saying that hashes with large load factors
> are a super trick that solves everything.  They can be, and have been
> used that way. You asked for an example.

I can't think of any advantage of an O(n) look up hash table, it works
like an unsorted list, see above. 

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Mon, 28 Feb 2005 11:29:29 -0500
From: "mike" <mlescault91967@aol.com>
Subject: NEED MONEY FOR FAMILY MATTERS
Message-Id: <cvvh5r$2q5s@bee.cs.kiev.ua>

HI
I WAS A MARINE MECHANIC working boat engines for 20 years and now I have
started making money for the rest of my life after i got into my own business
but I wish I had started many years ago, check it out for yourself
you'll be HAPPY you did. This site changed my life and my families
and it will change yours.

COPY AND PAST THIS SITE
http://www.mach90.com/pre.asp?username=mad4701


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

Date: Mon, 28 Feb 2005 16:48:11 GMT
From: "Lord0" <lawrence.tierney@bipcontracts.com>
Subject: Re: newbie: Perl IDE available??
Message-Id: <fXHUd.1657$Pl5.648@newsfe5-gui.ntli.net>

You could have a look at Kimodo (www.activestate.com) , Perl Builder 
(www.solutionsoft.com) and PerlEdit (www.indigostar.com) . I've used them 
all with varying degrees of satisfaction. BTW 
http://www.google.co.uk/search?hl=en&q=perl+ide&btnG=Google+Search&meta=

Lord0 




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

Date: Mon, 28 Feb 2005 11:46:15 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Performance questions (SQL-statements)
Message-Id: <etopsyk5xqg.fsf@wilson.emschwar>

Sherm Pendley <spamtrap@dot-app.org> writes:
> Piet L. wrote:
>> Also a question extra, Should I use CGI or isn't this neccessary?
>
> Ask your users. Do they want a web interface where they can fill in a form?
> If so, that means CGI.

There's always Apache::Request under mod_perl, which isn't CGI.  But
for what's going on here, yeah, that's probably the way to do it.

However, if the OP *was* doing mod_perl, then the output of any
long-running process could be cached in memory (this could become
potentially expensive, space-wise, though).

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Mon, 28 Feb 2005 11:48:47 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Performance questions (SQL-statements)
Message-Id: <etoll985xm8.fsf@wilson.emschwar>

xhoster@gmail.com writes:
> PietLaroy@hotmail.com (Piet L.) wrote:
>>         The query is:
>>         "SELECT b.*, ba.* from book b, book_author ba
>>          LEFT JOIN list_authors l
>>          ON ba.person_id = l.person_id
>>          WHERE b.book_id = ba.book_id
>>          AND ba.person_id = 124"
>
> Almost never should you use b.* notation in production code.  Spell
> out the columns that you want.

Oh yeah.  This gives you two things:

1) Saves time if one of the extra columns returned happens to be, say,
   a BLOB containing a JPG of the author.
2) Lets you confidently index by column number in the returned row(s).

> Why do you think the left join is necessary?  Indeed, why is any join
> against list_authors necessary when you never retrieve any of the fields
> on that table?

Look closer-- list_authors is aliased to 'l', which is matched to
ba.person_id.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Mon, 28 Feb 2005 18:50:02 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Perl Hash problem (with registry)
Message-Id: <422359cd$0$18089$bb690d87@news.main-rheiner.de>

thomasjbs@gmail.com wrote:
> Peter Wyzl wrote:
>>: use Win32::Registry;
>>
>>The docs say this is an obsolete module, use Win32::TieRegistry
> 
> instead...
> 
> I tried TieRegistry first, but I could not find any working examples
> (even the examples in the documentation failed.)

They should not. But I agree: it takes some time to get used to it.

Here is a much shorter example to achieve this task with Win32::TieRegistry:

use strict;
use warnings;

use Win32::TieRegistry(Delimiter => '/');

my $key = 'LMachine/Software/Microsoft/Windows/CurrentVersion/Uninstall';

foreach my $subkey ( keys(%{$Registry->{$key}}) ) {
    # beware: $subkey comes with a trailing slash
    my $name = $Registry->{"$key/$subkey/DisplayName"} || 'no name found';
    print "$name\n";
}

Thomas

-- 
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-


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

Date: 28 Feb 2005 13:42:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sequences of numbers
Message-Id: <cvv745$rut$1@mamenchi.zrz.TU-Berlin.DE>

Big Daddy  <ihatespam@hotmail.com> wrote in comp.lang.perl.misc:
> Well, no offense, but I thought the original post was quite clear. I 

Clear?

You gave us a problem, we solved it.  Then you come back and tell us
it wasn't your real problem, would we please solve another.  Not what
I call a clear description.

> obviously thought the problem was complex, hence the posting. The solution 
> provided doesn't work. Here's why:

It does work with your original data.

> Try it on this:
> 
> $array[0] = ("-10 10 30 30 30 30");
> $array[1] = ("-10 -10 -10 -10 20 30");
> $array[2] = ("-12 2 2 2 20 30");
> $array[3] = ("10 20 30");
> 
> Then, 
> 
> @stack = map{chop;$_} grep !/\b(\d+ )\1{3}\b/,map "$_", @array;
> 
> will yield @stack with 2 elements still.
> 
> I do understand the above, I couldn't figure out how to modify it to work 
> properly.

No, you don't understand it.  Your rendition above is broken.

> The regular expression /\b(\d+ )\1{3}\b/ only works provided there is a 
> space after the digit, which isn't the case for the last number in the 
> string.

That's what the part you broke is taking care of.

> I never depicted a space after the last number in each string in 
> the original post and it isn't trivial (at least for me) how to modify this 
> to work when it is possible that the repeated number in the string could 
> occur over the last four numbers of the string.
> 
> In other words, if the solution was trivial, someone would have figured it 
> out by now, and they haven't.

We haven't had much time to look at your real problem, have we?

> In fact, your idea of using a non-whitespace 
> character doesn't appear to work either. So please don't flame me for 
> posting a question which has clearly been very difficult for even the best 
> Perl programmers in the world to figure out.

It isn't hard at all when you're not trying to come up with a one-liner.

If a problem is too complex to solve in one go, break it down:

    my @stack = grep ! has_long_const_seq( $_, 3), @array;

Now take your time and space to come up with a function
has_long_const_seq() that checks if the number of consecutive elements
in the first argument exceeds the second one.  That's a rather
straight-forward application of split and a counting loop:

    sub has_long_const_seq {
        my ( $str, $max) = @_;
        my $count = 1;
        my ( $last, @rest) = split ' ', $str;
        for ( @rest ) {
            if ( $_ eq $last ) {
                ++ $count <= $max or return 1;
            } else {
                $last = $_;
                $count = 1;
            }
        }
        0;
    }

The regex-only solution (which may still be possible) only looked
attractive because of your over-simplified problem description.

Anno



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

Date: Mon, 28 Feb 2005 17:11:25 +0100
From: Alexandre Jaquet <alexj@floor.ch>
Subject: system (date) in perl
Message-Id: <cvvfr7$ga8$1@news.hispeed.ch>

Hi I can't find why I'm getting Bad file descriptor when I use :

my $time_start = system "date \"+%H:%M:%S\"";
warn "date \"+%H:%M:%S\""; --> date "+%H:%M:%S"

thx


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

Date: Mon, 28 Feb 2005 16:33:08 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: system (date) in perl
Message-Id: <8JHUd.72926$g16.27107@trndny08>

"Alexandre Jaquet" <alexj@floor.ch> wrote in message
news:cvvfr7$ga8$1@news.hispeed.ch...
> Hi I can't find why I'm getting Bad file descriptor when I use :
>
> my $time_start = system "date \"+%H:%M:%S\"";
> warn "date \"+%H:%M:%S\""; --> date "+%H:%M:%S"

Unquoted string "date" may clash with future reserved word at - line 2.
String found where operator expected at - line 2, near "date
"+%H:%M:%S""
        (Do you need to predeclare date?)

1) Post real code.
2) Even after removing what appears to be your pseudo code for a
comment, I do not get any messages about a "bad file descriptor".
Therefore, your problem lies elswhere.  Please post a short *but
complete* program that exhibits this problem.  (Have you read the
Posting Guidelines that are posted here twice weekly?)

Paul Lalli



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

Date: Mon, 28 Feb 2005 06:49:01 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: thread trouble
Message-Id: <qqKdnY7oRN6wmL7fRVn-hQ@comcast.com>

Alexandre Jaquet wrote:

> 
> I checked perl -V and got :
> 
> ummary of my perl5 (revision 5 version 8 subversion 6) configuration:
> ...
>   -Dusethreads=n - is that the problem ?

Uh, yah.  Perl has to be compiled to use threads or it can't.  Your
perl isn't compiled to use threads.  You're going to need to build
a new instance of perl with threads enabled if you want to use threads.

-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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