[25140] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7389 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 10 18:05:31 2004

Date: Wed, 10 Nov 2004 15:05:08 -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           Wed, 10 Nov 2004     Volume: 10 Number: 7389

Today's topics:
    Re: better way using IO::Select and pool of non-blockig <uguttman@athenahealth.com>
    Re: better way using IO::Select and pool of non-blockig <and11@rol.ru>
    Re: better way using IO::Select and pool of non-blockig <and11@rol.ru>
    Re: better way using IO::Select and pool of non-blockig <and11@rol.ru>
    Re: better way using IO::Select and pool of non-blockig <uguttman@athenahealth.com>
        CBC/BLOWFISH, NEWBIE HELP - CAN'T DECRYPT FROM SAVED FI (Homer J.)
        FAQ 1.11: When shouldn't I program in Perl? <comdog@panix.com>
        FAQ 1.6: What is perl6? <comdog@panix.com>
    Re: Grabbing a PDF file from the web...how? (funkyville)
    Re: how greedy is nongreedy in regexp ? <nobull@mail.com>
    Re: how greedy is nongreedy in regexp ? <nobull@mail.com>
    Re: Is this really legal? <dformosa@zeta.org.au>
    Re: Looking to improve program <mritty@gmail.com>
    Re: Looking to improve program <uguttman@athenahealth.com>
    Re: Looking to improve program <mritty@gmail.com>
    Re: map()'s BLOCK [was: "Re: Q: re Inline and Benchmark <dformosa@zeta.org.au>
    Re: map()'s BLOCK [was: "Re: Q: re Inline and Benchmark (Anno Siegel)
    Re: perldoc problem on linux (Zhiliang Hu)
    Re: references to OTHER objects <spamtrap@dot-app.org>
    Re: references to OTHER objects <nospam@nospam.com>
    Re: references to OTHER objects <spamtrap@dot-app.org>
    Re: replace pattern including newline : perl version 5. (Prince)
    Re: replace pattern including newline : perl version 5. (Prince)
    Re: replace pattern including newline : perl version 5. (Prince)
        SWITCH: question on evaluation (Robert)
    Re: SWITCH: question on evaluation <mritty@gmail.com>
    Re: Using $SIG{"ALRM"}  assignment inside a subroutine  <nobull@mail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 10 Nov 2004 12:50:07 -0500
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <m3pt2liofk.fsf@lap.athenahealth.com>

