[18693] in Perl-Users-Digest
Perl-Users Digest, Issue: 861 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 9 11:10:36 2001
Date: Wed, 9 May 2001 08:10:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <989421015-v10-i861@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 9 May 2001 Volume: 10 Number: 861
Today's topics:
Re: Question about "->" operator <gtoomey@usa.net>
Re: Question about "->" operator <trondmm-usenet@crusaders.no>
Re: Question about "->" operator (Randal L. Schwartz)
Reading from empty file handle OR from a pipe <ronald.fischer@deadspam.com>
Re: Reading from empty file handle OR from a pipe (Anno Siegel)
Re: Search ... <zlach@yahoo.com>
Re: Search ... <zlach@yahoo.com>
Re: Seeking a PERL Tutorial <fty@mediapulse.com>
Re: Seeking a PERL Tutorial <bart.lateur@skynet.be>
Re: Sort String <bart.lateur@skynet.be>
Re: unicode support in perl 5.6 -- I'm trying to get it <eike.grote.extern@fmis.de>
Re: unicode support in perl 5.6 -- I'm trying to get it <thoren@southern-division.com>
Re: unicode support in perl 5.6 -- I'm trying to get it <thoren@southern-division.com>
Re: unicode support in perl 5.6 -- I'm trying to get it <pne-news-20010509@newton.digitalspace.net>
Re: Why would printing to FILEHANDLE wipe out contents <colin.soper@oracle.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 9 May 2001 20:34:40 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: Question about "->" operator
Message-Id: <cR8K6.22913$482.107447@newsfeeds.bigpond.com>
"Ed Napier" <napes@attglobal.net> wrote in message
news:3AF86D5C.E3848F99@attglobal.net...
> I feel as though I'm misunderstanding something. I think the thing I'm
> missing is a complete understanding of the "->", the infix dereference
> operator.
I'm confused about another use of ->.
Why does sub { ...} define an anonymous subroutine, but sub { ...}->()
define and execute it?
I cannot find a reference to this in perldoc.com (maybe I wasn't looking
hard enough).
gtoomey
------------------------------
Date: Wed, 9 May 2001 14:15:17 +0200
From: "Trond Michelsen" <trondmm-usenet@crusaders.no>
Subject: Re: Question about "->" operator
Message-Id: <8yaK6.7884$gX3.529472@news3.oke.nextra.no>
"Gregory Toomey" <gtoomey@usa.net> wrote in message
news:cR8K6.22913$482.107447@newsfeeds.bigpond.com...
> I'm confused about another use of ->.
> Why does sub { ...} define an anonymous subroutine, but sub { ...}->()
> define and execute it?
Because -> dereferences the expression to it's left.
normally you create a reference, and use the -> operator on it like
this:
my $func = sub { ... };
$func->();
or
my $hashref = get_hashref();
print $hashref->{some_key};
but you can always attach the -> to any expression that returns a
reference, to use that reference directly.
sub { ... }->();
get_hashref()->{some_key};
> I cannot find a reference to this in perldoc.com (maybe I wasn't
looking
> hard enough).
I think perlreftut is a good place to look.
--
Trond Michelsen
------------------------------
Date: 09 May 2001 07:03:34 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Question about "->" operator
Message-Id: <m1k83q4o21.fsf@halfdome.holdit.com>
>>>>> "Gregory" == Gregory Toomey <gtoomey@usa.net> writes:
Gregory> "Ed Napier" <napes@attglobal.net> wrote in message
Gregory> news:3AF86D5C.E3848F99@attglobal.net...
>> I feel as though I'm misunderstanding something. I think the thing I'm
>> missing is a complete understanding of the "->", the infix dereference
>> operator.
Gregory> I'm confused about another use of ->.
Gregory> Why does sub { ...} define an anonymous subroutine, but sub {
Gregory> ...}->() define and execute it?
Gregory> I cannot find a reference to this in perldoc.com (maybe I
Gregory> wasn't looking hard enough).
"perldoc perlref" =>
3. Subroutine calls and lookups of individual array
elements arise often enough that it gets cumbersome to
use method 2. As a form of syntactic sugar, the
examples for method 2 may be written:
$arrayref->[0] = "January"; # Array element
$hashref->{"KEY"} = "VALUE"; # Hash element
$coderef->(1,2,3); # Subroutine call
That's your one, that last one right there. Invented by me on a dare
that I couldn't get Chip Salzenberg, the 5.004 pumpking, to add at
least one significant feature to Perl during the *gamma* release
phase. I won. :)
Prior to that, you had to use the other kind of dereferencing:
&{$coderef}(@args)
This cleaned it up to:
$coderef->(@args)
and 5.6 allows you to drop the arrow in some places as well. Chip
couldn't do that without breaking something else; I'm not sure what
changed to permit that.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 09 May 2001 14:41:51 +0200
From: Ronald Fischer <ronald.fischer@deadspam.com>
Subject: Reading from empty file handle OR from a pipe
Message-Id: <7qfr8xyofsg.fsf@demchh2msx.icn.siemens.de>
Depending on some switch (say), my program should sometimes do this:
while(<>)
{
... process every line from the arguments or stdin
}
and sometimes do this:
open(X,"myfilter|");
while(<X>)
{
... process every line coming from my filter
}
I am looking at an elegant way to unify these possibilities. Of course
in this particular case, one would simply put the "process every line"
part in a sub and do something like
if($flag)
{ &process($_) while(<>); }
else
{ open(X,...); &process($_) while(<X>);}
but suppose this alternative is not an option (my example is a highly
simplified version from the real thing). Is there an alternative? What I
would like to do is something in the spirit of:
# This code is wrong, of course. Wrong, wrong, wrong!
$filehandle = $flag ? (empty file handle) : (open(X,...),X);
while(<$filehandle>)
{
... process every line ....
}
Can somewhat like this be done at all? The closest I got was the
standard module FileHandle, but if I understand it right, it can't
return anything which behaves like the empty filehandle, <>, with its
builtin magic.
Ronald
--
Do NOT reply to the address given in the From: header. If you want to
reply by mail, use the following address (after deleting the XXX):
Ronald Otto Valentin Fischer <rovfXXX@thekeyboard.com>
(Tired of getting spam after posting a message? http://www.deadspam.com)
------------------------------
Date: 9 May 2001 14:08:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reading from empty file handle OR from a pipe
Message-Id: <9dbj18$92s$1@mamenchi.zrz.TU-Berlin.DE>
According to Ronald Fischer <ronald.fischer@deadspam.com>:
> Depending on some switch (say), my program should sometimes do this:
>
> while(<>)
> {
> ... process every line from the arguments or stdin
> }
>
> and sometimes do this:
>
> open(X,"myfilter|");
> while(<X>)
> {
> ... process every line coming from my filter
> }
>
> I am looking at an elegant way to unify these possibilities. Of course
> in this particular case, one would simply put the "process every line"
> part in a sub and do something like
>
> if($flag)
> { &process($_) while(<>); }
> else
> { open(X,...); &process($_) while(<X>);}
my $fh;
if ( $flag ) {
$fh = \ *ARGV;
} else {
open( $fh, ...);
}
process( $_) while <$fh>;
Anno
------------------------------
Date: Wed, 9 May 2001 15:27:18 +0200
From: "Zlach" <zlach@yahoo.com>
Subject: Re: Search ...
Message-Id: <9dbglj$3cg$1@ss204.hinet.hr>
"Mario Rizzuti" <diab.lito@usa.net> wrote in message
news:SZVJ6.8960$oa2.192733@news6.giganews.com...
>
> Zlach <zlach@yahoo.com> wrote in message 9d92bi$2uj$1@ss204.hinet.hr...
> > I'd like to make a "search" for my web page. Options would be searching
by
> > author and searching by title words.
> > What is the best and most efficient programming language to do that ?
>
> Perl and PHP.
> Maybe PHP is a little bit more efficient vs CGI.
Is this complicated to do in Perl ?
Zlach
------------------------------
Date: Wed, 9 May 2001 15:26:23 +0200
From: "Zlach" <zlach@yahoo.com>
Subject: Re: Search ...
Message-Id: <9dbgju$3ae$1@ss204.hinet.hr>
"Todd Smith" <todd@designsouth.net> wrote in message
news:1eVJ6.78255$U4.17308797@news1.rdc1.tn.home.com...
> "Zlach" <zlach@yahoo.com> wrote in message
> news:9d92bi$2uj$1@ss204.hinet.hr...
> > I'd like to make a "search" for my web page. Options would be searching
by
> > author and searching by title words.
> > What is the best and most efficient programming language to do that ?
> >
> > Thanks !
> > Zlach
> >
> >
> >
>
> Just find a free script online that's already built to do that. There are
> lots of them. Some search engines can stick code in your website to let
you
> search your site using their technology. Try that.
Thanks !
Have you any links for that, maybe ?
Zlach
------------------------------
Date: Wed, 09 May 2001 13:34:06 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: Seeking a PERL Tutorial
Message-Id: <iHbK6.49998$sP6.3174265@news3.aus1.giganews.com>
"Neal Weissman" <nweissma@mathlab.sunysb.edu> wrote in message
news:Pine.GSO.4.05.10105081730411.16383-100000@SunRa.mathlab.sunysb.edu...
>
> Please recommend a PERL tutorial.
>
> Thanks.
$3.00 to write and submit FAQ
$12.75 dollars to keep checking NG for replies
$3.40 reading replies
Look on posters face as he realizes he asked a FAQ and could have used a
search engine or just check the Perl FAQ...Priceless.
------------------------------
Date: Wed, 09 May 2001 14:38:59 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Seeking a PERL Tutorial
Message-Id: <qcliftctb084ljs77p5hh5csvhb7knusqf@4ax.com>
F. Xavier Noria wrote:
>: Please recommend a PERL tutorial.
>
>Choose one:
>
> http://www.perl.com/reference/query.cgi?tutorials
This one *still* isn't listed:
"Practical Perl Programming"
<http://www.cs.cf.ac.uk/Dave/PERL/>
>though I encourage you to get a copy of "Learning Perl", aka "The
>Llama Book", the best intro to a programming language I've ever read.
I tend to agree. IMO, there's something about books that make them
easier to grok than anything from a computer screen alone. And this
particular book is a good choice. It'll have you airborne in under a few
hours.
--
Bart.
------------------------------
Date: Wed, 09 May 2001 10:49:00 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Sort String
Message-Id: <gm7iftk71tjle40mp2kuosv936cd9pvg9i@4ax.com>
Uri Guttman wrote:
[quote:]
> RLS> and never use split /(....)/.
Sometimes it's handy. For example, there's this $`,$&, $' replacement:
my($prematch, $match, $postmatch) = split /($re)/, $_, 2;
where $re is supposed not to contain any capturing parentheses itself.
>well, not until you know why you need to use it. i have rarely used it
>but it has a use nonetheless. sometimes you want to keep the fields and
>their delims (which could be odd and not just fixed strings).
One time where I wanted it, was in a simple arithmetic expression
evaluator, that only knew about "+" and "-":
$_ = '2+3-5+6--1';
@split = split /([+-]+)/;
but for this, split with lookahead works just as nice:
@terms = split /(?=[+-]+)/;
The '+' and '-' signs are considered part of the term, here. Change the
sign of the number depending on whether the count of minusses is odd or
even, and simply add the terms together. No eval necessary.
--
Bart.
------------------------------
Date: Wed, 09 May 2001 09:09:02 +0200
From: Eike Grote <eike.grote.extern@fmis.de>
Subject: Re: unicode support in perl 5.6 -- I'm trying to get it to work l
Message-Id: <3AF8ED0E.E77B3647@fmis.de>
Ilya Zakharevich wrote:
>
> [A complimentary Cc of this posting was sent to
> Eike Grote
> <eike.grote@epost.de>], who wrote in article <3AF7A69E.AE5CA0CB@fmis.de>:
> > use utf8;
> >
> > @c = (chr(0x00e0), chr(0x00e1), chr(0xddc0));
> >
> > print join("",@c[0,1]),"\n";
> > print join("",@c[0,2]),"\n";
Oops... now I see my mistake: @c[0,2] ne @c[0..2]
But still the question remains why the rather simple character
"à" (0x00e0) causes an error message:
# perl -Mutf8 -e 'chr(0x00e0) =~ /\p{IsAlpha}/;'
Malformed UTF-8 character (unexpected non-continuation byte 0x00 after start
byte 0xe0) in pattern match (m//) at -e line 1.
Eike
--
Eike Grote, ConSol GmbH
E-Mail: eike.grote@epost.de
------------------------------
Date: 09 May 2001 09:52:14 +0200
From: Thoren Johne <thoren@southern-division.com>
Subject: Re: unicode support in perl 5.6 -- I'm trying to get it to work l
Message-Id: <m3d79jez81.fsf@thoren.southern-division.com>
Eike Grote <eike.grote.extern@fmis.de> writes:
> But still the question remains why the rather simple character
> "à" (0x00e0) causes an error message:
>
> # perl -Mutf8 -e 'chr(0x00e0) =~ /\p{IsAlpha}/;'
> Malformed UTF-8 character (unexpected non-continuation byte 0x00 after
> start byte 0xe0) in pattern match (m//) at -e line 1.
isn't it written:
perl -Mutf8 -e 'chr(0x00e0) =~ /\pP{IsAlpha}/;'
^^^
HTH
--
# Thoren Johne - 8#X - thoren@southern-division.com
# Southern Division Classic Bikes - www.southern-division.com
;*42=sub{10.32.56.35.X=>=>&{sub{H=>&{sub{P=>&{sub{A=>&{sub{J=>}}}}}}}}}=>
*0=sub{'Just Another Perl Hacker 8#X'=>}=>print!&{*0}=>(reverse(&{*42}));
------------------------------
Date: 09 May 2001 10:08:44 +0200
From: Thoren Johne <thoren@southern-division.com>
Subject: Re: unicode support in perl 5.6 -- I'm trying to get it to work l
Message-Id: <m38zk7eygj.fsf@thoren.southern-division.com>
Thoren Johne <thoren@southern-division.com> writes:
> Eike Grote <eike.grote.extern@fmis.de> writes:
>
> > But still the question remains why the rather simple character
> > "à" (0x00e0) causes an error message:
> >
> > # perl -Mutf8 -e 'chr(0x00e0) =~ /\p{IsAlpha}/;'
> > Malformed UTF-8 character (unexpected non-continuation byte 0x00 after
> > start byte 0xe0) in pattern match (m//) at -e line 1.
>
> isn't it written:
>
> perl -Mutf8 -e 'chr(0x00e0) =~ /\pP{IsAlpha}/;'
pardon, that's rubbish - my fault.
--
# Thoren Johne - 8#X - thoren@southern-division.com
# Southern Division Classic Bikes - www.southern-division.com
eval('+qjmw!:wqv"C/kplavyVctj&Aacke`\l "I &8%im_"'^(1x42)^((((((('j'.'2'x
5).'a'.'3'x5).'p'.'5'x5).'h'.'7'x5).'8'.'11'x2).'#'.'13'x2).'X'.'17'x2));
------------------------------
Date: Wed, 09 May 2001 10:46:10 +0200
From: Philip Newton <pne-news-20010509@newton.digitalspace.net>
Subject: Re: unicode support in perl 5.6 -- I'm trying to get it to work l
Message-Id: <1u0iftkhuge6gu38udoshf749rmkghp4mt@4ax.com>
On 8 May 2001 21:59:25 GMT, Eli the Bearded <elijah@workspot.net>
wrote:
> What is U+DDC0 anyway?
An unpaired low surrogate.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Wed, 09 May 2001 14:48:07 +0100
From: Colin Soper <colin.soper@oracle.com>
Subject: Re: Why would printing to FILEHANDLE wipe out contents of that file?
Message-Id: <3AF94A97.B0998835@oracle.com>
Hi,
Have you tried:
open (LOG, ">>$log") || die;
instead of:
open (LOG, ">$log") || die;
so that it appends to the file?
Regards
Colin.
Arvin Portlock wrote:
> I have a REALLY puzzling problem that I don't expect anybody
> to answer but perhaps someone can suggest a direction I might
> investigate. Basically, I am opening a filehandle, printing some
> information (successfully) to the file, but a subsequent print wipes
> out the previous information I just printed. It's as if the filehandle
> is being closed and reopened between the two prints but that's
> not happening in the code.
>
> The rough details make it even more confusing. I am generating
> multiple logfiles from within a foreach loop. Only the first logfile
> generated by the loop has this problem. All subsequent files
> print fine. This file also has more data than the others but I'm
> not talking about a LOT of data, only about 1 Kb. Lastly, here's
> the kicker, when I run the program on a DIFFERENT Unix system,
> using the exact same data, everything works fine.
>
> Can this have something to do with flushing, whatever that is?
> What sorts of things could cause this persistent problem? What
> kinds of diagnostics can I try to pinpoint the problem?
>
> Roughly here is what's happening:
>
> foreach $log (keys %logs) { # thus files are guaranteed unique
> open (LOG, ">$log") || die;
> print LOG $header || die;
> my $line;
> foreach $error (@{$errors{$log}}) {
> $line .= "$error\n";
> }
> # Breakpoint here confirms log has $header information
> print LOG $line || die;
> # Breakpoint here confirms file is now EMPTY!
> print LOG $footer || die;
> # Breakpoint here confirms file contains only the $footer
> close (LOG);
> }
>
> There are no next or last statements anywhere within the loop
> which might cause the file to be reopened. Needless to say, nor
> does it die at any point. Again, it only happens to the first file in
> the loop, and it doesn't happen at all on another Unix machine.
>
> How do I go about diagnosing this problem?
------------------------------
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 861
**************************************