[17524] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4944 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 21 18:11:06 2000

Date: Tue, 21 Nov 2000 15:10:15 -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: <974848215-v9-i4944@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 21 Nov 2000     Volume: 9 Number: 4944

Today's topics:
    Re: parse email body <bart.lateur@skynet.be>
        perl adds a spurious + sign to integers (Mark Kvale)
    Re: perl adds a spurious + sign to integers <jeffp@crusoe.net>
    Re: perl adds a spurious + sign to integers <kvale@phy.ucsf.edu>
        perl vs C style <joe@benburb.demon.co.uk>
        POE 0.12 Released (Rocco Caputo)
    Re: Q: How to treat a string as a file? nobull@mail.com
    Re: Q: How to treat a string as a file? <bart.lateur@skynet.be>
    Re: Reading files? <johngros@Spam.bigpond.net.au>
        REGEXP Help! Trying to parse funky time format... <liam@nethelpnow.com>
    Re: sending a signal to a process which I don't own (Martien Verbruggen)
    Re: Sort strings before numbers <hbhb@gmx.de>
        sybperl CTlib character set <ken.chesak@dhs.state.tx.us>
    Re: Tom Christiansons' 'style' (Greg Bacon)
    Re: uploading files over web <todd@mrnoitall.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 21 Nov 2000 20:17:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: parse email body
Message-Id: <j2ml1t0ct9qv20lpinjovsom7p0r5sc6sm@4ax.com>

Kevin Hanrahan wrote:

>can anyone show me how to parse out just the body of an email message
>and save it as a variable or pipe it to another program?

The first empty line is between headers and body.

-- 
	Bart.


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

Date: 21 Nov 2000 19:23:19 GMT
From: kvale@ivy.ucsf.edu (Mark Kvale)
Subject: perl adds a spurious + sign to integers
Message-Id: <8vei37$127u@itssrv1.ucsf.edu>
Keywords: scalar conversions

perl is well-known for its transparent conversion of scalars from
numbers to strings and back again as needed by the context.

Recently, however, I was surprised by the following behavior:

The program

$num = -1;
$num = -$num;
print "$num\n";

$num = "-1";
$num = -$num;
print "$num\n";

yields the following output with 5.6:

1
+1

The problem is that 1 == +1 but "1" ne "+1". This caused a bug in a
program I was writing, as my hash (with integer keys) was treating
$h{1} and $h{+1} as different elements. My workaround is to set

$num = int -$num;

which removes the + sign.

I consider adding the + sign spurious and a bug, but I would be
interested in hearing if there was a rationale for this before I send
it off to p5p. Are there any other instances where a + is
spontaneously generated?

Thanks,
        -Mark




-- 
Mark Kvale, neurobiophysicist
http://www.keck.ucsf.edu/~kvale/


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

Date: Tue, 21 Nov 2000 15:30:14 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: perl adds a spurious + sign to integers
Message-Id: <Pine.GSO.4.21.0011211522020.714-100000@crusoe.crusoe.net>

[posted & mailed]

On Nov 21, Mark Kvale said:

>perl is well-known for its transparent conversion of scalars from
>numbers to strings and back again as needed by the context.
>
>$num = "-1";
>$num = -$num;
>print "$num\n";  # +1
>
>I consider adding the + sign spurious and a bug, but I would be
>interested in hearing if there was a rationale for this before I send
>it off to p5p. Are there any other instances where a + is
>spontaneously generated?

Check perlop for unary minus:

     Unary "-" performs arithmetic negation if the operand is
     numeric.  If the operand is an identifier, a string
     consisting of a minus sign concatenated with the identifier
     is returned.  Otherwise, if the string starts with a plus or
     minus, a string starting with the opposite sign is returned.

