[31635] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2898 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 1 18:09:27 2010

Date: Thu, 1 Apr 2010 15:09:09 -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           Thu, 1 Apr 2010     Volume: 11 Number: 2898

Today's topics:
    Re: FAQ 6.9 How can I quote a variable to use in a rege sln@netherlands.com
    Re: FAQ 6.9 How can I quote a variable to use in a rege <Phred@example.invalid>
    Re: FAQ 6.9 How can I quote a variable to use in a rege <tadmc@seesig.invalid>
    Re: How to convert "=?ISO-8895-1?Q?..." stuff? <josef_u._gabriele-moellers@t-online.de>
        perl.libwww? <galen@hendersonsoftware.com>
    Re: perl.libwww? <ben@morrow.me.uk>
    Re: perl.libwww? <galen@hendersonsoftware.com>
        software requirements again, take 483 <cartercc@gmail.com>
    Re: software requirements again, take 483 <cwilbur@chromatico.net>
    Re: software requirements again, take 483 <jurgenex@hotmail.com>
    Re: unary minus strangeness <nospam-abuse@ilyaz.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 31 Mar 2010 15:58:59 -0700
From: sln@netherlands.com
Subject: Re: FAQ 6.9 How can I quote a variable to use in a regex?
Message-Id: <tqk7r5ldg3iarpg8oe84uahl04ocdp18rg@4ax.com>

On Wed, 31 Mar 2010 16:00:46 -0600, Phred Phungus <Phred@example.invalid> wrote:

>Ben Morrow wrote:
>> Quoth Phred Phungus <Phred@example.invalid>:
>
>>> my $string2 = "Placido P. Octopus\n";
>>> print $string2;
>>> $string =~ s/$regex/Polyp/g;
>>   ^^^^^^^
>>> print $string2;
>>         ^^^^^^^^
>> 
>> One of these things is not like the other.
>
>Yeah.  It's funny the things a person thinks when he can't see an error 
>like this, which is, of course, no error at all.  You spend a minute 
>thinking the output might be right, but then not only is Juergen wrong, 
>but no one else in c.l.p.misc calls him on it.  That seemed unlikely.
>
>Hence the need to post.  A different set of eyes makes all the 
>difference.  I don't know how it runs with other people, but I tend to 
>see what I'm looking for and could miss Lady Godiva riding right next to it.
>
>One thing I like about this ng are the frequently-posted faq's.


How did you jump to the regular expression variables and s///
form substitutions without knowing what meta-chars and modifiers are?


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

Date: Thu, 01 Apr 2010 12:48:20 -0600
From: Phred Phungus <Phred@example.invalid>
Subject: Re: FAQ 6.9 How can I quote a variable to use in a regex?
Message-Id: <81k83lFvnU1@mid.individual.net>

Peter J. Holzer wrote:
> On 2010-03-28 08:47, Phred Phungus <Phred@example.invalid> wrote:
>> PerlFAQ Server wrote:
>>>             $string = "Placido P. Octopus";
>>>             $regex  = "P.";
>>>
>>>             $string =~ s/$regex/Polyp/;
>>>             # $string is now "Polypacido P. Octopus"
>>>
>>>     Because "." is special in regular expressions, and can match any single
>>>     character, the regex "P." here has matched the <Pl> in the original
>>>     string.
>>>
>> Am I then correct that a period is not a character?
> 
> No. Why do you think so?

Because I forgot one needed the g the modifier, but that's covered ground.

I'm really close to understanding all the dusty corners of this faq, but 
I'm having trouble with the first 2 sentences:

     The Perl parser will expand $variable and @variable references in
     regular expressions unless the delimiter is a single quote. Remember,
     too, that the right-hand side of a "s///" substitution is considered a
     double-quoted string (see perlop for more details). Remember also that
     any regex special characters will be acted on unless you precede the
     substitution with \Q. Here's an example:

# end excerpt

I like the latest version of the script:

$ ./perl1.pl
Placido P. Octopus
Polypacido P. Octopus

Placido P. Octopus
Polypacido Polyp Octopus

Placido P. Octopus
Placido Polyp Octopus

$ cat perl1.pl
#!/usr/bin/perl

use strict;
use warnings;

my $string = "Placido P. Octopus\n";
my $regex  = "P.";

my $string1 = $string;
print $string1;
$string1 =~ s/$regex/Polyp/;
print $string1;
print "\n";

