[23311] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5531 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 19 18:10:46 2003

Date: Fri, 19 Sep 2003 15:10:13 -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           Fri, 19 Sep 2003     Volume: 10 Number: 5531

Today's topics:
        return() inside eval <aajii@yahoo.com>
    Re: return() inside eval <stefan@unfunked.org>
    Re: return() inside eval <aajii@yahoo.com>
    Re: return() inside eval <stefan@unfunked.org>
    Re: simple server <spam-block-@-SEE-MY-SIG.com>
    Re: simple server (Tad McClellan)
    Re: simple server <flavell@ph.gla.ac.uk>
        transforming an explicit range based on implicit except (YAPoster)
    Re: transforming an explicit range based on implicit ex <kha@rogers.com>
    Re: View NG with Net::NNTP <Borniac_1@hotmail.com>
    Re: Writing out part of a file <nospam@goawayspam.com>
    Re: Writing out part of a file (Anno Siegel)
    Re: wtf is the deal? <tom@nosleep.net>
    Re: wtf is the deal? <usenet@dwall.fastmail.fm>
    Re: wtf is the deal? <tom@nosleep.net>
    Re: wtf is the deal? <ebohlman@earthlink.net>
    Re: wtf is the deal? <ebohlman@earthlink.net>
    Re: wtf is the deal? <usenet@dwall.fastmail.fm>
    Re: XML ( WML in particular) (Shambo)
    Re: XML ( WML in particular) <flavell@ph.gla.ac.uk>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 19 Sep 2003 19:05:57 GMT
From: "A.J." <aajii@yahoo.com>
Subject: return() inside eval
Message-Id: <3F6B5390.A27870D5@yahoo.com>

This works as needed:

#!/usr/local/bin/perl
use strict;
use Exception::Class( 'Exception' );

sub test() {
  eval {
    return( param1 => 'first',
            param2 => 'second' );
  };
  #print "here\n";
}

my %ret = &test();
print "param1:".$ret{param1}."\n";
print "param2:".$ret{param2}."\n";

>./test.pl
param1:first
param2:second

This doesn't. Why doesn't return work
properly in this case. Why is the print
clause executed? perl5.8.0
#!/usr/local/bin/perl
use strict;
use Exception::Class( 'Exception' );

sub test() {
  eval {
    return( param1 => 'first',
            param2 => 'second' );
  };
  print "here\n";
}

my %ret = &test();
print "param1:".$ret{param1}."\n";
print "param2:".$ret{param2}."\n";

>./test.pl
here
param1:
param2:





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

Date: Fri, 19 Sep 2003 20:57:07 +0100
From: Stefan <stefan@unfunked.org>
Subject: Re: return() inside eval
Message-Id: <bkfn2k$ef0$1@newsg2.svr.pol.co.uk>

Using return within your eval returns from the eval block, not the 
surrounding subroutine. The reason the first version works is that the 
eval is the last statement, and therefore it's value is used as the 
return value. In the first version you are returning eval which in turn 
returns your hash. In the second version you are running eval, ignoring 
the result and returning print.

Stefan


A.J. wrote:
> This works as needed:
> 
> #!/usr/local/bin/perl
> use strict;
> use Exception::Class( 'Exception' );
> 
> sub test() {
>   eval {
>     return( param1 => 'first',
>             param2 => 'second' );
>   };
>   #print "here\n";
> }
> 
> my %ret = &test();
> print "param1:".$ret{param1}."\n";
> print "param2:".$ret{param2}."\n";
> 
> 
>>./test.pl
> 
> param1:first
> param2:second
> 
> This doesn't. Why doesn't return work
> properly in this case. Why is the print
> clause executed? perl5.8.0
> #!/usr/local/bin/perl
> use strict;
> use Exception::Class( 'Exception' );
> 
> sub test() {
>   eval {
>     return( param1 => 'first',
>             param2 => 'second' );
>   };
>   print "here\n";
> }
> 
> my %ret = &test();
> print "param1:".$ret{param1}."\n";
> print "param2:".$ret{param2}."\n";
> 
> 
>>./test.pl
> 
> here
> param1:
> param2:
> 
> 
> 



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