You have dubbed $num as POK by placing its value in quotes (POK meaning
it's ok as a string value), and it does NOT have the IOK flag set (IOK
meaning it's flagged as a valid integer value).

So when you do -$num, Perl sees -"-1", and it returns "+1".

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Tue, 21 Nov 2000 13:07:02 -0800
From: Mark Kvale <kvale@phy.ucsf.edu>
Subject: Re: perl adds a spurious + sign to integers
Message-Id: <3A1AE3F6.28C68D47@phy.ucsf.edu>

Jeff Pinyan wrote: 
> On Nov 21, Mark Kvale said:
> 
> >perl is well-known for its transparent conversion of scalars from
> >numbers to strings and back again as needed by the context.
> >
> >$num = "-1";
> >$num = -$num;
> >print "$num\n";  # +1
> >
> >I consider adding the + sign spurious and a bug, but I would be
> >interested in hearing if there was a rationale for this before I send
> >it off to p5p. Are there any other instances where a + is
> >spontaneously generated?
> 
> Check perlop for unary minus:
> 
>      Unary "-" performs arithmetic negation if the operand is
>      numeric.  If the operand is an identifier, a string
>      consisting of a minus sign concatenated with the identifier
>      is returned.  Otherwise, if the string starts with a plus or
>      minus, a string starting with the opposite sign is returned.
> 
> You have dubbed $num as POK by placing its value in quotes (POK meaning
> it's ok as a string value), and it does NOT have the IOK flag set (IOK
> meaning it's flagged as a valid integer value).
> 
> So when you do -$num, Perl sees -"-1", and it returns "+1".
> 

Ok, if this is documented, someone must consider this a feature ;)
Thanks Jeff!

	-Mark


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

Date: 21 Nov 2000 21:10:53 +0000
From: joe mc cool <joe@benburb.demon.co.uk>
Subject: perl vs C style
Message-Id: <u7d7fpvxnm.fsf@benburb.tangent.com>

Please,

can someone point me to sources on the differences between idioms in
perl and c programming.
-- 
joe mc cool SMIEEE
========================================================================
Tangent Computer Research BT71 7LN (www.tangent-research.com)
voice:(44)2837-548074fax:(44)-870-0520185 The more you say the less the better.



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

Date: 21 Nov 2000 11:15:42 -0500
From: troc@netrus.net (Rocco Caputo)
Subject: POE 0.12 Released
Message-Id: <t1lmde49af0540@corp.supernews.com>

Good morning.

POE 0.12 has been uploaded to the PAUSE and <http://poe.perl.org/>.
It should appear at your favorite CPAN mirror shortly.

This is the first CPAN release in about four months.  Several changes
have occurred in web-only releases since 0.11.  Some highlights:

 o Added support for Gtk.  Fixed Tk support.  POE now can use one of
   four event loops: Gtk, Tk, Event, or its own perl select() loop.
   POE's public interface maps itself to whichever event loop is used,
   so the same program guts (POE::Component::IRC, for example) will
   work in each environment.  POE supports each event loop's unique
   features through a generic postback mechanism.

 o Added a way to populate the heap at construction time or change it
   to something completely different.

 o Added POE::NFA, a true nondeterministic state machine variation of
   POE::Session.

 o Optimized the macro/const/enum source filter, POE::Preprocessor.
   Startup should be a little faster.

 o Added new tests.  Extended existing ones.  Revised the problematic
   signals tests.  Skipped many tests under Windows simply because
   Windows does not support the features they test.  Test coverage is
   about 70%.

 o Improved coverage testing.  It's still far from perfect, and it
   always will be, but it's better than before.

 o Improved Wheels so their events can be tied back to which wheel
   generated them.  This makes it possible for one session to keep
   track of many wheels.

 o Moved POE's web site and mailing list.  Documented the new
   addresses.

 o Improved Filter::Line with contributed code: Added Addi's newline
   auto-detection code and Dennis Taylor's patch for supporting
   different newlines.

 o Improved messages in skipped tests so they don't look like
   problems.

 o Fixed Filter::HTTPD, which didn't work correctly with some clients.

 o Added a cheezy neural network to the samples directory.

These are just highlights.  The full README and Changes files are
available at <http://poe.perl.org/>.

Thank you.

-- Rocco Caputo / troc@netrus.net




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

Date: 21 Nov 2000 19:07:55 +0000
From: nobull@mail.com
Subject: Re: Q: How to treat a string as a file?
Message-Id: <u9bsv987p0.fsf@wcl-l.bham.ac.uk>

nospam@our.site writes:

> Subject: Q: How to treat a string as a file?

IO::Scalar

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 21 Nov 2000 20:16:30 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Q: How to treat a string as a file?
Message-Id: <43ll1t05la7c7km41ih2cklnlividmoosp@4ax.com>

nospam@our.site wrote:

>I am writing a little module to parse a results file from an external
>program.
>
>However the results could be returned either on STDIN, in a file or
>passed in a string.
>
>I thought the easiest thing to do was 
>
>while( defined ( $record = <INFILE> ) )
>{
>  do lots of things with each $record;
>}
>
>so how can I get my string to be sucked through the filehandle?

Tieing the filehandle, that could work. However, *you* are still
responsible for splitting the data into lines. So this approach solves
nothing. Er... nothing much, anyway.

This is how you can get the next line:

    $buffer = "This is one\nThis is two\nThis is three\n";
    while(defined $buffer and
      ($_, $buffer) = split /(?<=\n)/, $buffer, 2) {
        print "Line: \"$_\"\n";
    }

You still want a single API to load in the data from any source? OK:

tie *INFILE, Tie::StringAsFile, <<'#EOF#';
This is one
This is two
This is three
#EOF#
while(<INFILE>) {
    print "Line: \"$_\"\n";
}

package Tie::StringAsFile;

sub TIEHANDLE {
	my $class = shift;
	return bless { BUFFER => shift }
}

sub READLINE {
	my $self = shift;
	for($self->{BUFFER}) {  # alias
		defined and length or return;  # eof
		(my $line, $_) = split /(?<=\n)/, $_, 2;
		return $line;
	}
}
__END__

You only need to tie the handle to the string if indeed you get a string
of data.

   HTH,
   Bart.


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

Date: Tue, 21 Nov 2000 22:54:53 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Reading files?
Message-Id: <13DS5.1723$bg5.10014@news-server.bigpond.net.au>

I don't believe I missed that. I know thats the first thing to look for with
a syntax error. 8-(
"Wyzelli" <wyzelli@yahoo.com> wrote in message
news:Xns8FF3A2E5Cwyzelliyahoocom@203.39.3.131...
> "John Boy Walton" <johngros@Spam.bigpond.net.au> wrote in
> <u6oS5.97$bg5.808@news-server.bigpond.net.au>:
>
> >$line = <BOGUS>
> > if ($form_data{'pass'} eq $line)
>
> missing ; on first line
>
> I assume the second line normally ends in { for starting the if block
>
> Wyzelli




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

Date: Tue, 21 Nov 2000 14:04:13 -0800
From: "Liam Furniss" <liam@nethelpnow.com>
Subject: REGEXP Help! Trying to parse funky time format...
Message-Id: <t1lsiaostpnga2@news.supernews.com>

Hello Perlish Types,

I have a some time data in the form XXd,XX:XX.XX (e.g. 5d,23:55.07), and I
can't seem to craft a regexp the will extract just the numbers into
variables that will be useful to me. Currently, I'm trying
/(\d*d,)?(\d*:)?(\d*\.)?(\d*)?/, but it reports the minutes in $4 and $3 is
empty...The other problem of course is making it work when the no day or
hour data (e.g. 5.23)...Anyone feel kind enough to work their regexp mojo
for me? This script could help save a struggling dot com! Hehe.

Cheers,
Liam@Nethelpnow.com




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

Date: Tue, 21 Nov 2000 22:24:13 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: sending a signal to a process which I don't own
Message-Id: <slrn91ltfd.r2.mgjv@verbruggen.comdyn.com.au>

On Tue, 21 Nov 2000 08:15:21 +0100,
	Willem Joosten <nospam@jsoft.xs4all.nl> wrote:
> 
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn91i4k3.imr.mgjv@martien.heliotrope.home...
> 
>> Several other ways: sockets, named pipes, SYSV message queues.
>>
>> What is best, and how to solve it is impossible to say without knowing
>> much, much more about what your programs do, and what the intent of the
>> signal is.
> 
> The cgi script updates a text file which should be reread by the 'deamon'
> script and processed. The processing takes about an hour so I don't the cgi
> script to do the processing.

Another solution would be to have the CGI fork a child that does the
processing, and dissociate that child fromt he parent. Of course, the
CGI user would need write permissions anywhere that it needs them.

>> My crystal ball says that you'll either need the four argument form of
>> select, with a named pipe or sockets, or you'll need two processes
>> instead of one waiting for that 'signal', parent and child.
> 
> Very good crystal ball! Haven't implemented the child process yet (too much
> new stuff for one evening :) but the select on a named pipe works like a
> charm. Thanks for the reply.

I do suppose you've taken care of the possibility that while you're
processing some other CGI process tries to update the file again? It
sounds like you probably have, but I thought I'd just put up a warning
flag :)

If the process has nothing else to do while it's waiting for a signal
to start processing, a blocking read might be sufficient. Something
like:

PROCESSOR:

create a named pipe 
make sure permissions are sufficient for CGI user to write to it
while (! end)
{
	read (blocking) a line from the pipe
	open the text file for read
	LOCK_SH the text file
	PROCESS
	close text file
}

CGI:

open the named pipe for write
LOCK_EX it
if failed
	other CGI process is working
	bail out
open the text file for update
LOCK_EX it
if failed
	processor already has a lock, is working
	bail out
update the text file
close the text file
write a line to the named pipe
close pipe
exit

I think there is no race condition in the above, but a bit more
thought should go into it. If not sure, a control file for locking
could be useful. I'm also not 100 percent sure that a lock can be
obtained on a named pipe on all platforms, although I believe it
should be possible.

Of course, if you don't want the processor to block on a read, you do
need to use a select in that loop.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd.   | Then things get worse.
NSW, Australia                  | 


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

Date: Tue, 21 Nov 2000 23:51:32 +0100
From: Holger <hbhb@gmx.de>
Subject: Re: Sort strings before numbers
Message-Id: <etul1tc4psolasleidvb596t7ec63ev4u9@4ax.com>

On Mon, 20 Nov 2000 18:58:39 -0500, tadmc@metronet.com (Tad McClellan)
wrote:

(Code examples snipped)

Thanks for your suggestions. I am going to try and benchmark them which is
faster.

>>In <perlfunc> I found an example for sort.
>>    @new = map { $_->[0] }
>>                sort { $b->[1] <=> $a->[1]
>>                                ||
>>                       $a->[2] cmp $b->[2]
>>               } map { [$_, /=(\d+)/, uc($_)] } @old;
>>Unfortunately, I don't comprehend it entirely, especially not the final
>>pair of brackets. I suppose they form a list, but couldn't find a proof in
>>the docs. 
>
>The last curly brackets are just a code block.
>The last square brackets return a reference to an anonymous array.

Yes, I meant the square ones. Is there a difference between an (anonymous)
list and array (in perl, in C at least I know that there is)? In <perldata>
I only found parentheses, that form a list.

>I got the ST below to work, but it generates warnings:
>
>   my @sorted = map  { $_->[0] }
>                sort { $a->[2] <=> $b->[2] or $a->[1] cmp $b->[1] }
>                map  { [ $_, /[a-z]/i ? ($_,'') : ('', $_) ] } keys %config;
>
>I doubt that the ST is a win for what you need to do anyway, just
>split up the list of keys as above.
Initially, I also got warnings that some arguments aren't numeric in
numeric comparison. That's why my original post has these expensive tests
because I had to test for numeric value before comparing.
OP> sort { (($a =~ m/^(\d+)$/) && ($b =~ m/^(\d+)$/)) ?
OP> $a <=> $b : (($a =~ m/\D/) xor ($b =~ m/\D/)) ?
OP> $b cmp $a : $a cmp $b } (keys %config)

One question to your example: Doesn't building up the "helping" array
consume too much time (not to mention space)?
Btw, what does "ST" mean?

Regards,

	Holger


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

Date: Tue, 21 Nov 2000 13:56:33 -0600
From: "Ken Chesak" <ken.chesak@dhs.state.tx.us>
Subject: sybperl CTlib character set
Message-Id: <8vek79$5u7$1@goblin.tdh.state.tx.us>

How do I make a character set selection using sybperl CTlib?

Current connection string:

 $::dbh  = new Sybase::CTlib $::DBUSER, $::DBPWD, $::ltcSERVER, undef,
                 { CON_PROPS => { CS_HOSTNAME => 'beaver',
                                  CS_SYB_CHARSET => 'iso_1' }};

Error:

Ambiguous use of CS_HOSTNAME => resolved to "CS_HOSTNAME" => at a.pl line
680.
Ambiguous use of CS_SYB_CHARSET => resolved to "CS_SYB_CHARSET" => at a.pl
line

Thanks






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

Date: Tue, 21 Nov 2000 20:48:30 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Tom Christiansons' 'style'
Message-Id: <t1lnsu2a2jlt6a@corp.supernews.com>

In article <3a1b90de.2046913@news.hal-pc.org>,
    Monte Phillips <montep@hal-pc.org> wrote:

: My question is this.  Tom, are you telling me that you do not go to
: the auto dept and buy a new battery for your car?  You actually go
: home, design a battery, build it and then install it?  Do you also
: design rubber gaskets and make them and install them on leaking
: faucets?  I can bet the farm you don't.

The issue is irrelevant.  When you purchase a battery or a gasket,
you're paying in part for the human effort that went into producing
the item.  Looking for a handout in comp.lang.perl.misc is no
different from looking for a handout at the hardware store.  Both
are acts of acute rudeness and insult.

:                                          I will also bet you hire
: mechanics and plumbers and lawyers and all sorts of other people to do
: the things you cannot do because of lack of training, talent or time.

Precisely.  This isn't alt.sources.wanted.  If you want someone to
write Perl programs for you, then hire a program.  Loitering around
this newsgroup pestering passers-by isn't likely to yield much
success.

: Do you think that all everyone in the whole world does or needs to
: know is some arcane computer language

This isn't comp.lang.fortran. :-)

:                                       that is useful in the present,
: but will like all its predecessors be cast aside as need disappears?

How is your question relevant?  This is comp.lang.perl.misc, a
discussion group for Perl programmers, i.e., the very people who know
the "arcane computer language" in question.  If you're looking for a
handout, a better group would be alt.sources.wanted.

: The questions asked were intelligently posed, not the 'this script I
: downloaded doesn't work' variety.  They sounded as if from people who
: either need Perl only occasionally or that are very serious early
: learners. [...]

Walk for a while in the shoes of a comp.lang.perl.misc regular, and
the difference between serious learners and handout seekers will
become obvious.  Serious learners will usually mention the documentation
they've read and even include code they've tried.  The ones who don't
see others rewarded for doing so and imitate the behavior.

Greg
-- 
I have not finished with a woman until I have had her all three ways.
    -- JFK


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

Date: Tue, 21 Nov 2000 12:53:10 -0600
From: Todd Anderson <todd@mrnoitall.com>
Subject: Re: uploading files over web
Message-Id: <3A1AC491.AE21B441@mrnoitall.com>



Troy Rasiah wrote:

> Hi there...
>     I have a simple file uploading html/cgi page that uploads files to a
> server. My problem is that I want a progress bar or even dots going across
> the screen as the file uploads. My HTML only comes on the screen once the
> file has finished uploading.
>
> Can anyone help me?
> Thanks in advance
>
> This is basically what i'm using...the print statements don't show till the
> file has finished uploading
>
> sub uploadFile {

  print "Now Uploading ";

>
>   my ($fileonServer)=@_;
>   my $req = new CGI;
>   my $file = $req->param("fileToGo");
>   if ($file ne "") {
>
>     my $fileName="$fileonServer";
>     open (OUTFILE, ">$fileName");
>     while (my $bytesread = read($file, my $buffer, 1024)) {
>       print ". ";
>       print OUTFILE $buffer;
>     }
>     close (OUTFILE);
>   }
> }
>
> --
> ----------------------------------------------------------------------------
> ----------------
> TR

--
Todd Anderson
ASGWEB.net
1362E 3345S
SLC, UT 84106
801.487.3675

http://asgweb.net
http://asgweb.net/asgpro
http://mrnoitall.com




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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4944
**************************************


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