[30532] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1775 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 6 21:09:47 2008

Date: Wed, 6 Aug 2008 18:09:12 -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           Wed, 6 Aug 2008     Volume: 11 Number: 1775

Today's topics:
    Re: a weird problem <someone@example.com>
    Re: a weird problem <m@rtij.nl.invlalid>
    Re: CLPM - a help group? <worrall+unet@cs.bris.ac.uk>
    Re: CLPM - a help group? <worrall+unet@cs.bris.ac.uk>
    Re: FAQ 6.4 How do I match XML, HTML, or other nasty, u <jimsgibson@gmail.com>
    Re: FAQ 6.4 How do I match XML, HTML, or other nasty, u <brian.d.foy@gmail.com>
    Re: How to check for filetype existence quickly <calvin.chan.cch@gmail.com>
    Re: How to flush STDIN with getc()? <usenet@larseighner.com>
    Re: How to flush STDIN with getc()? <ben@morrow.me.uk>
    Re: How to flush STDIN with getc()? <someone@example.com>
    Re: How to flush STDIN with getc()? <usenet@larseighner.com>
    Re: How to flush STDIN with getc()? <someone@example.com>
    Re: Perl distributed as one all-inclusive Windows binar <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 06 Aug 2008 18:12:29 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: a weird problem
Message-Id: <hQlmk.116696$kx.106177@pd7urf3no>

Zhiliang Hu wrote:
> I have a perl script that takes a while to run.  I inserted a few
> lines in the program to print some progress messages to the console
> (STDOUT) so I know where it is at, like:
> 
> #!/usr/bin/perl
> print STDOUT "Please wait "; #-- This is the very first line in the
> script
> open(FILE,">localfile");
> use DBI;
> $dbh = DBI->connect("dbi:mysql:.....");
> #-- omitted lines: query and fetch etc.
> while (@content = $query_a->fetchrow_array) {
>       #-- some nested stuff omitted, etc etc
>       print FILE "--some stuff...\n";
>       print STDOUT  "...";
> }
> print STDOUT  "done\n";
> $dbh->disconnect;
> close(FILE);
> 
> But it prints out nothing to the screen until the very end, when it
> finishes, it dumps all for STDOUT at once to the screen.  The other
> parts of the program runs fine.  I thought I have used similar schemes
> some years ago and it worked nicely but I cannot see what's wrong
> here.  Something new on perl 5.8.x or what else could be the cause?

Either use STDERR instead of STDOUT or use autoflush on the STDOUT 
filehandle.



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Wed, 6 Aug 2008 23:54:02 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: a weird problem
Message-Id: <pan.2008.08.06.21.54.02@rtij.nl.invlalid>

On Wed, 06 Aug 2008 10:49:04 -0700, Zhiliang Hu wrote:

> I have a perl script that takes a while to run.  I inserted a few lines
> in the program to print some progress messages to the console (STDOUT)
> so I know where it is at, like:
> 
(snip)
> 
> But it prints out nothing to the screen until the very end, when it
> finishes, it dumps all for STDOUT at once to the screen.  The other
> parts of the program runs fine.  I thought I have used similar schemes
> some years ago and it worked nicely but I cannot see what's wrong here. 
> Something new on perl 5.8.x or what else could be the cause?

Try:

$|=1; # make pipes hot

See perldoc perlvar.

HTH,
M4


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

Date: Wed, 06 Aug 2008 17:25:38 -0700
From: Adam Worrall <worrall+unet@cs.bris.ac.uk>
Subject: Re: CLPM - a help group?
Message-Id: <hgrmk.19322$Ri.571@flpi146.ffdc.sbc.com>

RedGrittyBrick wrote:
> Adam Worrall wrote:
>> Michael Carman wrote:
>>> Adam Worrall wrote:
>>>> Yes I meant 'help desk', but you are wrong in assuming that a 'help 
>>>> desk' always has to be a formal service for customers. There are, in 
>>>> fact, many volunteer-run help desk, and this newsgroup, like many 
>>>> others, functions as exactly that. People volunteer their time to 
>>>> _help_ others.
>>>
>>> I believe that the aversion to calling c.l.p.misc a "help desk" is 
>>> because that term carries a connotation that the purpose of the group 
>>> is to provide a service where someone will solve your problem for 
>>> you. The regular contributors to this group are, on the whole, very 
>>> resistant to that idea. "RTFM. What have you tried? Show us your code."
>>>
>>> nobull phrased it very well:
>>>
>>>   "Get real! This is a discussion group, not a helpdesk. You post
>>>    something, we discuss its implications. If the discussion happens
>>>    to answer a question you've asked, that's incidental."
>>>
>>> The purpose of the group is to discuss Perl: it's strengths, 
>>> weaknesses, idioms, quirks, dusty corners, etc. The asking and 
>>> answering of questions are merely a mechanism by which discussion 
>>> topics are identified.
>>
>> I understand what you are saying, but it still doesn't answer my 
>> question: who exactly gets to decide what is and isn't acceptable for 
>> everyone in a news group? AKAIK, no one simple person can claim 
>> ownership of a news group, so telling someone something along the 
>> lines of "this is not a help desk" is legislating your own beliefs, 
>> which is contrary to what Usenet is and how it works (at least in 
>> terms of open non-moderated groups.)
> 
> If I said "comp.lang.perl.misc is not a place for discussing pet 
> allergies" would I be legislating my own belief?