my $string2 = $string;
print $string2;
$string2 =~ s/$regex/Polyp/g;
print $string2;
print "\n";

my $string3 = $string;
print $string3;
$string3 =~ s/\Q$regex/Polyp/;
print $string3;
print "\n";

$

What "expansion" occured in the perl parser?

Gruss,
-- 
fred


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

Date: Thu, 01 Apr 2010 15:28:16 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: FAQ 6.9 How can I quote a variable to use in a regex?
Message-Id: <slrnhra07a.1h0.tadmc@tadbox.sbcglobal.net>

Phred Phungus <Phred@example.invalid> wrote:

> I'm really close to understanding all the dusty corners of this faq, but 
> I'm having trouble with the first 2 sentences:
>
>      The Perl parser will expand $variable and @variable references in
>      regular expressions unless the delimiter is a single quote. Remember,
>      too, that the right-hand side of a "s///" substitution is considered a
>      double-quoted string (see perlop for more details). Remember also that
>      any regex special characters will be acted on unless you precede the
>      substitution with \Q. Here's an example:
>
> # end excerpt
>
> I like the latest version of the script:

> my $regex  = "P.";

> $string1 =~ s/$regex/Polyp/;


$regex gets expanded:

    $string1 =~ s/P./Polyp/;

> $string3 =~ s/\Q$regex/Polyp/;


$regex gets expanded and special chars are escaped:

    $string3 =~ s/P\./Polyp/;


> What "expansion" occured in the perl parser?


See above.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Thu, 01 Apr 2010 18:52:41 +0200
From: Josef Moellers <josef_u._gabriele-moellers@t-online.de>
Subject: Re: How to convert "=?ISO-8895-1?Q?..." stuff?
Message-Id: <hp2j0p$rkq$02$1@news.t-online.com>

Rainer Weikusat wrote:
> Josef Moellers <josef_u._gabriele-moellers@t-online.de> writes:
> 
> [...]
> 
>> I need something that will allow me to decode this:
>>
>> From: =?ISO-8859-1?Q?Josef_M=F6llers?= <josef.moellers@gmx.de>
>> into
>> From: Josef Möllers <josef.moellers@gmx.de>
>>
>> and this
>>
>> Subject: =?ISO-8859-1?Q?L=E4_l=F6_l=FC_sa=DFen_auf_der_Stra=DF?=
>>  =?ISO-8859-1?Q?e?=
>> into
>> Subject: Lä lö lü saßen auf der Straße
>>
>> I had hoped that there was some function in some library that I might
>> peruse ...
> 
> http://packages.debian.org/lenny/libuu0
> http://cpan.uwinnipeg.ca/htdocs/MIME-Base64/MIME/QuotedPrint.html

Thanks, also to Holger Petersen who sent me a few PMs to help.
I've now implemented it as a small Perl script using MIME::QuotedPrint:

#! /usr/bin/perl

use warnings;
use strict;
use MIME::QuotedPrint;

my $quoted_printable;

# Read header
my @header;
while (my $line = <>) {
    chomp $line;
    last if length($line) == 0;
    if ($line =~ /^ /)
    {
        $header[-1] .= substr($line, 1);
        next;
    }
    push @header, $line;
}
# We have the entire header, now process
foreach (@header) {
    if (/^From:\s/ || /^Subject:\s/) {
        s/_/ /g;
        1 while (s/=\?ISO-8859-1\?Q\?(.*?)\?=/decode_qp($1)/e);
    } elsif (/^Content-Transfer-Encoding:\s.*quoted-printable/i) {
        $quoted_printable = 1;
    }

    print "$_\n";
}
print "\n";
# Now copy mail body

if ($quoted_printable) {
    while (<>) {
        s/_/ /g;
        print decode_qp($_);
    }
} else {
    while (<>) {
        print $_;
    }
}

Josef


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

Date: Thu, 1 Apr 2010 11:16:18 +0000 (UTC)
From: "Galen Henderson" <galen@hendersonsoftware.com>
Subject: perl.libwww?
Message-Id: <PZzv9KcFEg5G-pn2-fNpHwBjKVOxq@ecshome>

Hello all.  I tried several times to post a messge to perl.libwww but 
it never appeared.  I am having a problem building HTML::Parser.  I've
pasted the original message below in case Gisle or someone here can 
help me out. 

Hello all.  Hopefully Gisle is still monitoring this group.  I went 
through the archives and found a post by him about this issue.  I 
checked patchlevel.h and all seems well.  There are no other 
patchlevel.h on the system.