>>>>> "AT" == Andrew Tkachenko <and11@rol.ru> writes:

  AT> thanks a lot for hint - unfortunately I've missed this module before.
  AT> Very good and handy job. I'm sure I'll use it in future, but
  AT> unfortunately, for my current task this module is not quite suitable :(
  AT> SO, the question is still remains actual.

why don't you state your actual reason for not using it? IO::Select has
a very poor api for doing read and write events. if your event code is
all isolated to one area, it should be easy to convert it to event.pm.

uri


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

Date: Wed, 10 Nov 2004 22:49:18 +0000
From: Andrew Tkachenko <and11@rol.ru>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <cmtrgm$2j2$1@news.rol.ru>

I don't need much from IO::Select - just to know if socket if ready for write or has something to read. 
Nothing more. I already have engine generating appropriate events, and after some expirements and
reading of Event.pm pod and tutorial I've found that this would be quite expensive for me to embed Event.pm
into existing project. As I said, I've missed this quite useful module while I planned this task. Otherwise
probably I'd use it, and I'm sure I'll use it in future.

Thanks,
Andrew

Uri Guttman wrote:
> why don't you state your actual reason for not using it? IO::Select has
> a very poor api for doing read and write events. if your event code is
> all isolated to one area, it should be easy to convert it to event.pm.
> 
> uri

-- 
Andrew


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

Date: Wed, 10 Nov 2004 22:59:45 +0000
From: Andrew Tkachenko <and11@rol.ru>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <cmts49$2rr$1@news.rol.ru>

Thanks for you response, Stuart.

I'm sorry, probably I've missed something, but I've thought that there is no
need to use additional tools/modules/classes to create hash of sockets?

%socks = ();
for (0 .. 10) {
        $socks{$sock} = new IO::Socket::INET(<skipped>);
}

<..skipped..>

@readers = $ios->can_read(0);
for my $r(@readers) {
        if ($socks{$r}) {
                # then do something
        }
}

I've used it lots of time and never thought that it is impossible or erroneus
Please correct me if I've missed something or did it wrong ?

Thanks for advance,
Andrew

Stuart Moore wrote:


> 
> Then a modified version of your code would be:
> 
> while(1)
> {
>            my ($can_read, $can_write) = IO::Select->select($rd_set,
> $wr_set, undef, $TIMEOUT);
> 
> foreach my $reader(@$can_read){
> my $i = $sock_index{$reader};
> #read from socket
> }
> foreach my $writer(@$can_write){
> my $i = $sock_index{$writer};
> #write to socket
> }
-- 
Andrew


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

Date: Wed, 10 Nov 2004 23:28:26 +0000
From: Andrew Tkachenko <and11@rol.ru>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <cmttq2$377$1@news.rol.ru>

Sorry, mistaken a bit.
I've meant:

 %socks = ();
 for (0 .. 10) {
         my $sock = new IO::Socket::INET(..);
         $socks{$sock} = $_;
 }


Andrew Tkachenko wrote:

> Thanks for you response, Stuart.
> 
> I'm sorry, probably I've missed something, but I've thought that there is
> no need to use additional tools/modules/classes to create hash of sockets?
> 
> %socks = ();
> for (0 .. 10) {
>         $socks{$sock} = new IO::Socket::INET(<skipped>);
> }
> 
> <..skipped..>
> 
> @readers = $ios->can_read(0);
> for my $r(@readers) {
>         if ($socks{$r}) {
>                 # then do something
>         }
> }
> 
> I've used it lots of time and never thought that it is impossible or
> erroneus Please correct me if I've missed something or did it wrong ?
> 
> Thanks for advance,
> Andrew
> 
> Stuart Moore wrote:
> 
> 
>> 
>> Then a modified version of your code would be:
>> 
>> while(1)
>> {
>>            my ($can_read, $can_write) = IO::Select->select($rd_set,
>> $wr_set, undef, $TIMEOUT);
>> 
>> foreach my $reader(@$can_read){
>> my $i = $sock_index{$reader};
>> #read from socket
>> }
>> foreach my $writer(@$can_write){
>> my $i = $sock_index{$writer};
>> #write to socket
>> }

-- 
Andrew


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

Date: Wed, 10 Nov 2004 15:45:18 -0500
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <m3d5yligbl.fsf@lap.athenahealth.com>

>>>>> "AT" == Andrew Tkachenko <and11@rol.ru> writes:

  AT> I don't need much from IO::Select - just to know if socket if
  AT> ready for write or has something to read.  Nothing more. I already

but that is what event.pm will tell you. and you don't have the clunky
api of io::select when it needs to do read AND write events. it is fine
for simple event loops with read or write but the need to create these
objects for each r/w instance is nuts. and the proper way to handle them
is to loop over your sockets and build up the args to the event loop.

  AT> have engine generating appropriate events, and after some
  AT> expirements and reading of Event.pm pod and tutorial I've found
  AT> that this would be quite expensive for me to embed Event.pm into
  AT> existing project. As I said, I've missed this quite useful module
  AT> while I planned this task. Otherwise probably I'd use it, and I'm
  AT> sure I'll use it in future.

expensive makes little sense here. your engine doesn't generate events,
io::select or event.pm does. what your engine does is handle the
events. now if you wrote this system in a procedural style and only call
io::select when you feel like it, then i can understand why you are
reticent to redesign it. that is a poor event loop design since it can
cause timeouts and possible lost data when you are doing other computing
and don't check back often enough. it is akin to a classic polling
design where you actually ask each socket if it has data. you waste so
much cpu in the polling loop.

but i can't convince anyone about anything today. 

uri


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

Date: 10 Nov 2004 12:39:49 -0800
From: homersimpson2@rogers.com (Homer J.)
Subject: CBC/BLOWFISH, NEWBIE HELP - CAN'T DECRYPT FROM SAVED FILE
Message-Id: <5abd563.0411101239.3e0903a2@posting.google.com>

Hello,

I'm wondering if the experienced PERL people can help me here.  

I'm stuck.  I'm trying to use Crypt::CBC using Blowfish to encrypt
some data.  I can get it to encrypt and decrypt OK as long as I assign
the ciphertext to a variable and decrpyt it from that variable all
within the same script execution.  However, when I save the ciphertext
to a text file and then subsequently open the file and read in the
ciphertext to a variable and finally try to decrypt the cipheredtext I
get garbage instead of my original test message.

Someone please help!   I'm sure it's, something obviously wrong that
I've done, but I can't seem to figure out what it is.

Homer
homersimpson2@rogers.com


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

Date: Wed, 10 Nov 2004 17:03:05 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 1.11: When shouldn't I program in Perl?
Message-Id: <cmthk9$m99$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

1.11: When shouldn't I program in Perl?

    When your manager forbids it--but do consider replacing them :-).

    Actually, one good reason is when you already have an existing
    application written in another language that's all done (and done well),
    or you have an application language specifically designed for a certain
    task (e.g. prolog, make).

    For various reasons, Perl is probably not well-suited for real-time
    embedded systems, low-level operating systems development work like
    device drivers or context-switching code, complex multi-threaded
    shared-memory applications, or extremely large applications. You'll
    notice that perl is not itself written in Perl.

    The new, native-code compiler for Perl may eventually reduce the
    limitations given in the previous statement to some degree, but
    understand that Perl remains fundamentally a dynamically typed language,
    not a statically typed one. You certainly won't be chastised if you
    don't trust nuclear-plant or brain-surgery monitoring code to it. And
    Larry will sleep easier, too--Wall Street programs not withstanding. :-)



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Wed, 10 Nov 2004 23:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 1.6: What is perl6?
Message-Id: <cmu6n5$1lt$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

1.6: What is perl6?

    At The Second O'Reilly Open Source Software Convention, Larry Wall
    announced Perl6 development would begin in earnest. Perl6 was an oft
    used term for Chip Salzenberg's project to rewrite Perl in C++ named
    Topaz. However, Topaz provided valuable insights to the next version of
    Perl and its implementation, but was ultimately abandoned.

    If you want to learn more about Perl6, or have a desire to help in the
    crusade to make Perl a better place then peruse the Perl6 developers
    page at http://dev.perl.org/perl6/ and get involved.

    Perl6 is not scheduled for release yet, and Perl5 will still be
    supported for quite awhile after its release. Do not wait for Perl6 to
    do whatever you need to do.

    "We're really serious about reinventing everything that needs
    reinventing." --Larry Wall



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: 10 Nov 2004 12:04:57 -0800
From: dean@realideas.com (funkyville)
Subject: Re: Grabbing a PDF file from the web...how?
Message-Id: <cfe020bf.0411101204.43bd67a0@posting.google.com>

Thanks all...got it working...your advice is greatly appreciated.


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

Date: Wed, 10 Nov 2004 18:36:23 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: how greedy is nongreedy in regexp ?
Message-Id: <cmtmqr$2me$1@sun3.bham.ac.uk>



Anno Siegel wrote:
> peter pilsl  <pilsl@goldfisch.at> wrote in comp.lang.perl.misc:
> 
>>
>>the following substitution does not what I want. So I ask myself where 
>>the knot in my brain is this time.
>>
>>I want to clean up urls and  make  	 => a/b/e/f
> 
> 
> The standard module File::Spec has canonpath() to do this.

But since this is a question about canonicalising URLs it would seem 
more appropriate to use the URI module.  However the canonical() method 
of URI doesn't do this.  Is this right or should it be considered a bug 
in URI?



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

Date: Wed, 10 Nov 2004 18:40:27 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: how greedy is nongreedy in regexp ?
Message-Id: <cmtn2f$2qh$1@sun3.bham.ac.uk>



peter pilsl wrote:

 > Subject: Re: how greedy is nongreedy in regexp ?

[ snip ]

Others have answered the question in the mssage body, but to answer the 
question in the subject line...

Non-greedyness is local.  Non-greedyness does _not_ trump finding the 
leftmost match.  When ther are two (non-)gready subexpressions the first 
ones (non-)greadyness tekes priority.



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

Date: 11 Nov 2004 07:07:41 +1100
From: ? the Platypus {aka David Formosa} <dformosa@zeta.org.au>
Subject: Re: Is this really legal?
Message-Id: <m33bzho4c2.fsf@dformosa.zeta.org.au>

Tad McClellan <tadmc@augustmail.com> writes:

> Bradd W. Szonye <bradd+news@szonye.com> wrote:
> 
> > I had trouble with a very similar construct:
> > 
> >     my $foo = 'stuff' if defined $bar;
> 
> 
> Me too, which is why I kicked myself when I found it clearly
> documented, and why I can cite from memory the documentation
> trail that would have saved me (and you).  :-)