Date: Fri, 19 Sep 2003 20:06:49 GMT
From: "A.J." <aajii@yahoo.com>
Subject: Re: return() inside eval
Message-Id: <3F6B61D4.FF794C32@yahoo.com>

The reason I want to use eval is to catch
possible exceptions inside various subroutines.
I'm using Exception::Class. Is there a better
way of doing this?

sub test() {
  eval {
    do something..

    return( param1 => 'first',
            param2 => 'second' );
  };
  if( UNIVERSAL::isa( $@, 'Exception' ) ) {
    return( param1 => 'Catched exception:'.$@->message,
            param2 => '' );
  }
}



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

Date: Fri, 19 Sep 2003 21:24:38 +0100
From: Stefan <stefan@unfunked.org>
Subject: Re: return() inside eval
Message-Id: <bkfom8$nvg$1@news8.svr.pol.co.uk>

A.J. wrote:
> The reason I want to use eval is to catch
> possible exceptions inside various subroutines.
> I'm using Exception::Class. Is there a better
> way of doing this?

Sure, just make sure you put your result in a variable before returning 
it. For example:

sub test() {
    my %result;
    eval {
       do something...
       %result = (
          param1 => 'first',...
       );
    }
    if ($@) {
       ...
    }
    else {
       return %result;
    }
}



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

Date: Fri, 19 Sep 2003 19:31:35 +0100
From: James Taylor <spam-block-@-SEE-MY-SIG.com>
Subject: Re: simple server
Message-Id: <ant1918351cbfNdQ@nospam.demon.co.uk>

In article <bkf9qd$7p9$1@titan.btinternet.com>,
D Borland <no.name@eidosnet.co.uk> wrote:
>
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnbmm6r2.gdh.tadmc@magna.augustmail.com...
> >
> > D Borland <no.name@eidosnet.co.uk> wrote:
> > >
> > > is there any way with perl for me to create a simple server,
> > > so i could say open a local file form the harddrive in my
> > > webbrowser, then click on a link to execute a perl script
> > > which will in turn return data to the current browser process.
> >
> > Any web server will do that.
> >
> > There are many free web servers available.

That wasn't his question. He may not have access to a suitable
platform for running any of those servers, or he may simply
want to study the code of a simple Perl HTTP server.

I'd also like to play with a simple Perl web server so an answer
to his question would help me and probably many others too.

> > What is your Perl question?
> 
> my perl question was how do i do that in perl,

I've just had a quick look on CPAN: http:/search.cpan.org/
and the following category looks interesting:
http://search.cpan.org/modlist/World_Wide_Web/HTTP
In particular, http://search.cpan.org/search?module=HTTP::Daemon
might be useful. However, someone else may be able to point us
directly at a portable HTTP server that supports CGI.

-- 
James Taylor, Cheltenham, Gloucestershire, UK.       PGP key: 3FBE1BF9
To protect against spam, the address in the "From:" header is not valid.
In any case, you should reply to the group so that everyone can benefit.
If you must send me a private email, use james at oakseed demon co uk.



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

Date: Fri, 19 Sep 2003 14:33:47 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: simple server
Message-Id: <slrnbmmmgr.hd2.tadmc@magna.augustmail.com>

D Borland <no.name@eidosnet.co.uk> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnbmm6r2.gdh.tadmc@magna.augustmail.com...


>> Any web server will do that.

> I was wondering if perl has an ability to do that.


Yes, you can write a web server in Perl.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 19 Sep 2003 20:00:23 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: simple server
Message-Id: <Pine.LNX.4.53.0309191947200.4262@ppepc56.ph.gla.ac.uk>

On Fri, 19 Sep 2003, James Taylor wrote:

> I'd also like to play with a simple Perl web server so an answer
> to his question would help me and probably many others too.

CPAN is always the first port of call for such a requirement, rather
than usenet, no?

> I've just had a quick look on CPAN: http:/search.cpan.org/
> and the following category looks interesting:
> http://search.cpan.org/modlist/World_Wide_Web/HTTP
> In particular, http://search.cpan.org/search?module=HTTP::Daemon
> might be useful.