When I try to build (on OS/2), it bombs when it is trying to make the 
PARSERMK.DLL. with the following:

weakld: error: Unresolved symbol (UNDEF EXPORT) 'boot_HTML__Parser'.
weakld: info: The symbol is referenced by:
    U:/unixroot/galen/.cpan/build/HTML-Parser-3.64-GhzQBp/Parser.def
Ignoring unresolved externals reported from weak prelinker.
Error! E2028: boot_HTML__Parser is an undefined reference
Error! E2044: exported symbol boot_HTML__Parser not found
make: *** [blib/arch/auto/HTML/Parser/ParserMK.dll] Error 1

I can make the dll without declaring the export so it doesn't seem to 
be a GCC issue...  When I look at the parser.c file that gets 
generated, there is no reference to this function.  Is this supposed 
to be automatically added by the EXTutils functions or something else?

Thanks in advance for any replies.

-- 
Regards,
Galen
------
There are only 10 kinds of people in the world.  Those who understand 
binary and those who don't.


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

Date: Thu, 1 Apr 2010 12:45:00 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: perl.libwww?
Message-Id: <side87-phu1.ln1@osiris.mauzo.dyndns.org>


Quoth "Galen Henderson" <galen@hendersonsoftware.com>:
> Hello all.  I tried several times to post a messge to perl.libwww but 
> it never appeared.

Do you mean the group on nntp.perl.org? I believe that server doesn't
allow posting: certainly, nothing I've posted has ever shown up. You
should be able to send mail to libwww-perl@perl.org.

> I am having a problem building HTML::Parser.  I've
> pasted the original message below in case Gisle or someone here can 
> help me out. 
> 
> Hello all.  Hopefully Gisle is still monitoring this group.  I went 
> through the archives and found a post by him about this issue.  I 
> checked patchlevel.h and all seems well.  There are no other 
> patchlevel.h on the system.

Well, I'm not Gisle, but I might be able to help :).

> When I try to build (on OS/2), it bombs when it is trying to make the 
> PARSERMK.DLL. with the following:
> 
> weakld: error: Unresolved symbol (UNDEF EXPORT) 'boot_HTML__Parser'.
> weakld: info: The symbol is referenced by:
>     U:/unixroot/galen/.cpan/build/HTML-Parser-3.64-GhzQBp/Parser.def
> Ignoring unresolved externals reported from weak prelinker.
> Error! E2028: boot_HTML__Parser is an undefined reference
> Error! E2044: exported symbol boot_HTML__Parser not found
> make: *** [blib/arch/auto/HTML/Parser/ParserMK.dll] Error 1

I don't understand why this is trying to build a file called
ParserMK.dll. On my system the shared library is called

    blib/arch/auto/HTML/Parser/Parser.so

(without the 'MK'). Is this usual on OS/2?

> I can make the dll without declaring the export so it doesn't seem to 
> be a GCC issue...  When I look at the parser.c file that gets 
> generated, there is no reference to this function.  Is this supposed 
> to be automatically added by the EXTutils functions or something else?

