[28117] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9481 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 16 14:05:35 2006

Date: Sun, 16 Jul 2006 11:05:04 -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           Sun, 16 Jul 2006     Volume: 10 Number: 9481

Today's topics:
    Re: A simply regex question <franzl.wisseworst@mailinator.net>
    Re: A simply regex question <jurgenex@hotmail.com>
    Re: A simply regex question <franzl.wisseworst@mailinator.net>
    Re: Can I compare array with array? <bart@nijlen.com>
    Re: Can I compare array with array? <jurgenex@hotmail.com>
    Re: Can I compare array with array? <1usa@llenroc.ude.invalid>
    Re: Can I compare array with array? <1usa@llenroc.ude.invalid>
    Re: Can I compare array with array? <bart@nijlen.com>
    Re: Can I compare array with array? <rvtol+news@isolution.nl>
    Re: How get UTF-8 from urlencoded web form <bart@nijlen.com>
    Re: How get UTF-8 from urlencoded web form <ynleder@nspark.org>
    Re: How get UTF-8 from urlencoded web form <1usa@llenroc.ude.invalid>
    Re: How get UTF-8 from urlencoded web form <bart@nijlen.com>
    Re: How get UTF-8 from urlencoded web form <1usa@llenroc.ude.invalid>
    Re: How get UTF-8 from urlencoded web form <bart@nijlen.com>
    Re: How to local-ly close a handle? <bol@adv.magwien.gv.at>
    Re: Need Search::Binary examples <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 16 Jul 2006 16:49:06 +0200
From: Franzl Wisseworst <franzl.wisseworst@mailinator.net>
Subject: Re: A simply regex question
Message-Id: <e9dkhe$mae$01$1@news.t-online.com>

Jürgen Exner wrote:

> Your task can better be solved without using a RE.

I opted for something simple like:
$domain_string =~ /mein.totenkopf.de/

> You normalize both strings before searching, e.g. make both all
> lower-case, see
>     perldoc -f lc

How obvious! Thank you.



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

Date: Sun, 16 Jul 2006 15:12:10 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: A simply regex question
Message-Id: <eHsug.5285$Ss2.954@trnddc01>

Franzl Wisseworst wrote:
> Jürgen Exner wrote:
>
>> Your task can better be solved without using a RE.
>
> I opted for something simple like:
> $domain_string =~ /mein.totenkopf.de/

You realize that this RE matches e.g. 'mein#totenkopfXde', too, do you?
Beside, as pointed out earlier, there is no need to crank the big RE engine 
for a simple textual comparison as you are looking for.

>> You normalize both strings before searching, e.g. make both all
>> lower-case, see
>>     perldoc -f lc
>
> How obvious! Thank you.

Which of course is not even needed. If you are cranking the big RE engine 
already, then you could just as well take advantage of its power and search 
case-insensitive: perldoc perlre.

jue 




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

Date: Sun, 16 Jul 2006 17:31:56 +0200
From: Franzl Wisseworst <franzl.wisseworst@mailinator.net>
Subject: Re: A simply regex question
Message-Id: <e9dn1o$la6$03$1@news.t-online.com>

[..]

> >> Your task can better be solved without using a RE.

If I only knew how to...

> You realize that this RE matches e.g. 'mein#totenkopfXde', too, do you?

No I did not.

[..]

> search case-insensitive: perldoc perlre.

Will munch through this bit of documentation too.

Thank you for the information.




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

Date: 16 Jul 2006 09:09:13 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: Can I compare array with array?
Message-Id: <1153066153.522764.173280@i42g2000cwa.googlegroups.com>

A. Sinan Unur wrote:

> "Bart Van der Donck" <bart@nijlen.com> wrote in
> news:1153061300.577609.326490@m79g2000cwm.googlegroups.com:
>
> > Davy wrote:
> >> Can I use if(@a==@b) directly?
> > [...]
> > But it's better practice to do
> >
> >   if ( $#a == $#b )   { ... }
>
> Why?

I'ld say because with $#arrayname it is immediately clearer that we're
dealing with the number of elements, while @arrayname is more perceived
as the array as a whole.

> > (and better practice to not use $a and $b as variable names,
> But he is not using those names.

Apparently I mistook the @ for a $ when I typed that.

-- 
 Bart



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

Date: Sun, 16 Jul 2006 16:23:37 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Can I compare array with array?
Message-Id: <dKtug.5141$k31.504@trnddc06>

Bart Van der Donck wrote:
> A. Sinan Unur wrote:
>
>> "Bart Van der Donck" <bart@nijlen.com> wrote in
>> news:1153061300.577609.326490@m79g2000cwm.googlegroups.com:
>>
>>> Davy wrote:
>>>> Can I use if(@a==@b) directly?
>>> [...]
>>> But it's better practice to do
>>>
>>>   if ( $#a == $#b )   { ... }
>>
>> Why?
>
> I'ld say because with $#arrayname it is immediately clearer that we're
> dealing with the number of elements,

But we are not. $#arrayname is the last index in that array, not the number 
of elements.

> while @arrayname is more
> perceived as the array as a whole.

That depends on the context ;-)

jue 




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

Date: Sun, 16 Jul 2006 16:38:21 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Can I compare array with array?
Message-Id: <Xns980280AB73156asu1cornelledu@127.0.0.1>

"Bart Van der Donck" <bart@nijlen.com> wrote in 
news:1153066153.522764.173280@i42g2000cwa.googlegroups.com:

> A. Sinan Unur wrote:
> 
>> "Bart Van der Donck" <bart@nijlen.com> wrote in
>> news:1153061300.577609.326490@m79g2000cwm.googlegroups.com:
>>
>> > Davy wrote:
>> >> Can I use if(@a==@b) directly?
>> > [...]
>> > But it's better practice to do
>> >
>> >   if ( $#a == $#b )   { ... }
>>
>> Why?
> 
> I'ld say because with $#arrayname it is immediately clearer that we're
> dealing with the number of elements,

Boolean conditions provide scalar context. In that context, @a is the 
number of elements in @a, whereas $#a is one less than the number of 
elements in @a.

One can actually compare arrays for equality in a single statement if 
the contents of the arrays are simple strings or numbers:

#!/usr/bin/perl

use strict;
use warnings;

my @a = qw(one two three);
my @b = qw(one two three);
my @c = (1, 2, 3);
my @d = (1.0, 2.0, 3.0);

print 'Comparing @a and @b:', "@a" eq "@b" ? "equal\n" : "not equal\n"; 
print 'Comparing @c and @d:', "@c" eq "@d" ? "equal\n" : "not equal\n"; 
print 'Comparing @a and @d:', "@a" eq "@d" ? "equal\n" : "not equal\n"; 

    
__END__

Not a good idea with large arrays.

> while @arrayname is more perceived as the array as a whole.

This is Perl5. So, the meaning of @arrayname is dictated by context.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: Sun, 16 Jul 2006 16:47:11 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Can I compare array with array?
Message-Id: <Xns9802822A56A8Casu1cornelledu@127.0.0.1>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in 
news:Xns980280AB73156asu1cornelledu@127.0.0.1:

> One can actually compare arrays for equality in a single statement if 
> the contents of the arrays are simple strings or numbers:

Clarification:

Of course, the stringification of references would also allow us to 
check if the arrays contain references to the _same_ aggregate types.

However,

#!/usr/bin/perl

use strict;
use warnings;

my @y = ( [1], [2] );
my @z = ( [1], [2] );

print 'Comparing @y and @z:', "@y" eq "@z" ? "equal\n" : "not equal\n"; 

__END__

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: 16 Jul 2006 09:48:50 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: Can I compare array with array?
Message-Id: <1153068530.634247.90130@75g2000cwc.googlegroups.com>

A. Sinan Unur wrote:

> [...]
> Boolean conditions provide scalar context. In that context, @a is the
> number of elements in @a, whereas $#a is one less than the number of
> elements in @a.
>
> One can actually compare arrays for equality in a single statement if
> the contents of the arrays are simple strings or numbers

It seems I was not well aware of the difference between $#array and
@array when it comes to the number of elements in an array.

-- 
 Bart



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

Date: Sun, 16 Jul 2006 19:13:59 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Can I compare array with array?
Message-Id: <e9e3c9.to.1@news.isolution.nl>

A. Sinan Unur schreef:

> $#a is one less than the number of
> elements in @a.

Generally yes, as it is the last index in the array.


> my @a = qw(one two three);
> my @b = qw(one two three);

perl -wle '
  $, = qq/\t/;
  @a = qw(a b c);
  @b = (qq/a$"b$"c/);
   print qq/@a/ eq qq/@b/, 0+@a, 0+@b
'

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: 16 Jul 2006 08:05:08 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <1153062308.612948.84580@m79g2000cwm.googlegroups.com>

A=2E Sinan Unur wrote:

> [...]
> Escaping is a general method of changing the meaning of the characters
> following a designated special character. In this case, % is the special
> character, and it changes the meaning of the characters following it.
> Characters not allowed in URIs are replaced with these escape sequences.

Yes, but escaping would then only refer to the %-sign, not to what
follows. In '%E9', '%' is the escape character and 'E9' the encoded
value of '=E9'. E9 has nothing to do with escaping; otherwise it would
have been %=E9 (or \=E9).

So I think we're both 50% right here :-)

--=20
 Bart



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

Date: Sun, 16 Jul 2006 17:06:34 +0200
From: Yohan N. Leder <ynleder@nspark.org>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <MPG.1f247465dc3a40ff98988e@news.tiscali.fr>

In article <1153050463.349171.239300@i42g2000cwa.googlegroups.com>, 
bart@nijlen.com says...
> Yes, the URL encoding is done at the browser's side by default, before
> and apart from the sendout of the name/value pairs. This behaviour can
> be altered by adding enctype="multipart/form-data" as an extra argument
> to <form method="post">. The main reason for this feature to exist, is
> the transfer of (binary) files to the gateway software on the server.
> Thus, if you want to send 'é', the browser will pass it as "%E9" by
> default. It's up to your Perl script to decode it back to 'é'. In the
> multipart/form-data encoding type, 'é' is just passed as 'é'. In
> UTF-8 sets, the browser looks for the literal equivalent of 'é', and
> then passes the URL-encoded value of that literal equivalent.
> 

Well understood, Bart. Thanks


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

Date: Sun, 16 Jul 2006 16:01:48 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <Xns98027A78AAA47asu1cornelledu@127.0.0.1>

"Bart Van der Donck" <bart@nijlen.com> wrote in
news:1153062308.612948.84580@m79g2000cwm.googlegroups.com: 

> A. Sinan Unur wrote:
> 
>> [...]
>> Escaping is a general method of changing the meaning of the
>> characters following a designated special character. In this case, %
>> is the special character, and it changes the meaning of the
>> characters following it. Characters not allowed in URIs are replaced
>> with these escape sequences. 
> 
> Yes, but escaping would then only refer to the %-sign, not to what
> follows. In '%E9', '%' is the escape character and 'E9' the encoded
> value of 'é'. E9 has nothing to do with escaping; otherwise it would
> have been %é (or \é).

Not really. In Perl, \n is the "escape sequence" for the platform 
dependent end-of-line character. Clearly, 'n' in that escape sequence is 
just like the E9 above. 

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: 16 Jul 2006 09:22:30 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <1153066950.541410.170880@p79g2000cwp.googlegroups.com>

A=2E Sinan Unur wrote:

> "Bart Van der Donck" <bart@nijlen.com> wrote in
> news:1153062308.612948.84580@m79g2000cwm.googlegroups.com:
>
> > Yes, but escaping would then only refer to the %-sign, not to what
> > follows. In '%E9', '%' is the escape character and 'E9' the encoded
> > value of '=E9'. E9 has nothing to do with escaping; otherwise it would
> > have been %=E9 (or \=E9).
>
> Not really. In Perl, \n is the "escape sequence" for the platform
> dependent end-of-line character.

While that is absolutely true, E9 is still an encoded value of =E9. It
might or might not serve inside a notation that uses a designated
escape character.

> Clearly, 'n' in that escape sequence is just like the E9 above.

There is no encoding involved in \n, but there is when you write =E9 as
%E9

--=20
 Bart



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

Date: Sun, 16 Jul 2006 16:42:44 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <Xns98028169278E8asu1cornelledu@127.0.0.1>

"Bart Van der Donck" <bart@nijlen.com> wrote in
news:1153066950.541410.170880@p79g2000cwp.googlegroups.com: 

> A. Sinan Unur wrote:
> 
>> "Bart Van der Donck" <bart@nijlen.com> wrote in
>> news:1153062308.612948.84580@m79g2000cwm.googlegroups.com:
>>
>> > Yes, but escaping would then only refer to the %-sign, not to what
>> > follows. In '%E9', '%' is the escape character and 'E9' the encoded
>> > value of 'é'. E9 has nothing to do with escaping; otherwise it
>> > would have been %é (or \é).
>>
>> Not really. In Perl, \n is the "escape sequence" for the platform
>> dependent end-of-line character.

 ...

> There is no encoding involved in \n, but there is when you write é as
> %E9

That does not make sense. 'n' all by itself is not the end of line 
character anywhere. In the realm of Perl's interpolates strings, the 
letter 'n' that follows '\' is the encoding of the EOL.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: 16 Jul 2006 10:27:32 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <1153070852.318555.265370@75g2000cwc.googlegroups.com>

A=2E Sinan Unur wrote:

> > There is no encoding involved in \n, but there is when you write =E9 as
> > %E9
>
> That does not make sense. 'n' all by itself is not the end of line
> character anywhere. In the realm of Perl's interpolates strings, the
> letter 'n' that follows '\' is the encoding of the EOL.

You can't compare (n vs. \n) to (=E9 vs. %E9). There is simply no
relation between the characters that are represented by "n" and "\n".
There is no encoding or conversion or whatever.

The idea is totally different when _going_from_ =E9 to %E9. You have a
clear encoding algorithm there that takes its data from some code
table. There is no "going from" involved in "n" versus "\n".

=E9 to %E9 consists of 2 parts:
(1) Encode from =E9 to E9
(2) Put a % before E9 to make clear it's a escape sequence

--=20
 Bart



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

Date: Sun, 16 Jul 2006 18:18:54 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: How to local-ly close a handle?
Message-Id: <1153066735.956842@proxy.dienste.wien.at>

kj:

> I know of ways to temporarily silence STDERR that actually work,
> but none of them begins to approach the simplicity of any of the
> examples above.  Any suggestions?

Yes. How about:

system 'crazystuff 2>/dev/null';

Localizing STDERR with whatever has no impact on child processes,
because the parent process' STDERR (which the child inherits) still
remains open. It will have an impact when you do a "print STDERR"
or somewhat similar, but it's meaningful with Perl commands only.

And although you can localize a typeglob (and its associated IO handle),
you can't localize a close! So if you close a file (as you did with "close
STDERR"), the file will remain closed, even when leaving the block!
The file doesn't get re-opened automatically thereafter (well, perhaps
this would be an enhancement for Perl 7, wouldn't it? :-).

Greetings, Ferry

-- 
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: bol@adv.magwien.gv.at





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

Date: Sun, 16 Jul 2006 18:47:33 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Need Search::Binary examples
Message-Id: <pan.2006.07.16.16.47.33.204093@hjp.at>

On Tue, 11 Jul 2006 12:40:33 +0000, David Combs wrote:
> In article <qbrq7e.5ln.ln@teal.hjp.at>,
> Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
>>Arvin Portlock wrote:
>>> Peter J. Holzer wrote:
>>>> Search::Binary is obviously written to search files, not arrays. But it
>>>> can be used to search arrays, too.

[41 lines deleted. Please quote only text relevant to your answer]

>>I do agree that the documentation isn't easy to understand. I had to
>>step through binary_search in the debugger to find an error I made at
>>first.
>>
> 
> Maybe this followup is (way) too late for this,
> but if now you see how you could (greatly) *improve*
> that doc, at least here and there, why not give
> it a shot, and then send it to the module-author?

You are of course right, that is what I should do.
There are some reasons why I didn't:

* I never used Search::Binary before. Installing it, fixing the OP's
  program and explaining it was already more work than I had planned to
  spend on answering a usenet posting.

* I'm not very good at improving the writing of other people. I stick
  too much to what is already there, so the result is often rather
  awkward (at work I tend to rather rewrite a whole chapter from scratch
  rather than try to improve somebody else's writing).

* My experience with sending unsolicited patches to CPAN authors isn't
  very good. Many CPAN modules seem not to be maintained any more, so
  unless I have some personal interest in improving a module (e.g.,
  because I'm using it myself) I won't invest time into writing a patch
  which will probably just vanish into a black whole. 

  	hp

-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd



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

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


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