I'm wondering if that construct should trigger warnings?

-- 
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.


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

Date: Wed, 10 Nov 2004 16:27:37 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Looking to improve program
Message-Id: <Zjrkd.2032$uT1.844@trndny03>

"Tom Ewall" <tewall@lycos.com> wrote in message
news:85bf428.0411100802.1d234182@posting.google.com...
> The following code looks for files in a directory with lables of "Run
> A" "Run B" "Run C" or "Run D".  Each of the files has a total line.
> It grabs the total, something like "$211,153" and strips out the "$"
> and the ",".
>
> The program works, but I'm sure there are more efficient/perl
> idiomatic ways of doing things than how I've done them here.  I'm
> looking for suggested improvements.

suggestions noted below:

> #!\Perl\bin\perl
>
> use strict;
use warnings;

> my $total;
> my @total;
> my $runA;
> my $runB;
> my $runC;
> my $runD;
> my @list;
> my $lmoDir = "/__lmo";

1) You generally should declare your variables in the smallest scope
possible, which usually means "not until you need them".
2) Even if you insist on declaring them all at once, at least don't
bother with so many extra declarations:
my ($total, @total, $runA, $runB, $runC, $runD, @list);
my $lmnoDir = '/__lmno';


> opendir(LMODIR, $lmoDir) or die "could not open LMO directory";

