[25264] in Perl-Users-Digest
Perl-Users Digest, Issue: 7509 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 12 00:05:59 2004
Date: Sat, 11 Dec 2004 21:05:05 -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 Sat, 11 Dec 2004 Volume: 10 Number: 7509
Today's topics:
Re: FAQ 4.22: How do I expand function calls in a strin <nobull@mail.com>
Re: grammar function [OT - English Grammar] <barbr-en_delete_@online.no.invalid>
Re: grammar function <usenet@morrow.me.uk>
Re: How can I strip keywords out of a search string <spamtrap@dot-app.org>
Re: How can I strip keywords out of a search string <pobugfix@peterlink.ru>
Re: How can I strip keywords out of a search string <spamtrap@dot-app.org>
Re: Is this possible in perl? <nobull@mail.com>
Re: multiple webpages sharing a dataset reference <wyzelli@yahoo.com>
Re: Obtaining length of binary string <usenet@morrow.me.uk>
Re: Obtaining length of binary string <usenet@morrow.me.uk>
Re: Paragraph separation for DOS files on Unix <usenet@morrow.me.uk>
Re: Passing hashes to a function <cwilbur@mithril.chromatico.net>
Re: Question on loops and return values <usenet@morrow.me.uk>
Re: Regaular Expression <nobull@mail.com>
Re: why the following HereDoc print don't work? <usenet@morrow.me.uk>
Re: why the following HereDoc print don't work? <usenet@morrow.me.uk>
Re: why the following HereDoc print don't work? <spamtrap@dot-app.org>
Re: why the following HereDoc print don't work? <spamtrap@dot-app.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 11 Dec 2004 21:53:19 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: FAQ 4.22: How do I expand function calls in a string?
Message-Id: <cpfpv3$3c3$1@sun3.bham.ac.uk>
brian d foy wrote:
> In article <cpa3f6$c5p$1@sun3.bham.ac.uk>, Brian McCauley
> <nobull@mail.com> wrote:
>
>
>>PerlFAQ Server wrote:
>>
>>>4.22: How do I expand function calls in a string?
>>
>>> See also ``How can I expand variables in text strings?'' in this section
>>> of the FAQ.
>>
>>This "See also" is inappropriate.
>
>
> I don't no about inappropriate, but that answer really sucks.
> I'll write a new one.
I assure you it's a order of magnitude better than it used to be. For a
very long time it included the statement that ${\(EXPR)} would evaluate
EXPR in a scalar context. A statement that is simply (and trivally
demonstrably) false!
I think the current answer is excellent. If you alter it then take care
not to re-introduce old errors.
------------------------------
Date: Sat, 11 Dec 2004 21:07:52 +0100
From: Kåre Olai Lindbach <barbr-en_delete_@online.no.invalid>
Subject: Re: grammar function [OT - English Grammar]
Message-Id: <lhkmr0tb9tjd3s5gnlstfu3v6f10tsjcmq@4ax.com>
On Sat, 11 Dec 2004 13:23:11 -0500, "Matt Garrish"
<matthew.garrish@sympatico.ca> wrote:
>"? the Platypus {aka David Formosa}" <dformosa@zeta.org.au> wrote in message
>news:m3y8g5flkj.fsf@dformosa.zeta.org.au...
>> "Paul Lalli" <mritty@gmail.com> writes:
>>
>>> "Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message
>>> news:HJmdnb8C-OEc-CvcRVn-pw@speakeasy.net...
>>> >
>>> > chair remains chair if there are one or zero.
>>>
>>> You have "zero chair"? "zero desk"? That doesn't especially sound like
>>> correct (American) English to me.
>>
>> I have three chairs.
>> I have two chairs.
>> I have I chair;
>> I have no chairs;
>>
>>> Singular is used for one item.
>>> Plural is used for not-one items.
>>
>> Looks like it.
>
>Looks are always deceiving:
>
>You have no senses at all
>You have no sense at all
Strange things also happens when one also deals with non-whole
numbers:
I now have 2 1/2 (two-and-a-half) chair, after you partyed here last
night.
I now have 2.5 chairs, after you partyed here last night.
(At least so it goes in Norwegian :)
--
mvh/Regards Kåre Olai Lindbach
(News: Remove '_delete_' and '.invalid')
(HTML-written email from unknown will be discarded)
------------------------------
Date: Thu, 9 Dec 2004 21:31:02 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: grammar function
Message-Id: <mpsm82-vqi.ln1@osiris.mauzo.dyndns.org>
Quoth Uri Guttman <uri@stemsystems.com>:
> >>>>> "KS" == Ken Sington <ken_sington@nospam_abcdefg.com> writes:
>
> KS> And I'm using American English where colour became color and
> KS> centre became center.
>
> KS> Or worst, "culla" "centa".
>
> s/t/e/ since we are being grammar pedants in this thread. :)
s/ea/\x{0294}\x{0259}/ while we're about it (to be applied after Uri's).
:)
Ben
--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # ben@morrow.me.uk
------------------------------
Date: Sat, 11 Dec 2004 16:39:31 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How can I strip keywords out of a search string
Message-Id: <ho-dnUW4f5yJ9CbcRVn-jw@adelphia.com>
Andrew Tkachenko wrote:
> blnukem wrote on 11 Декабрь 2004 12:15:
>
>
>>How can I strip keywords "machinery liquidator" out of a search string I
>>cant seem to loose the "web/" in my query results
>>
>>my $String =
>>'http://msxml.excite.com/info.xcite/search/web/machinery%2Bliquidator';
>
> URI.pm will help you
Did you *try* URI.pm with the string shown? Note that the query is
passed as extra path info, *not* separated by a "?" - URI.pm's path()
method returns everything after the host name, and its query() method
returns undef.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Sun, 12 Dec 2004 04:05:12 +0000
From: Andrew Tkachenko <pobugfix@peterlink.ru>
Subject: Re: How can I strip keywords out of a search string
Message-Id: <cpg5kt$o93$1@news.rol.ru>
Sherm Pendley wrote on 11 Декабрь 2004 21:39:
> Andrew Tkachenko wrote:
>
>> blnukem wrote on 11 Декабрь 2004 12:15:
>>
>>
>>>How can I strip keywords "machinery liquidator" out of a search string I
>>>cant seem to loose the "web/" in my query results
>>>
>>>my $String =
>>>'http://msxml.excite.com/info.xcite/search/web/machinery%2Bliquidator';
>>
>> URI.pm will help you
>
> Did you *try* URI.pm with the string shown? Note that the query is
> passed as extra path info, *not* separated by a "?" - URI.pm's path()
> method returns everything after the host name, and its query() method
> returns undef.
>
> sherm--
>
my $uri = new
URI("http://msxml.excite.com/info.xcite/search/web/machinery%2Bliquidator");
print "Domain:", $uri->authority, "\n", "Query:", ($uri->path_segments)[-1],
"\n";
Why not ? I'm too lazy to care about parsing URIs by hand.
If I do something wrong, I'd appreciate you comments.
--
Andrew
------------------------------
Date: Sat, 11 Dec 2004 21:05:04 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How can I strip keywords out of a search string
Message-Id: <8Imdnaq4mL_MOibcRVn-vA@adelphia.com>
Andrew Tkachenko wrote:
> my $uri = new
> URI("http://msxml.excite.com/info.xcite/search/web/machinery%2Bliquidator");
> print "Domain:", $uri->authority, "\n", "Query:", ($uri->path_segments)[-1],
> "\n";
>
> Why not ? I'm too lazy to care about parsing URIs by hand.
Two reasons:
First, the above approach only works if the query string has no '/'s.
And second, blnukem didn't ask about parsing URIs - he asked why his
regex wasn't matching what he thought it should. Neither you nor I knows
for sure whether he's actually processing URIs for real, or simply using
them as an exercise for learning regexes.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Sat, 11 Dec 2004 19:07:03 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Is this possible in perl?
Message-Id: <cpfg7c$s5d$1@sun3.bham.ac.uk>
Peter Scott wrote:
> In article <cpa5rv$d94$1@sun3.bham.ac.uk>,
> Brian McCauley <nobull@mail.com> writes:
>
> {
>> no strict 'refs';
>> $func = $xml->get_func_name();
>> "My::Module::XMLfunc::$func"->();
>> }
>
>
> Why not
>
> {
> my $func = $xml->get_func_name();
> My::Module::XMLfunc::{$func}->();
> }
Well appart from the missing $ there's nothing wrong with that.
However I kinda prefer manipulations of the symbol table to look like
what they are.
------------------------------
Date: Sun, 12 Dec 2004 03:44:43 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: multiple webpages sharing a dataset reference
Message-Id: <L8Pud.69483$K7.16716@news-server.bigpond.net.au>
"sam" <sam.wun@authtec.net> wrote in message
news:cpbo3v$6qt$1@news.hgc.com.hk...
: Hi,
<snip>
: Therefore the procedure may be:
:
: Query webpage -> $dataset -> Result webpage
That looks like an ordinary CGI process to me...
--
Wyzelli
------------------------------
Date: Thu, 9 Dec 2004 21:13:14 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Obtaining length of binary string
Message-Id: <aorm82-vqi.ln1@osiris.mauzo.dyndns.org>
Quoth Perl User <ravi@none.nowhere.com>:
> On Fri, 3 Dec 2004, Ben Morrow wrote:
> > Quoth Perl User <ravi@none.nowhere.com>:
> >>
> >> I read encrypted data from a server and save it in a variable. Now, I need
> >> to send this back to the server along with a number that tells how many
> >> bytes long the binary data is.
> >>
> >> I've tried
> >> $x = read_data_from_server($args);
> >> $y = length $x;
> >> send_data_to_server($x,$y);
> >>
> >> I am not sure if the length function is the right way to count the number
> >> of bytes in the string $x. Can someone please show me how to do this?
> >
> > It is, provided you've told perl that your data is binary not textual.
> > Make sure you use binmode on the socket filehandle.
>
> Thanks Ben and everyone else for helping me out! I realized that I was not
> using the "use bytes" pragma at one particular place in the program, and
> this was causing it to fail.
Don't do that! It doesn't do what you think it does (well, it doesn't do
what you want here, anyway). Use binmode on the filehandle (which you
should be doing anyway) and length will give the byte-length.
Ben
--
Although few may originate a policy, we are all able to judge it.
- Pericles of Athens, c.430 B.C.
ben@morrow.me.uk
------------------------------
Date: Thu, 9 Dec 2004 21:16:26 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Obtaining length of binary string
Message-Id: <aurm82-vqi.ln1@osiris.mauzo.dyndns.org>
Quoth "A. Sinan Unur" <1usa@llenroc.ude.invalid>:
> Brian McCauley <nobull@mail.com> wrote in
> news:corsm2$36s$1@sun3.bham.ac.uk:
>
> On the other hand, the following might be better in that it would allow the
> OP to selectively decide whether he wants characters or bytes to be
> counted.
>
> use strict;
> use warnings;
>
> use bytes ();
>
> my $s = "\x{2022}";
>
> print bytes::length($s), "\n", length($s);
This will give you the length in bytes of "\x{2022}" represented in
perl's internal character encoding. THIS IS NOT A USEFUL VALUE. You
should not know or care how perl represents characters internally: if
you mark the data as binary (with binmode) then Perl will return the
byte-length.
IMNSHO the fact that binary and textual strings are not adequately
distinguished is a flaw in perl's Unicode implementation, although I can
see it was mostly done for backwards compatibility so it's excusable.
Ben
--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
ben@morrow.me.uk
------------------------------
Date: Thu, 9 Dec 2004 21:07:37 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Paragraph separation for DOS files on Unix
Message-Id: <pdrm82-vqi.ln1@osiris.mauzo.dyndns.org>
Quoth "Andrew Hamm" <ahamm@mail.com>:
> Steve May wrote:
> > Oliver Heidelbach wrote:
> >
> >> Hi,
> >>
> >> is there any way to get Unix Perl to work on DOS files (CRLF) when
> >> reading in paragraphs and without to convert the line endings
> >> before processing the file?
> >>
> >> The usual
> >>
> >> $/ = "";
> >> @paras = split(/""/,$_);
> >>
> >> works fine for DOS files on systems with DOS format and DOS-aware
> >> Perl and for Unix files on Unix systems and Unix-aware Perl.
> >>
> >> However, it does not work for DOS files on Unix systems. I tried
> >> everything which came to my mind, but nothing really works.
>
> Assuming you are using a sufficiently modern version of Perl, have a fresh
> look at the "IO layers" or "disciplines" of the open call. I'm actually
> struggling to find a suitable perldoc section (someone else will surely
> post one),
Err... the obvious place? perldoc -f open points you at perldoc open and
perldoc PerlIO.
> but if you have the 3rd edition of the Camel book, look at
> pages 754,755 which actually appears to show almost exactly what you are
> trying to do
>
> open FH, "<:para:crlf", $filename
>
> :para means put the file into paragraph mode, :crlf means to handle CR/LF
> line terminators on your behalf.
The stuff in the Camel about IO 'disciplines' is mostly incorrect in
detail, as it hadn't been written at that time. They are now called
'layers', and there is no :para. :crlf, however, will do what the OP
wants (though not what I think it should do... :) ).
Ben
--
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
/Alcestis/) [ flame, and falls out of sight. ] ben@morrow.me.uk
------------------------------
Date: Sat, 11 Dec 2004 20:29:38 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Passing hashes to a function
Message-Id: <87wtvolgu9.fsf@mithril.chromatico.net>
>>>>> "SP" == Sherm Pendley <spamtrap@dot-app.org> writes:
SP> Uri Guttman wrote:
>> i am only upset because you gave a job to sherm and not to me.
SP> Someone wants to give me a job? Cool!
Yeah, I was inspired by rentacoder.com. Here's $20 - can you port the
entirety of Cocoa to Windows, so I can just recompile and have my code
run? kthx!
Charlton
--
cwilbur at chromatico dot net
cwilbur at mac dot com
------------------------------
Date: Thu, 9 Dec 2004 20:14:04 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Question on loops and return values
Message-Id: <c9om82-5ni.ln1@osiris.mauzo.dyndns.org>
Quoth tadmc@augustmail.com:
> James <djcameron60616@yahoo.com> wrote:
>
> > Why does the return value [of open] matter?
>
> Because it tells you whether you actually got what you asked for or not.
>
> > Wouldn't it
> > just open or fail (die)?
>
> No. (so you should put the "or die" stuff in there yourself)
Unless you
use Fatal qw/open/;
in which case it will (but you should catch that exception with eval so
you can handle the error decently).
Ben
--
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
ben@morrow.me.uk (Kate Rusby)
------------------------------
Date: Sat, 11 Dec 2004 21:18:00 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Regaular Expression
Message-Id: <cpfnst$2dq$1@sun3.bham.ac.uk>
gene_leung@kader.com.hk wrote:
> Sorry for the wording 'Please send me email directly'
It's not the wording that is objectionable, it is the sentiment.
> Actually this is what I am doing,
>
> cat some_file | sed 's/|||/|\\N|\\N|g' | sed 's/||/|\\N|/g'
Well, since this is a Perl news group, the obvious answer is use Perl
(probably with the -p and -e swiches) not sed. (Correct Perl command
has already been given).
Since this is not a Unix newsgroup I woln't mention that you have a
useless use of cat.
------------------------------
Date: Thu, 9 Dec 2004 21:24:00 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: why the following HereDoc print don't work?
Message-Id: <gcsm82-vqi.ln1@osiris.mauzo.dyndns.org>
Quoth Sherm Pendley <spamtrap@dot-app.org>:
>
> ... and correct. I copy everything up to and including the EOF - but
> *NOT* the newline after EOF - into a text file and run it. What do I see?
>
> Sherm-Pendleys-Computer:~ sherm$ perl test.pl
> Can't find string terminator "EOF" anywhere before EOF at test.pl line 6.
>
> Now I add a newline to the end, after EOF, and what do I see?
By 'the newline after EOF' do you mean a /\r?\n/ immediately after 'EOF'
(terminating that line) or another one after that? That is, does the
file that fails look like this at the end
45 E
4f O
46 F
<end-of-file>
or like this
45 E
4f O
46 F
0a \n
<end-of-file>
? If the former, then it isn't a valid text file (no Unix editor will
produce a file like that unless you explicitly ask for it, though some
Windows editors do) and it's not surprising it fails. When given the
here-doc <<EOF perl looks for the literal sequence "\nEOF\n" as the
terminator.
Ben
--
The cosmos, at best, is like a rubbish heap scattered at random.
- Heraclitus
ben@morrow.me.uk
------------------------------
Date: Thu, 9 Dec 2004 21:25:05 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: why the following HereDoc print don't work?
Message-Id: <hesm82-vqi.ln1@osiris.mauzo.dyndns.org>
Quoth Sherm Pendley <spamtrap@dot-app.org>:
> ÕÔ±û·å wrote:
>
> > Perl complained "Can't find string terminator "EOF" anywhere before EOF at
> > XXX(line No.)".
> > What happened and why?
>
> Looks to me like the "EOF" is on the last line of your script, which
> doesn't have a newline at the end of it.
>
> Solution: Add a blank line to the end of your script.
No, Solution 1: get a real text editor.
Solution 2: persuade the one you've got to create a proper text file by
apparently putting a blank line on the end.
Ben
--
"If a book is worth reading when you are six, * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis
------------------------------
Date: Sat, 11 Dec 2004 19:07:52 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: why the following HereDoc print don't work?
Message-Id: <n-udnUkUYcxEFibcRVn-ug@adelphia.com>
Ben Morrow wrote:
> does the file that fails look like this at the end
>
> 45 E
> 4f O
> 46 F
> <end-of-file>
Yes, exactly.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Sat, 11 Dec 2004 19:32:29 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: why the following HereDoc print don't work?
Message-Id: <o6adnaL9d94DDCbcRVn-jA@adelphia.com>
Ben Morrow wrote:
> No, Solution 1: get a real text editor.
>
> Solution 2: persuade the one you've got to create a proper text file by
> apparently putting a blank line on the end.
Are you seriously suggesting that Perl *should* refuse to run a file,
simply because the file doesn't end with a blank line? That's ridiculous
- if I believed that whitespace-as-syntax nonsense, I'd be using Python.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
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 7509
***************************************