No you would obviously be wrong, as the charter clearly states that this 
group is for all things Perl and discussions of "pet allergies" is 
clearly off topic. But that is no where near the same as saying "this is 
not a help desk" which is a personal view that is not something the 
charter (for this or it's predecessor group) had written.

> If I were to say "comp.lang.perl.misc is not a help desk" I would be 
> merely stating my opinion on the consensus view (as observed by me) of 
> the main participants as to how they choose to participate and comparing 
> that consensus with a scenario in which people are employed (paid) to 
> answer customer enquiries.

You're assuming the consensus (as in everyone's opinion) is in agreeance 
to what you are saying, and that is something you cannot really confirm. 
further more, stop perpetuating the the false view that all help desks 
are for paid organizations, as plenty are volunteer-run and many are 
non-profit.

> When I say "the sky is blue" it is an observation, I am not legislating 
> what the sky may or may not do.

But it is a known fact that the sky is blue, which is different than a 
handful of people telling you that a group shouldn't be used in a why 
_they_ don't happen to approve of.


   - Adam


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

Date: Wed, 06 Aug 2008 17:28:11 -0700
From: Adam Worrall <worrall+unet@cs.bris.ac.uk>
Subject: Re: CLPM - a help group?
Message-Id: <Girmk.19323$Ri.16261@flpi146.ffdc.sbc.com>

brian d foy wrote:
> In article <vvbmk.16412$xZ.9861@nlpi070.nbdc.sbc.com>, Adam Worrall
> <worrall+unet@cs.bris.ac.uk> wrote:
> 
>> I understand what you are saying, but it still doesn't answer my 
>> question: who exactly gets to decide what is and isn't acceptable for 
>> everyone in a news group?
> 
> The charter decides that. Beyond that, there is no clpm police that
> gets to decide. So, post whatever Perl stuff you like.
> 
> This still isn't a help desk, but I'm usually happy to help people when
> I can. :)

No disrespect intended, but I don't think you've ever spent any time on 
a volunteer-run help desk before. Oh wait, you post in clpm :)

   - Adam


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

Date: Wed, 06 Aug 2008 15:15:16 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: FAQ 6.4 How do I match XML, HTML, or other nasty, ugly things with a regex?
Message-Id: <060820081515161737%jimsgibson@gmail.com>

In article <649pm5-52n.ln1@blue.stonehenge.com>, PerlFAQ Server
<brian@stonehenge.com> wrote:

> This is an excerpt from the latest version perlfaq6.pod, which
> comes with the standard Perl distribution. These postings aim to 
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is at http://faq.perl.org .
> 
> --------------------------------------------------------------------
> 
> 6.4: How do I match XML, HTML, or other nasty, ugly things with a regex?
> 
>      
> 
>     (contributed by brian d foy)
> 
>     If you just want to get work done, use a module and forget about the
>     regular expressions. The "XML::Parser" and "HTML::Parser" modules are
>     good starts, although each namespace has other parsing modules
>     specialized for certain tasks and different ways of doing it. Start at
>     CPAN Search ( http://search.cpan.org ) and wonder at all the work people
>     have done for you already! :)
> 
>     The problem with things such as XML is that they have balanced text
>     containing multiple levels of balanced text, but sometimes it isn't
>     balanced text, as in an empty tag ("<br/", for instance). Even then,

The closing '>' character is missing from the above line in my news
reader display.

-- 
Jim Gibson


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

Date: Wed, 06 Aug 2008 18:57:30 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 6.4 How do I match XML, HTML, or other nasty, ugly things with a regex?
Message-Id: <060820081857302980%brian.d.foy@gmail.com>

In article <060820081515161737%jimsgibson@gmail.com>, Jim Gibson
<jimsgibson@gmail.com> wrote:

> >     The problem with things such as XML is that they have balanced text
> >     containing multiple levels of balanced text, but sometimes it isn't
> >     balanced text, as in an empty tag ("<br/", for instance). Even then,
> 
> The closing '>' character is missing from the above line in my news
> reader display.

Fixed, thanks,


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

Date: Wed, 6 Aug 2008 15:31:20 -0700 (PDT)
From: cc96ai <calvin.chan.cch@gmail.com>
Subject: Re: How to check for filetype existence quickly
Message-Id: <3290457f-ab34-427f-8fe7-1d3269f22e4c@w24g2000prd.googlegroups.com>