1) Using lexical file handles is preferred to bareword filehandles.
2) If the opendir fails, it'd be nice to know *why* it failed:

opendir $dir, $lmnoDir or die "Could not open directory: $!";

> my @allfiles = grep !/^\.\.?\z/, readdir LMODIR; # exclude . and ..
> files
> closedir(LMODIR);
>
> foreach my $file (@allfiles){

rather than reading all the file names into memory at once, I'd probably
read them one at a time, and pick out the ones I don't want within the
loop:

while (my $file = readdir ($dir)){
   next if $file =~ /^\.{1,2}$/;


>     open LMO, "$lmoDir/$file" or die "Cannot open file: $!";

again, lexical file handles are preferred:
open $lmo, "$lmoDir/$file" or die "Cannot open file: $!";

>     my @list=<LMO>;
>     foreach (@list) {

Again, no reason to slurp the entire file into memory:

while (<$lmo>){
    chomp;   #rather than chomping conditionally twice below

>         if (/Run/){
>             $run = "$_";

see the PerlFAQ "What's wrong with always quoting "$vars"?":
perldoc -q quoting

>             chomp ($run);
>         }
>         if (/Total/){
>             $total = "$_";
>             chomp ($total);
>         }
>     }
>     @total = split(/\t/, $total);
>     $total = @total[$#total - 2];

Do you really not know how many fields will *precede* the field you
want, and instead only know how many will follow?  If that's true, I
suppose this is okay.  Otherwise, if you know that the desired field
will always be, say, 2nd, I'd recommend eliminating the extraneous
array:

(undef, $total) = split (/\t/, $total);

As side notes, you should never use @ to access a single element of an
array.   You might also want to learn about negative subscripts to
arrays, to avoid the yucky $#total syntax.  That line could/should have
been:

$total = $total[-3];


>     if ($run eq 'Run A'){
>         $runA = $total;
>     }
>     if ($run eq 'Run B'){
>         $runB = $total;
>     }
>     if ($run eq 'Run C'){
>         $runC = $total;
>     }
>     if ($run eq 'Run D'){
>         $runD = $total;
>     }

This kind of structure screams for using a hash instead of four
independent variables:
my %run;  #before the for loop

if ($run =~ /^Run ([A-D])$/){
    $run{$1} = $total;
}


> }
>
> $_ = $runA;
> s/,//;
> s/\$//;
> $runA = $_;
>
> $_ = $runB;
> s/,//;
> s/\$//;
> $runB = $_;
>
> $_ = $runC;
> s/,//;
> s/\$//;
> $runC = $_;
>
> $_ = $runD;
> s/,//;
> s/\$//;
> $runD = $_;

Now that you have the hash, you can use it instead of four nearly
identical code fragments.  There's also no real reason to be assigning
to and from $_, rather than just using the variables you have.  You can
also combine the two substitutes:
foreach my $key (%run){
   $run{$key} =~ s/[,$]//g;
}

Hope this is helpful,
Paul Lalli



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

Date: Wed, 10 Nov 2004 13:14:41 -0500
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: Looking to improve program
Message-Id: <m3lld9inal.fsf@lap.athenahealth.com>

>>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:

  PL> foreach my $key (%run){
  PL>    $run{$key} =~ s/[,$]//g;

in recent perls values returns aliases to the actual values of a
hash. so that could become:

	s/[,$]//g for values %run ;

and since tr is faster for char operations:

	tr/,$//d for values %run ;

uri


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

Date: Wed, 10 Nov 2004 18:40:13 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Looking to improve program
Message-Id: <hgtkd.1170$5H4.464@trndny06>

"Uri Guttman" <uguttman@athenahealth.com> wrote in message
news:m3lld9inal.fsf@lap.athenahealth.com...
> >>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:
>
>   PL> foreach my $key (%run){
>   PL>    $run{$key} =~ s/[,$]//g;
>
> in recent perls values returns aliases to the actual values of a
> hash. so that could become:
>
> s/[,$]//g for values %run ;

huh.  I didn't realize that.  Good to know.  Thanks.

> and since tr is faster for char operations:
>
> tr/,$//d for values %run ;

Somehow I always manage to forget about tr///.  Thanks again.

Paul Lalli



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

Date: 11 Nov 2004 06:36:37 +1100
From: ? the Platypus {aka David Formosa} <dformosa@zeta.org.au>
Subject: Re: map()'s BLOCK [was: "Re: Q: re Inline and Benchmark"]
Message-Id: <m37joto5ru.fsf@dformosa.zeta.org.au>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:

> ? the Platypus {aka David Formosa}  <dformosa@zeta.org.au> wrote in
> comp.lang.perl.misc:

[...]

> > I don't think this is fair, perl brakes orthogonality when
> > orthogonality makes things harder.  When orthogonality makes things
> > easer then orthogonality shouldn't be broken.
> 
> That's an ideal.  In practice, Perl has broken orthogonality for all
> kinds of reasons.  Think of the use of filehandles.

I think your proving my point.  Filehandles are quite broken, hence
all the efforts with IO::Handle to provide us with an unbroken
version.  I think everyone would be happy if some of thouse useless
exceptions where done away with.

-- 
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.


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

Date: 10 Nov 2004 22:48:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: map()'s BLOCK [was: "Re: Q: re Inline and Benchmark"]
Message-Id: <cmu5r0$6jb$1@mamenchi.zrz.TU-Berlin.DE>

? the Platypus {aka David Formosa}  <dformosa@zeta.org.au> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> 
> > ? the Platypus {aka David Formosa}  <dformosa@zeta.org.au> wrote in
> > comp.lang.perl.misc:
> 
> [...]
> 
> > > I don't think this is fair, perl brakes orthogonality when
> > > orthogonality makes things harder.  When orthogonality makes things
> > > easer then orthogonality shouldn't be broken.
> > 
> > That's an ideal.  In practice, Perl has broken orthogonality for all
> > kinds of reasons.  Think of the use of filehandles.
> 
> I think your proving my point.  Filehandles are quite broken, hence

I'm not proving any point, I'm taking (and suggesting) a different
stance towards Perl's deficiencies.  It is a language that was never
designed, but developed from a modest beginning, *and* keeps an almost
unbroken chain of compatibility -- there must be some snags.  One
particularly messy example is filehandles, another is the existence
of various kinds of blocks with different capabilities.  The lack of
a decent case statement is another traditional deficiency.  I'm
taking the good with the bad.

> all the efforts with IO::Handle to provide us with an unbroken
> version.  I think everyone would be happy if some of thouse useless
> exceptions where done away with.

In Perl 5, it won't happen.  You must be talking Perl 6 :)  There,
we're getting the most fancy case statement ever designed: rules.
All control transfer will be (formally) through exceptions, so all
blocks will be equal.  I know nothing about IO, but I'll bet it will
be the neatest ever.

Anno




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

Date: 10 Nov 2004 13:30:34 -0800
From: zhilianghu@yahoo.com (Zhiliang Hu)
Subject: Re: perldoc problem on linux
Message-Id: <1daf0582.0411101330.332082ef@posting.google.com>

Joe Smith <Joe.Smith@inwap.com> wrote in message news:<bpjjd.579710$8_6.418708@attbi_s04>...
> Zhiliang Hu wrote:
> 
> > I have a strange problem - recently I newly setup a linux server and
> > installed perl 5.8, and when I tried to use "perldoc" (such as
> > "perldoc DBI"), nothing happens except as if I issued "source .cshrc"
> > (some personalized login message passes), then it's ready to take next
> > command.  However "perldoc" works normal for ~root (both accounts are
> > on "tcsh" shell).  Where should I check to solve it?
> 
> Have you looked at the obvious?
> 
>    linux% which perldoc
>    linux% echo $PATH
> 
>    linux# which perldoc
>    linux# echo $PATH
> 
> 	-Joe

Yes, I did - 'perldoc' is in /usr/local/bin/ and it is in both my and
~root's path.  (I double checked them and I still got the same as
before).

Following commands work fine:
 > perloc -V
 > perldoc -h
 > perldoc NONEexist    (this returns "No documentation found")
 > perldoc -l WWW::Search

but "perldoc WWW::Search" will show nothing but login prompts.

Zhiliang


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

Date: Wed, 10 Nov 2004 11:16:48 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: references to OTHER objects
Message-Id: <TPydnUJKctt2ow_cRVn-rA@adelphia.com>

daniel kaplan wrote:

> i was curious, and have to ask, not because i plan on doing it, just because
> it could happen...what if one piece of code calls the DESTROY() method,
> while a reference exists?

That will only happen if you call DESTROY() yourself, instead of letting 
Perl call it for you when appropriate. So don't do that. :-)

> protect from that?  not asking how, but am assuming there is probably a way
> to get the handle to the count of a referenced object/variable/etc.

Not really, at least from Perl. There are ways to fiddle with the 
reference count from C, which you can use if you're embedding a Perl 
interpreter into your app or extending Perl with an XS module.

> which, i am sorry, i must ask one more thing....i can't find it right now,
> but i was given flack for saying that aren't "dereferencing and casting the
> same thing?"

I wasn't giving you flack, simply pointing out that you're wrong. They 
are *not* the same thing. They're not the same in C either - where is 
this idea coming from?

> if you do have................$a = "cat"
> this is referencing:           $a_ref = \$ref;
> and this                          $$a_ref = "dog";
> is dereferencing....now to me, that's just casting a reference as a
> scalar...

Here's a similar example, in C:

int a = 0;

int *a_ref = &a;    // This is referencing

int b = *a_ref;     // This is dereferencing. It assigns the *value*
                     // of a_ref's target to b.

int c = (int)a_ref; // This is casting. It converts the *address*
                     // of a_ref's target to an integer value, and
                     // assigns that value to c.

There is no equivalent to casting in Perl. Perl is weakly typed - 
variables aren't declared as being ints, refs, strings, etc. So, there's 
no need to explicitly cast them from one type to another. To continue 
your example from above:

$a_ref = "cat";     # $a_ref is no longer a reference. It's a string.
$a_ref = 1.0;       # Now it's a float.
$a_ref = \$a;       # Now it's a reference again.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Wed, 10 Nov 2004 11:33:53 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: references to OTHER objects
Message-Id: <1100104502.224660@nntp.acecape.com>

"Sherm Pendley" <spamtrap@dot-app.org> wrote in message
news:TPydnUJKctt2ow_cRVn-rA@adelphia.com...
> daniel kaplan wrote:
>
> > protect from that?  not asking how, but am assuming there is probably a
way
> > to get the handle to the count of a referenced object/variable/etc.
>
> Not really, at least from Perl. There are ways to fiddle with the
> reference count from C, which you can use if you're embedding a Perl
> interpreter into your app or extending Perl with an XS module.

well obviosuly i won't need to do that, since obviosuly Perl seems to handle
this all

> I wasn't giving you flack, simply pointing out that you're wrong. They
> are *not* the same thing. They're not the same in C either - where is
> this idea coming from?
>
> int b = *a_ref;     // This is dereferencing. It assigns the *value*

here's where somehow years ago the two got melded together in my head , in
your line above, i always had to type:

int b = (int *)a_ref;

perhaps this was because of the warning level set on my compiler, so to make
it shut up i had to "cast" a_ref as an int pointer.  then in my head it
become one and the same with:

int b = (int *) some_void_ptr   or     int b = (int)some_other_value

thanks!

daniel





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

Date: Wed, 10 Nov 2004 11:57:57 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: references to OTHER objects
Message-Id: <v5CdnRjCGZUS1Q_cRVn-pA@adelphia.com>

daniel kaplan wrote:

> here's where somehow years ago the two got melded together in my head , in
> your line above, i always had to type:
> 
> int b = (int *)a_ref;

That's just a cast, no dereferencing. You might have meant to do both:

int b = *(int *)a_ref;

Either that, or you need to declare b as the type to which you're 
casting a_ref:

int *b = (int *)a_ref;

Your example as given assigns an int* value to an int. You'd get a 
warning along the lines of "assignment of pointer to integer without a 
cast" or similar.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: 10 Nov 2004 10:09:56 -0800
From: gsprince@gmail.com (Prince)
Subject: Re: replace pattern including newline : perl version 5.8
Message-Id: <97efbce6.0411101009.7f3d975f@posting.google.com>

Thank you both!

Abigail, that was my mistake. I intended "lowe case" only. Initially I
had the data file in upper case.

Regards,
Prince.

Abigail <abigail@abigail.nl> wrote in message news:<slrncog20g.d9i.abigail@alexandra.abigail.nl>...
> Prince Kumar (gspk@yahoo.com) wrote on MMMMLXXXI September MCMXCIII in
> <URL:news:629275ba.0411021351.721f541f@posting.google.com>:
> $$  I have a file with the following contents.
> $$  
> $$  drop table tabl1;
> $$  
> $$  create table tabl1 (
> $$  col1
> $$  col2
> $$  col3);
> $$  
> $$  drop table tabl2;
> $$  
> $$  create table tabl2 (
> $$  col1
> $$  col2);
> $$  
> $$  ..
> $$  
> $$  I want to replace "create table * );" with 
> $$  "create table * ) IN TBSP1;" 
> $$  
> $$  I tried the following, but I am not getting the desired result.
> $$  
> $$  perl -p -e 'undef $/; s/^CREATE TABLE (.*?)\);$/CREATE TABLE $1 \) IN
> $$  TBSP/s' my_input_file.
> $$  
> $$  Your help is appreciated.
> 
> 
> If you want to change "create table * );", then why do you write
> "CREATE TABLE" in the s///? Upper case isn't the same as lower
> case in te absence of /i.
> 
> 
> Abigail


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

Date: 10 Nov 2004 10:42:09 -0800
From: gsprince@gmail.com (Prince)
Subject: Re: replace pattern including newline : perl version 5.8
Message-Id: <97efbce6.0411101042.285662f5@posting.google.com>

Hi John,

The given solution works perfect. What does -073 option do?

Thanks,

"John W. Krahn" <someone@example.com> wrote in message news:<7PThd.85034$9b.53687@edtnps84>...
> Prince Kumar wrote:
> > I have a file with the following contents.
> > 
> > drop table tabl1;
> > 
> > create table tabl1 (
> > col1
> > col2
> > col3);
> > 
> > drop table tabl2;
> > 
> > create table tabl2 (
> > col1
> > col2);
> > 
> > ..
> > 
> > I want to replace "create table * );" with 
> > "create table * ) IN TBSP1;" 
> > 
> > I tried the following, but I am not getting the desired result.
> > 
> > perl -p -e 'undef $/; s/^CREATE TABLE (.*?)\);$/CREATE TABLE $1 \) IN
> > TBSP/s' my_input_file.
> 
> 
> perl -073pe's/^(\s*create\s+table\s+(\S+)\s+\((?s:.+?)\));/$1 IN \U$2;/i' 
> my_input_file
> 
> 
> 
> John


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

Date: 10 Nov 2004 11:00:25 -0800
From: gsprince@gmail.com (Prince)
Subject: Re: replace pattern including newline : perl version 5.8
Message-Id: <97efbce6.0411101100.79fa372e@posting.google.com>

Would you also, please explain "((?s:.+?)\))". I tried the perlre, but
couldn't understand completely.

Thanks,

"John W. Krahn" <someone@example.com> wrote in message news:<7PThd.85034$9b.53687@edtnps84>...
> Prince Kumar wrote:
> > I have a file with the following contents.
> > 
> > drop table tabl1;
> > 
> > create table tabl1 (
> > col1
> > col2
> > col3);
> > 
> > drop table tabl2;
> > 
> > create table tabl2 (
> > col1
> > col2);
> > 
> > ..
> > 
> > I want to replace "create table * );" with 
> > "create table * ) IN TBSP1;" 
> > 
> > I tried the following, but I am not getting the desired result.
> > 
> > perl -p -e 'undef $/; s/^CREATE TABLE (.*?)\);$/CREATE TABLE $1 \) IN
> > TBSP/s' my_input_file.
> 
> 
> perl -073pe's/^(\s*create\s+table\s+(\S+)\s+\((?s:.+?)\));/$1 IN \U$2;/i' 
> my_input_file
> 
> 
> 
> John


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

Date: 10 Nov 2004 11:42:49 -0800
From: sigzero@gmail.com (Robert)
Subject: SWITCH: question on evaluation
Message-Id: <5b49f5aa.0411101142.1bf2734a@posting.google.com>

If I have a whole lot of cases in a SWITCH: statement does the whole
statement get parsed or does it exit on a first match?

I was just curious...

robert


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

Date: Wed, 10 Nov 2004 19:59:31 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: SWITCH: question on evaluation
Message-Id: <Dqukd.1235$jP4.458@trndny07>

"Robert" <sigzero@gmail.com> wrote in message
news:5b49f5aa.0411101142.1bf2734a@posting.google.com...
> If I have a whole lot of cases in a SWITCH: statement does the whole
> statement get parsed or does it exit on a first match?

"parsing" is something that happens at compile time.  That's how syntax
errors are found.  I think you meant "does the whole statement get
*evaluated*?".  For the answer to that, we turn to the documentation:

perldoc Switch
     However, when a "case" block has been executed control is
     automatically transferred to the statement after the
     immediately enclosing "switch" block, rather than to the
     next statement within the block. In other words, the success
     of any "case" statement prevents other cases in the same
     scope from executing. But see "Allowing fall-through" below.


We can see this behavior ourselves with a simple test:
#!/usr/bin/perl
use strict;
use warnings;
use Switch;

sub foo{
   print "Foo() being evaluated\n";
   return 5;
}

sub bar {
   print "Bar() being evaluated\n";
   return 10;
}

sub baz {
   print "Baz() being evaluated\n";
   return 15;
}

my $foo = 10;

switch ($foo){

   case foo()  {print "matched to foo()\n";}
   case bar()  {print "matched to bar()\n";}
   case baz()  {print "matched to baz()\n";}
}

__END__
Foo() being evaluated
Bar() being evaluated
matched to bar()


From the above, it is apparent that the third case is never evaluated.

> I was just curious...

Hope this helps,
Paul Lalli



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

Date: Wed, 10 Nov 2004 18:52:18 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Using $SIG{"ALRM"}  assignment inside a subroutine ...
Message-Id: <cmtnnm$33f$1@sun3.bham.ac.uk>



torahul@gmail.com wrote:

> [...] regarding calling subroutine withour '&' prefix, I wasn't aware of
> 'this' way of calling subroutine (and hence difference between both!).
> The book which I am reading might be either older edition or has not
> make these things clear about subroutine -- at least till the point I
> have finished reading :-).
> 
> Usage of 'my' instead of 'local', 'use strict' are also new to me --
> and after browsing little thru online perl documentation, is making
> things clearer now.

Sounds like your book predates Perl5.  A lot changed between Perl4 and 
Perl5.  There is no point trying to learn Perl5 using a book about Perl4.



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

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


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