I where I'd start, if I had such a requirement, yes...

> However, someone else may be able to point us
> directly at a portable HTTP server that supports CGI.

Supporting CGI - supporting it properly, in accordance with the rules
of HTTP and of the CGI spec - is not exactly "simple", and any
substantive deviation could be a make-or-break difference from what a
real server would do.  So in order to give a competent response to a
user requirement of this kind, I think we'd need to know more about
the requirements than merely that the questioner "wants to do it in
Perl".

My gut feeling still says this: Apache is a competent server[*], it's
available for a wide range of platforms, it's happy to talk to Perl
scripts as CGI processes or in other ways (API, mod_perl), there are
lots of folk who can and will help you with using it; it would need a
very strong reason to want to re-invent that part of the wheel in
Perl.

[*] well, two, depending on which version you favour, 1.3.* or 2.*


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

Date: 19 Sep 2003 13:16:07 -0700
From: yaposter@yahoo.com (YAPoster)
Subject: transforming an explicit range based on implicit exceptions
Message-Id: <c45edaa8.0309191216.48a2c7d7@posting.google.com>

i have this problem:
i have an explit range, say:

$range = "1-1000";
and implicit exceptions to it, say:
$excepts = "3,5-7,12,14,16-18..."
how do i convert $range into:

$newrange = "1,2,8-11,13,15,19..."

with efficiency in time and processing at a premium.

thanks.


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

Date: Fri, 19 Sep 2003 21:47:09 GMT
From: Kien Ha <kha@rogers.com>
Subject: Re: transforming an explicit range based on implicit exceptions
Message-Id: <xPKab.506891$4UE.247837@news01.bloor.is.net.cable.rogers.com>

YAPoster wrote:
> i have this problem:
> i have an explit range, say:
> 
> $range = "1-1000";
> and implicit exceptions to it, say:
> $excepts = "3,5-7,12,14,16-18..."
> how do i convert $range into:
> 
> $newrange = "1,2,8-11,13,15,19..."
                    4 is missing here I hope
> 
> with efficiency in time and processing at a premium.
> 
> thanks.

don't know about the "time efficiency" though, and here
is OWTDI using Bit::Vector module

#!/usr/bin/perl
use strict;
use warnings;
use Bit::Vector;

my ($range, $excepts) = (1001, "0,3,5-7,12,14,16-18");
my $v = Bit::Vector->new_Enum($range, $excepts);
$v->Flip;
my $newrange = $v->to_Enum;
print "\$newrange = $newrange\n";


Have fun reading the long doc. of Bit::Vector,
but it sure is a good one. :-)



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

Date: Fri, 19 Sep 2003 19:56:55 GMT
From: Borniac <Borniac_1@hotmail.com>
Subject: Re: View NG with Net::NNTP
Message-Id: <190920032157550169%Borniac_1@hotmail.com>

In article <46cdc619.0309022039.723ec45a@posting.google.com>, Mike
<csdude@hotmail.com> wrote:

Is it possible to get the total chunks posted and total bytes of all
chunks posted


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

Date: Fri, 19 Sep 2003 13:23:05 -0500
From: "Kubaton Lover" <nospam@goawayspam.com>
Subject: Re: Writing out part of a file
Message-Id: <vmmicchii6mebe@corp.supernews.com>

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbmm85s.gk0.tadmc@magna.augustmail.com...
> Kubaton Lover <nospam@goawayspam.com> wrote:
>
> > I want to open the file, print the first 2 lines of the file out, then
print
> > out a line or two of something else, then print out the remaining
portion of
> > the file.
>
>
>    # untested
>    print scalar <CODE>;
>    print scalar <CODE>;
>    print "my stuff here\n";
>    print while <CODE>;
>
>
> -- 
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas

Poifect!  I knew it had to be easier than I was making it.




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

Date: 19 Sep 2003 18:42:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Writing out part of a file
Message-Id: <bkfim6$9sq$1@mamenchi.zrz.TU-Berlin.DE>

Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> Kubaton Lover <nospam@goawayspam.com> wrote:
> 
> > I want to open the file, print the first 2 lines of the file out, then print
> > out a line or two of something else, then print out the remaining portion of
> > the file.
> 
> 
>    # untested
>    print scalar <CODE>;
>    print scalar <CODE>;
>    print "my stuff here\n";
>    print while <CODE>;

