[32466] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3732 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 7 18:09:20 2012

Date: Sat, 7 Jul 2012 15:09:06 -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           Sat, 7 Jul 2012     Volume: 11 Number: 3732

Today's topics:
    Re: "use" inside of a subroutine <derykus@gmail.com>
        Duplicate Attribute mittra@juno.com
    Re: Duplicate Attribute <ben@morrow.me.uk>
        perlbal as load balancer? vs ha proxy? what i gents thi <gavcomedy@gmail.com>
        random string generation <oneingray@gmail.com>
    Re: Regexp help <mikaelpetterson@hotmail.com>
    Re: Regexp help <jurgenex@hotmail.com>
    Re: Regexp help <jimsgibson@gmail.com>
    Re: Regexp help <ben@morrow.me.uk>
    Re: Regexp help <jurgenex@hotmail.com>
    Re: Regexp help <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 6 Jul 2012 22:03:03 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: "use" inside of a subroutine
Message-Id: <0c0560cf-1dfc-476b-8f7d-28a643348f86@re8g2000pbc.googlegroups.com>

On Jun 22, 2:54=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Jason C <jwcarl...@gmail.com>:
> ...

> > If "use"ing a module like this inside of a sub is acceptable, then am I
> > correct that it wouldn't be loaded until (or unless) necessary?
>
> This is *not* correct. The module will always be loaded, at the point
> where the file is required.
>
> > Or does Perl read ahead and load everything at once, regardless of
> > whether the function or module is actually used?
>
> Not exactly. Perl does exactly what you ask it to do: if you ask it
> (with 'use') to load a module at compile time, it does that. If you ask
> it (with 'require') to load a module at runtime, it does that; but you
> have to realise that 'require' will not export functions. If you want to
> load a module on demand, you need to do it like this:
>
> =A0 =A0 sub copyFile {
> =A0 =A0 =A0 =A0 require File::Copy;
>
> =A0 =A0 =A0 =A0 File::Copy::copy(...) or die ...;
> =A0 =A0 }
>

I don't know how the autouse pragma works internally
but it could be another alternative. That is the
module's load will be postponed until a function is
actually used.