if you have sub-directory,
you could use find ()

find(\&listfile, $dir);

sub listfile(){

    if ( -f ) {
		my($filename, $directories, $suffix) =3D fileparse($File::Find::name);
		#check extension
=2E....
	}
}

On Aug 6, 8:56=A0am, xhos...@gmail.com wrote:
> fidokomik <fidoko...@gmail.com> wrote:
> > I have directory, say "c:\documents" on Windows or "/home/petr/
> > documents" on Linux. In this directory many files are stored with many
> > filetypes (extensions), say *.doc, *.txt, *.zip. I need to find fastes
> > way how to check if some filetype exist.
>
> You will have to write a file system that is optimized for this (for
> example, it stores directory information in some kind of tree based on th=
e
> reversed file name, so that extensions group together.) =A0Then you have =
to
> hack the operating system so that it can take advantage of the FS feature=
s.
> Then you would have to hack perl so that it can take advantage of the OS
> features.
>
> Personally, I think I'd settle for something other than the fastest, and
> just aim for good enough.
>
> Xho
>
> --
> --------------------http://NewsReader.Com/--------------------
> The costs of publication of this article were defrayed in part by the
> payment of page charges. This article must therefore be hereby marked
> advertisement in accordance with 18 U.S.C. Section 1734 solely to indicat=
e
> this fact.



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

Date: Wed, 6 Aug 2008 18:25:01 +0000 (UTC)
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: How to flush STDIN with getc()?
Message-Id: <slrng9jqq5.1qmk.usenet@debranded.larseighner.com>

In our last episode, <SLlmk.61095$nD.52932@pd7urf1no>, the lovely and
talented John W. Krahn broadcast on comp.lang.perl.misc:

> Lars Eighner wrote:
>> In our last episode, <slrng9imqi.1pfu.usenet@debranded.larseighner.com>, the
>> lovely and talented Lars Eighner broadcast on comp.lang.perl.misc:
>> 
>>> I'm using perl 5.8.8 on FreeBSD.
>> 
>>> I understand that getc() defaults to STDIN when an argument is not
>>> specified, and getc() does not work until ENTER is hit at the keyboard
>>> (i.e. STDIN).  However, on the second call to get(), it appears I
>>> get the next character from the same line (which might be the
>>> newline from the ENTER, or might be 'e' if 'yes\n' was typed instead
>>> of 'y\n'.
>> 
>>> What's the right way to throw away the junk from the previous line?
>> 
>> Nevermind.
>> 
>> It appears getc() is not what I want (athough I am still curious about
>> the question posed.  $answer = <STDIN>  seems to be the right solution,
>> and works in this sub:
>> 
>> sub ask {
>> $question = shift(@_);
>> print "$question\n$enter ($aff/$neg): ";
>> $answer = <STDIN>;
>> chomp $answer;
>> $answer =~ s/^(.).*\n/$1/;

> chomp() removes the newline so your pattern won't match.

You are right.  I copied and pasted from one working version, changed
my mind and then tried to make the post agree with new working version,
and obvious did not get the post right.

>> if ( $answer eq $aff || $answer eq uc($aff)){

> You can simplify that a bit:

> my $answer = <STDIN>;
> if ( uc $aff eq uc substr $answer, 0, 1 ) {

neat.

-- 
Lars Eighner <http://larseighner.com/> usenet@larseighner.com
                    War hath no fury like a noncombatant.
                          - Charles Edward Montague


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

Date: Wed, 6 Aug 2008 20:15:35 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to flush STDIN with getc()?
Message-Id: <nr9pm5-9b7.ln1@osiris.mauzo.dyndns.org>


Quoth "John W. Krahn" <jwkrahn@shaw.ca>:
> Lars Eighner wrote:
> 
> > if ( $answer eq $aff || $answer eq uc($aff)){
> 
> You can simplify that a bit:
> 
> my $answer = <STDIN>;
> if ( uc $aff eq uc substr $answer, 0, 1 ) {

lc is better than uc when performing case-smashed comparisons, as not
all Unicode characters have a defined 'uc' (Unicode has the concept of
'titlecase', which is distinct from 'uppercase').

This particular comparison could also be written

    if ($aff =~ /^\Q$answer/i) {

of course.

Ben

-- 
You poor take courage, you rich take care:
The Earth was made a common treasury for everyone to share
All things in common, all people one.
'We come in peace'---the order came to cut them down.       [ben@morrow.me.uk]


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

Date: Wed, 06 Aug 2008 19:48:07 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: How to flush STDIN with getc()?
Message-Id: <Xdnmk.61455$nD.56524@pd7urf1no>

Ben Morrow wrote:
> Quoth "John W. Krahn" <jwkrahn@shaw.ca>:
>> Lars Eighner wrote:
>>
>>> if ( $answer eq $aff || $answer eq uc($aff)){
>> You can simplify that a bit:
>>
>> my $answer = <STDIN>;
>> if ( uc $aff eq uc substr $answer, 0, 1 ) {
> 
> lc is better than uc when performing case-smashed comparisons, as not
> all Unicode characters have a defined 'uc' (Unicode has the concept of
> 'titlecase', which is distinct from 'uppercase').
> 
> This particular comparison could also be written
> 
>     if ($aff =~ /^\Q$answer/i) {
> 
> of course.

ITYM:

      if ( $answer =~ /^\Q$aff/i ) {

 From the OP's code:

> where the English values are:
> 
> $aff = 'y';
> $neg = 'n';
> $quit ='q';

So if $answer contains 'yes' then $aff =~ /^\Q$answer/i will not match.



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Wed, 6 Aug 2008 20:29:34 +0000 (UTC)
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: How to flush STDIN with getc()?
Message-Id: <slrng9k23m.1qmk.usenet@debranded.larseighner.com>

In our last episode, <Xdnmk.61455$nD.56524@pd7urf1no>, the lovely and
talented John W. Krahn broadcast on comp.lang.perl.misc:

> Ben Morrow wrote:
>> Quoth "John W. Krahn" <jwkrahn@shaw.ca>:
>>> Lars Eighner wrote:
>>>
>>>> if ( $answer eq $aff || $answer eq uc($aff)){
>>> You can simplify that a bit:
>>>
>>> my $answer = <STDIN>;
>>> if ( uc $aff eq uc substr $answer, 0, 1 ) {
>> 
>> lc is better than uc when performing case-smashed comparisons, as not
>> all Unicode characters have a defined 'uc' (Unicode has the concept of
>> 'titlecase', which is distinct from 'uppercase').
>> 
>> This particular comparison could also be written
>> 
>>     if ($aff =~ /^\Q$answer/i) {
>> 
>> of course.

> ITYM:

>       if ( $answer =~ /^\Q$aff/i ) {

>  From the OP's code:

>> where the English values are:
>> 
>> $aff = 'y';
>> $neg = 'n';
>> $quit ='q';

> So if $answer contains 'yes' then $aff =~ /^\Q$answer/i will not match.

Yes.  Perhaps it is advancing geezerhood, but applications which which
burp if I inadvertantly type yes at a y/n prompt rattle me.

I'm still vaguely curious about the best way to flush STDIN so
getc() might work in similar way.  I can off course eat the line
in a while loop until I get the \n, but I think there might be something
more elegant  I gather the example in the getc documentation is off
to the races when it gets one character, which isn't what I want and
doesn't enlighten me about what to do to flush the keyboard buffer.

It seems to me that opening STDIN should close it before opening if
it already is open, but either this doesn't work as I think it should,
or I haven't got the incantation right.

-- 
Lars Eighner <http://larseighner.com/> usenet@larseighner.com
              War on Terrorism:  Bad News from the Sanity Front
"There's one thing ... that I do like about Rumsfeld, he's just a little bit
             crazy, OK"? --Thomas Friedman, _The New York Times_


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

Date: Wed, 06 Aug 2008 20:43:56 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: How to flush STDIN with getc()?
Message-Id: <g2omk.61508$nD.37733@pd7urf1no>

Lars Eighner wrote:
> 
> I'm still vaguely curious about the best way to flush STDIN so
> getc() might work in similar way.  I can off course eat the line
> in a while loop until I get the \n, but I think there might be something
> more elegant  I gather the example in the getc documentation is off
> to the races when it gets one character, which isn't what I want and
> doesn't enlighten me about what to do to flush the keyboard buffer.
> 
> It seems to me that opening STDIN should close it before opening if
> it already is open, but either this doesn't work as I think it should,
> or I haven't got the incantation right.

AFAIK you can't flush STDIN, perhaps you want 
http://search.cpan.org/~jstowe/TermReadKey-2.30/ReadKey.pm or 
http://search.cpan.org/~nuffin/Prompt-ReadKey-0.03/lib/Prompt/ReadKey.pm



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Wed, 6 Aug 2008 20:12:46 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Perl distributed as one all-inclusive Windows binary?
Message-Id: <em9pm5-9b7.ln1@osiris.mauzo.dyndns.org>


Quoth yojrod@gmail.com:
> Anyone know of a download or version of Perl for Windows that does not
> rely on libraries? (i.e., you can run this exe on any Windows machine,
> independent of required installations or libraries?)

I believe there is no such animal; however, you can use PAR::Packer to
take a Perl program and package it up into a completely stand-alone
executable.

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 'Alcestis')        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

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 V11 Issue 1775
***************************************


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