If the CODE file doesn't have two lines, this runs a bit bumpy.

I actually liked the OPs solution just fine.  Using a while-loop to print
a fixed number of lines may look like overkill, but it handles marginal
cases better.  Considering that $. is already there to count input lines,
it becomes

    while ( <CODE> ) {
        print;
        last if $. == 2;
    }
    print "'***my stuff***^\n";
    print while <CODE>;

That's what I would use.

Anno


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

Date: Fri, 19 Sep 2003 11:12:21 -0700
From: "Tom" <tom@nosleep.net>
Subject: Re: wtf is the deal?
Message-Id: <3f6b465b@nntp0.pdx.net>

> Having worked in fields ranging from embedded systems to software QA,
> I can definitively state that you're wrong.  That is not the 'proper'
> way to do anything but confuse and irritate your audience.
>

Well, so far the hundreds and thousands of engineers I communicate with
communicate the way I described.
However, as you can all clearly see, I am obliging your requests.
I was just trying to understand why you all do it differently.
I'm not speaking to you in particular, but apparently many on usenet have
serious issues and should have been cops, since they seem to like being the
usenet police.


> -=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: Fri, 19 Sep 2003 18:10:04 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: wtf is the deal?
Message-Id: <Xns93FB901F2F196dkwwashere@216.168.3.30>

Tom <tom@nosleep.net> wrote:

> I didn't top post anything after ANYONE asked me to stop.
> If anyone said anything, I never saw it.
> As far as reading backwards in time, that is exactly the preferred
> way for Engineering, unless comments are inlined with quetsions,
> etc. 
> 
> I don't want to have to constantly scroll past what I already read
> a dozen times to get to what was responded to last.
> This is the 'proper' way to converse technical info, at least in
> the engineering world.