The declaration should also be at the top though for
the reasons mentioned.  (Also there are a couple of
added caveats in autouse's docs.)

   use autouse File::Copy =3D> qw/copy/;

--
Charles DeRykus


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

Date: Fri, 6 Jul 2012 15:38:14 -0700 (PDT)
From: mittra@juno.com
Subject: Duplicate Attribute
Message-Id: <67ef8029-3133-40ee-8890-75c82edf9a8b@googlegroups.com>


I have an XML that looks like: 

<abc attr1="val1" attr2="val2" attr1="val3">
</abc>

Yes, this is illegal per XML rule since we have two attr1 and when I parse it through XML::Simple, I get this error message: 

duplicate attribute at line 14, column 291, byte 1936 at /usr/lib/perl5/XML/Parser.pm line 187

However, I am wondering if there is a way to tell XML::Simple to ignore this error. 

Thanks. 


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

Date: Sat, 7 Jul 2012 01:39:38 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Duplicate Attribute
Message-Id: <a3dkc9-p3m1.ln1@anubis.morrow.me.uk>


Quoth mittra@juno.com:
> 
> I have an XML that looks like: 
> 
> <abc attr1="val1" attr2="val2" attr1="val3">
> </abc>
> 
> Yes, this is illegal per XML rule since we have two attr1 and when I
> parse it through XML::Simple, I get this error message: 
> 
> duplicate attribute at line 14, column 291, byte 1936 at
> /usr/lib/perl5/XML/Parser.pm line 187

What do you expect the result to be?

> However, I am wondering if there is a way to tell XML::Simple to ignore
> this error. 

I don't think so, but you could try the 'recover' option to
XML::LibXML::Parser to see if it will handle that case. You should then
be able to feed the corrected XML to XML::Simple using SAX.

Ben



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

Date: Fri, 6 Jul 2012 22:05:31 -0700 (PDT)
From: quiet_lad <gavcomedy@gmail.com>
Subject: perlbal as load balancer? vs ha proxy? what i gents think?
Message-Id: <20033ee3-6ee3-4923-a426-a5cd3fcb9b6e@q5g2000pba.googlegroups.com>

boon or bain?



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

Date: Sat, 07 Jul 2012 11:56:24 +0700
From: Ivan Shmakov <oneingray@gmail.com>
Subject: random string generation
Message-Id: <86mx3c88zr.fsf_-_@gray.siamics.net>

>>>>> Cal Dershowitz <cal@example.invalid> writes:

[...]

 > Also, if you were going to design a character class such that it was
 > to be used in randomly-generating prefixes for files, which would you
 > use?

 > As for me, o O 0 ~ ` < > i 1 I { } [ ] | wouldn't make the first cut.

	Depending on the task, I'd generate a wide enough random number
	(or a UUID), and encode it with a Base32 variant, such as the
	Crockford's one.  Like, e. g.:

#!/usr/bin/perl

use strict;
use warnings;

require Convert::Base32::Crockford;
require UUID;

UUID::generate (my $uuid);
UUID::unparse ($uuid, my $s);
my $fn
    = Convert::Base32::Crockford::encode_base32 ($uuid);
print ($fn, "\n");

	Then, when looking the file up by the user's supplied name, I'd
	convert the latter into upper case, and replace [oO] with 0 and
	[iIlL] with 1.

	Alternatively, the RFC 4648 Base32 variant may be used, which
	includes B but not 8 (which could be confused with the former.)

http://en.wikipedia.org/wiki/Base32

[...]

-- 
FSF associate member #7257


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

Date: Fri, 6 Jul 2012 03:08:18 -0700 (PDT)
From: mike <mikaelpetterson@hotmail.com>
Subject: Re: Regexp help
Message-Id: <eb07e492-a71d-4884-88d3-9c8b967fc24b@googlegroups.com>

On Friday, July 6, 2012 11:22:03 AM UTC+2, Henry Law wrote:
> On 06/07/12 09:26, mike wrote:
> > Feature: org.eclipse.equinox.p2.user.ui 2.1.2.R37x_v20110815-1155-6-Bk8pYWZz0qUTX5I15GZWwbXkrl  enabled
> > Feature: org.erlide.tracing 0.2.2.201204301337  enabled
> > Feature: org.erlide 0.16.0.201204301337
> >
> > we should only match org.erlide this exactly.
> 
> Oh, seeing the actual data would have helped azrazer ...
> 
> # assuming that $id is set to "org.erlide", then
> if ( /\s$id\s/ && !/disable/ ) {
> 
> Or even more explicitly, assuming that all your data is as you've shown
> if ( /^Feature: $id\s/ && !/disable/ ) {
> 
> BTW you'd coded /\$id/; that will match the string "$id", not the value 
> of the variable $id;
> 
> -- 
> 
> Henry Law            Manchester, England

Thanks that worked out fine. Sorry azrazer for leaving out essential information.

//mike


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

Date: Fri, 06 Jul 2012 07:21:01 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Regexp help
Message-Id: <pfsdv7dn2ip5ppeb61ttt2npl8fq978nf3@4ax.com>

Henry Law <news@lawshouse.org> wrote:
>On 06/07/12 09:26, mike wrote:
>> Feature: org.eclipse.equinox.p2.user.ui 2.1.2.R37x_v20110815-1155-6-Bk8pYWZz0qUTX5I15GZWwbXkrl  enabled
>> Feature: org.erlide.tracing 0.2.2.201204301337  enabled
>> Feature: org.erlide 0.16.0.201204301337
>>
>> we should only match org.erlide this exactly.

No, you don't want to match, you want to test for equality.

>Oh, seeing the actual data would have helped azrazer ...
>
># assuming that $id is set to "org.erlide", then
>if ( /\s$id\s/ && !/disable/ ) {

Yeah, right. Why do people, including the OP, insist on using REs for
comparing text? And you fell into the same trap, too.

Your suggestion will match e.g.
	orgXeclipse
too, and I don't think this is what the OP wants. 

Yes, this again can be patched by using quotemeta, but why?
If you want to check two strings for equality then just do so instead of
fumbling around with REs:

	(undef, $domain, $code, $status) = split($_, ' ');
	if ($domain == $id and $status!='disable') {
		....
	}

jue


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

Date: Fri, 06 Jul 2012 09:21:06 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Regexp help
Message-Id: <060720120921068820%jimsgibson@gmail.com>

In article <pfsdv7dn2ip5ppeb61ttt2npl8fq978nf3@4ax.com>, J¸rgen Exner
<jurgenex@hotmail.com> wrote:

> If you want to check two strings for equality then just do so instead of
> fumbling around with REs:
> 
>   (undef, $domain, $code, $status) = split($_, ' ');
>   if ($domain == $id and $status!='disable') {
>     ....
>   }

But please do use the string comparison operator:

   if ($domain eq $id ...

-- 
Jim Gibson


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

Date: Fri, 6 Jul 2012 17:18:12 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Regexp help
Message-Id: <4nfjc9-n1h1.ln1@anubis.morrow.me.uk>


Quoth Jürgen Exner <jurgenex@hotmail.com>:
> Henry Law <news@lawshouse.org> wrote:
> >On 06/07/12 09:26, mike wrote:
> >> Feature: org.eclipse.equinox.p2.user.ui
> 2.1.2.R37x_v20110815-1155-6-Bk8pYWZz0qUTX5I15GZWwbXkrl  enabled
> >> Feature: org.erlide.tracing 0.2.2.201204301337  enabled
> >> Feature: org.erlide 0.16.0.201204301337
> >>
> >> we should only match org.erlide this exactly.
> 
> No, you don't want to match, you want to test for equality.
> 
> >Oh, seeing the actual data would have helped azrazer ...
> >
> ># assuming that $id is set to "org.erlide", then
> >if ( /\s$id\s/ && !/disable/ ) {

\b might be better than \s there.

> Yeah, right. Why do people, including the OP, insist on using REs for
> comparing text? And you fell into the same trap, too.
> 
> Your suggestion will match e.g.
> 	orgXeclipse
> too, and I don't think this is what the OP wants. 
> 
> Yes, this again can be patched by using quotemeta, but why?
> If you want to check two strings for equality then just do so instead of
> fumbling around with REs:
> 
> 	(undef, $domain, $code, $status) = split($_, ' ');
> 	if ($domain == $id and $status!='disable') {
                    ^^                ^^
Um, you were saying something about falling into traps?

Ben



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

Date: Fri, 06 Jul 2012 17:27:31 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Regexp help
Message-Id: <0j0fv7hlvl0m814s3d12avadfrl6los4r4@4ax.com>

Jim Gibson <jimsgibson@gmail.com> wrote:
>In article <pfsdv7dn2ip5ppeb61ttt2npl8fq978nf3@4ax.com>, J¸rgen Exner
><jurgenex@hotmail.com> wrote:
>
>> If you want to check two strings for equality then just do so instead of
>> fumbling around with REs:
>> 
>>   (undef, $domain, $code, $status) = split($_, ' ');
>>   if ($domain == $id and $status!='disable') {
>>     ....
>>   }
>
>But please do use the string comparison operator:
>
>   if ($domain eq $id ...

Good idea ;-)

jue


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

Date: Fri, 06 Jul 2012 17:29:11 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Regexp help
Message-Id: <ak0fv7h678aohapssr6cfhs1iiji0d4hva@4ax.com>

Ben Morrow <ben@morrow.me.uk> wrote:
>Quoth J?Exner <jurgenex@hotmail.com>:
>> 
>> 	(undef, $domain, $code, $status) = split($_, ' ');
>> 	if ($domain == $id and $status!='disable') {
>                    ^^                ^^
>Um, you were saying something about falling into traps?

Ummm, yeah, that happens when coding in several similar but not quite
identical languages at the same time.

Thanks for catching it.

jue


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3732
***************************************


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