There should be a section starting

    XS(boot_HTML_Parser);
    XS(boot_HTML_Parser)
    {
    #ifdef dVAR
        dVAR; dXSARGS;
    #else
        dXSARGS;
    #endif

in Parser.c. The XS() macro expands into a suitable function prototype.
Is it not there? Can you run nm (or some local equivalent) on Parser.o
to see if the symbol is defined? Can you post the link line(s) make is
trying to use, to make sure it's picking up the right files?

Ben



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

Date: Thu, 1 Apr 2010 14:00:41 +0000 (UTC)
From: "Galen Henderson" <galen@hendersonsoftware.com>
Subject: Re: perl.libwww?
Message-Id: <PZzv9KcFEg5G-pn2-NXqC53mgdB0D@ecshome>

Hi, Ben.  Thanks for the reponse.  My comments below...

On Thu, 1 Apr 2010 11:45:00 UTC, Ben Morrow <ben@morrow.me.uk> wrote:

snip

> 
> I don't understand why this is trying to build a file called
> ParserMK.dll. On my system the shared library is called
> 
>     blib/arch/auto/HTML/Parser/Parser.so
> 
> (without the 'MK'). Is this usual on OS/2?

I haven't been building Perl modules on OS/2 for very long but from 
what I've seen, the MK is not added to the other dlls I've built.

> 
> There should be a section starting
> 
>     XS(boot_HTML_Parser);
>     XS(boot_HTML_Parser)
>     {
>     #ifdef dVAR
>         dVAR; dXSARGS;
>     #else
>         dXSARGS;
>     #endif

This is in the parser.c source file.

> 
> in Parser.c. The XS() macro expands into a suitable function prototype.
> Is it not there? Can you run nm (or some local equivalent) on Parser.o
> to see if the symbol is defined? Can you post the link line(s) make is
> trying to use, to make sure it's picking up the right files?

Here is the gcc build command:

gcc  -Zdll -Zomf  Parser.o -O2 -fomit-frame-pointer -falign-loops=2 
-falign-jump
s=2 -falign-functions=2 -s  -o blib/arch/auto/HTML/Parser/ParserMK.dll
 \
  /perl5/lib/5.10.0/os2/CORE/libperl.a -lsocket 
/perl5/lib/5.10.0/os2/CORE/libpe
rl_override.a Parser.def        \
  || ( U:/PERL5/BIN/PERL.EXE -MExtUtils::Command -e 'rm_f' -- 
blib/arch/auto/HTM
L/Parser/ParserMK.dll && sh -c false )

nm shows the symbol as _boot_HTML__Parser.  I'm stumped.

-- 
Regards,
Galen
------
There are only 10 kinds of people in the world.  Those who understand 
binary and those who don't.


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

Date: Thu, 1 Apr 2010 08:27:44 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: software requirements again, take 483
Message-Id: <4a4bdfe2-b46f-4eab-8db2-930851534086@u31g2000yqb.googlegroups.com>

We have an institutionally critical process that consists of a back
end (getting data from various sources and creating input files to
generate the documents) and a front end (preparing and sending the
documents from the input files.) We do this multiple times a year, and
it's task based, with single individuals performing multiple tasks
(from one to about six), and it generates hundreds of task documents
institution wide. Several years ago, I wrote the back end, and it's
worked perfectly.

A month or so ago, I was given the front end process as well. The due
date was Tuesday a week ago, nine days as I write. It was a week late,
I finished it last Tuesday, a week late. (I had to wait on input from
other people to finish the job, and they were tardy getting back to
me.) About 3:00 p.m., I got a call from the manager in charge who told
me that the software wasn't doing some of the documents correctly,
some weren't prepared at all and some were prepared wrong. Four
documents were affected out of 489.

After looking at it, I saw that the problem was the some tasks could
also be performed by multiple individuals, and my scripts only allowed
for tasks to be performed by one person. (The main database we use
contains a 'task' table, with one row per task and the individual
responsible for the task. It doesn't not contain information about
multiple individuals per task.) To correct the problem, I literally
had to start from the very beginning -- the first problem is that the
data now has to come from two tables that do not share a common key --
and revise the database queries, data formats, data structures, etc.

I griped (to anyone who would listen) that this requirement to
generate task documents accounting for tasks to be performed by
multiple individuals was a critical functional requirement, and I
DIDN'T FIND OUT ABOUT IT UNTIL THE SOFTWARE WAS A WEEK LATE!
It wasn't that this requirement wasn't known, these documents have
been generated for years, the manager wasn't aware of the details, it
just worked, and assumed that I knew the details. The guy who did the
front end had his methods for accounting for this requirement, but he
wasn't available. I'm guessing that he made the corrections manually,
but he had access to sources of data that I do not have.

It mystifies me that a critical requirement of this nature wouldn't be
specified until after the software had been written, and when the
software was already late. Apparently there's some universal law that
states this, but I don't know what the law is, or why the law is.

I know what some on c.l.p.m. will say -- don't correct the software
but comply with the wrong requirements, or get another job, but these
aren't realistic.

I'm just blowing off steam, decompressing. I've been pretty beat up
over the last three weeks, I'm about to take the rest of the week off,
and I just wanted to relate my experience. Thanks for listening.

CC.


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

Date: Thu, 01 Apr 2010 15:19:25 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: software requirements again, take 483
Message-Id: <86y6h72d6q.fsf@mithril.chromatico.net>

>>>>> "cc" == ccc31807  <cartercc@gmail.com> writes:

    cc> It mystifies me that a critical requirement of this nature
    cc> wouldn't be specified until after the software had been written,
    cc> and when the software was already late. Apparently there's some
    cc> universal law that states this, but I don't know what the law
    cc> is, or why the law is.

This is not mystifying.  It has to do with the people who do the job
every day not thinking about the details, because they're internalized.

The problem is that this lack of communication has somehow become *your*
problem, and you seem to have accepted that.  Doing that just sets
yourself up for more frustration and more failure.

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Thu, 01 Apr 2010 13:50:30 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: software requirements again, take 483
Message-Id: <u6v9r5h9u54vdg9e12bjv09j1qj3utjm72@4ax.com>

ccc31807 <cartercc@gmail.com> wrote:
[Story of long suffereing snipped]
>DIDN'T FIND OUT ABOUT IT UNTIL THE SOFTWARE WAS A WEEK LATE!
>It wasn't that this requirement wasn't known, these documents have
>been generated for years, the manager wasn't aware of the details, it
>just worked, and assumed that I knew the details. The guy who did the
>front end had his methods for accounting for this requirement, but he
>wasn't available. I'm guessing that he made the corrections manually,
>but he had access to sources of data that I do not have.
>
>It mystifies me that a critical requirement of this nature wouldn't be
>specified until after the software had been written, and when the
>software was already late. Apparently there's some universal law that
>states this, but I don't know what the law is, or why the law is.

So, what was the feedback from those people when you presented your
spec? Did they miss the flaw, too, and signed off on the misguided
concept?
And what about during the testing phase? Yes, testing should primarily
check if the code complies with the written specification, but at least
in the later parts when actual users check out if the progam meets their
needs, then they should have noticed that critical functionality is
missing.


Honestly, looking at your long history here in this NG you are in this
way over your head and while you are trying to make up with a lot of
enthusiasm and determination it is hard to overlook that you are missing
basic skills for the job you are supposed to do.

It's like you know how to use a hammer and a saw and you are actually
rather skillful with those. So you are building garden sheds and the
occasional deck or gazebo and you turn them out on demand, in decend
quality and functional. But that doesn't automatically qualify you to
build a house or like in this case an add-on garage with mother-in-law. 

Those projects simply require planning, organization, and preparation
skills (aka project management) which you don't have. And, if you excuse
me for saying so, which you have shown little interest to learn or to
adapt. 
It's really the same story over and over again: you need to get your
nose out of the editor and stop worrying about those pesky syntax
errors. The actual coding part is only one small portion of the whole
development process and you have to start looking at the bigger picture
and understand development processes in context or things like this here
will keep happening again and again and every single time you will get
more and more frustrated. 

Now, I do understand that there are people who couldn't care less about
project management and love spending all their day coding from dawn to
dusk instead. Fair enough, there's nothing wrong with that. 
But based on your stories your position is not a position where you have
the luxury to do that. There is nobody else who would provide this
service for you, nobody you would talk with the users, gather and
organize their requirements, organize your coding work, organize the
schedule, testing, feedback gathering, and and and. 
Therefore you either have to grow into that role or find someone else to
cover that role. Because as long as you keep applying the same
non-functioning process you cannot expect the outcome to change for the
better. 

jue


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

Date: Wed, 31 Mar 2010 23:01:06 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: unary minus strangeness
Message-Id: <slrnhr7l1i.jhg.nospam-abuse@powdermilk.math.berkeley.edu>

On 2010-03-31, Bo Lindbergh <blgl@hagernas.com> wrote:
>> > {
>> >     my $strange=-0.0;
>> >     print $strange ? "$strange is true\n" : "$strange is false\n";
>> >     print $strange ? "$strange is true\n" : "$strange is false\n";
>> > }
>> 
>> This is a bug.  Read-only access should not change the value.

 ... Reading string value of -0.0 changes TRUE/FALSE...

> Would you call this example the same bug, a different bug, or not a bug?
> {
>     my $strange="-0";
>     print "- $strange == ", -$strange, "\n";
>     my $ignored=0+$strange;
>     print "- $strange == ", -$strange, "\n";
> }

 ... Reading NUM value of "-0" changes the effect of unary minus.

It looks like different bugs - but they may have the same fix....  ;-)

> Ditto for this one.
> {
>     my($one,$two)=("12","21");
>     print "$one | $two == ", $one | $two, "\n";
>     my $ignored=$one+$two;
>     print "$one | $two == ", $one | $two, "\n";
> }

Not a bug - just a documented brokenness of |-operator...

Hope this helps,
Ilya


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

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


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