Where I work most people's experience with email is solely MS-Outlook 
(they don't know from usenet), so the convention at my workplace is 
"sedimentary" or top-posting order.  I don't like it, but rather than 
confuse everyone else when there's a long email discussion, I follow 
the convention.

The convention here is NOT top-posting.  You might not like it and 
you might think it's stupid, but if you ignore the conventions of the 
community the community will ignore you.  

If you travelled to Britain, would you insist on driving on the 
right-hand side of the road?  After all, it's just a convention, and 
those silly Brits will surely see the light after you show them how 
to drive properly.  What would actually happen, though, is that 
everyone would honk at you and you would cause a wreck.

Stop driving on the wrong side of the road.

-- 
David Wall


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

Date: Fri, 19 Sep 2003 11:30:17 -0700
From: "Tom" <tom@nosleep.net>
Subject: Re: wtf is the deal?
Message-Id: <3f6b4a8f$1@nntp0.pdx.net>

 .
>
> Can we get back to Perl now?
>
> --keith
>

OK, but one final word. In my work, the entire threads must be kept intact
so everyone involved can follow the flow and know all the details.

Tom




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

Date: 19 Sep 2003 18:46:43 GMT
From: Eric Bohlman <ebohlman@earthlink.net>
Subject: Re: wtf is the deal?
Message-Id: <Xns93FB8DB2BE3BBebohlmanomsdevcom@130.133.1.4>

"David H. Adler" <dha@panix.com> wrote in 
news:slrnbml91g.j3k.dha@panix2.panix.com:

> That's the point.  Context *is* important.  The idea is that you trim
> out the stuff that isn't relevant to your reply.  That way there isn't
> anything irrelevant to "scroll to the bottom" of.

And that's one of the big differences between Usenet and email, 
particularly corporate-internal email.  When replying to the email 
equivalent of a memo, in some corporate cultures snipping anything one's 
superior wrote may be seen as disrespectful.  But here on Usenet, we aren't 
divided into bosses and subordinates.  We have archives and references that 
make it possible to get the full text of what was being replied to.  And 
we're writing not to be read by one person, but by thousands of them.


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

Date: 19 Sep 2003 18:51:53 GMT
From: Eric Bohlman <ebohlman@earthlink.net>
Subject: Re: wtf is the deal?
Message-Id: <Xns93FB8E929B0CFebohlmanomsdevcom@130.133.1.4>

"Tom" <tom@nosleep.net> wrote in news:3f6b4a8f$1@nntp0.pdx.net:

> OK, but one final word. In my work, the entire threads must be kept
> intact so everyone involved can follow the flow and know all the
> details. 

In Usenet, unlike arbitrary email exchanges, we have threading, message-
IDs, and archives to achieve those goals.  Therefore it's not necessary for 
each  new article in a thread to embody the entire history of the thread.  
I strongly suspect that many of the email conventions in your work are 
based more on CYA considerations than anything else, considerations that 
don't apply here.


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

Date: Fri, 19 Sep 2003 19:49:05 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: wtf is the deal?
Message-Id: <Xns93FBA0E95A359dkwwashere@216.168.3.30>

Eric Bohlman <ebohlman@earthlink.net> wrote:

> And we're writing not to be read by
> one person, but by thousands of them. 

/me looks around wildly, suddenly gets stage fright, and shuffles 
away.....



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

Date: 19 Sep 2003 11:48:49 -0700
From: shambo_p@yahoo.com (Shambo)
Subject: Re: XML ( WML in particular)
Message-Id: <72190192.0309191048.46c6182@posting.google.com>

> > WML is very unforgiving with its range of displayable characters.
> 
> Could you be more specific?

I should have been more clear. WML only allows 7 NAMED references to
be used: &quot; &amp; &lt; &gt; &apos; &nbsp; &shy; Anything else,
such as &cent; will cause the file not to display. But, as you
indicated, it shouldn't matter since WML does support UTF-8 encoding
(I did not know that before today).

> > That line will change characters above the first 128 ASCII characters
> 
> Ahem, *bogosity alert*.  ASCII is a 7-bit code, the "first 128 ASCII
> characters" is all that there are.

D'oh!

Obviously, the encoding concept is still taking a while to seep into
my brain.

I probably should have just stopped at "open (FILE, ">:utf8",
"/somepath/somefile.wml")", but you're right to say Brian should know
what his source encoding is (see, Alan, I do listen to you ;-).


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

Date: Fri, 19 Sep 2003 21:35:04 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: XML ( WML in particular)
Message-Id: <Pine.LNX.4.53.0309192119100.4414@ppepc56.ph.gla.ac.uk>

On Fri, 19 Sep 2003, Shambo wrote:

> I should have been more clear. WML only allows 7 NAMED references to
> be used: &quot; &amp; &lt; &gt; &apos; &nbsp; &shy; Anything else,
> such as &cent; will cause the file not to display.

Thanks ;-)

> But, as you
> indicated, it shouldn't matter since WML does support UTF-8 encoding
> (I did not know that before today).

Well, neither did I, to be honest; I was basing my reply on what I'd
been told on this thread.  (I already made my protest against
specifications that refuse to be read without taking legal opinion
first...)

> D'oh!
>
> Obviously, the encoding concept is still taking a while to seep into
> my brain.

Oh, there's a lot of it about, don't take it personally if I
occasionally get a bit sharp...

> I probably should have just stopped at "open (FILE, ">:utf8",

well, as long as you mention that older Perls don't have this...

> "/somepath/somefile.wml")",

  ... or die "could not open output file $!";

> but you're right to say Brian should know
> what his source encoding is (see, Alan, I do listen to you ;-).

It's OK, I'm just trying to share what I know.  Character coding isn't
hard if one can come to it with a clear head and get a clear mental
picture.  I must admit that I had the early discipline (in the 1970's)
of a machine which used a character coding that was used almost
nowhere else, and so it was taken for granted that all input would
have to be translated from its external coding, whatever it might be,
and all output would have to be translated to a user-defined output
coding.  That sets a challenge which somehow never went away.  RFC2070
was nice  ;-) if you care for that sort of thing.

It's so frustrating when folks come to it with some misunderstood
picture of custom fonts and DOS codepages and I don't know what else
all jumbled up together.  But don't mind me...

cheers


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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