[32060] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3324 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 17 00:09:24 2011

Date: Wed, 16 Mar 2011 21: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           Wed, 16 Mar 2011     Volume: 11 Number: 3324

Today's topics:
    Re: Autovivification <uri@StemSystems.com>
    Re: C Compiler question <dave@invalid.invalid>
    Re: C Compiler question <jimsgibson@gmail.com>
    Re: C Compiler question <dave@invalid.invalid>
    Re: C Compiler question <hjp-usenet2@hjp.at>
    Re: convenient module to take statistics for hashed str <nospam.gravitalsun@hotmail.com.nospam>
    Re: FAQ 2.2 How can I get a binary version of perl? <brian.d.foy@gmail.com>
    Re: going from CPAN to RPM <agw@dsm.fordham.edu>
    Re: going from CPAN to RPM <m@rtij.nl.invlalid>
    Re: going from CPAN to RPM <hjp-usenet2@hjp.at>
        HTML::TreeBuilder filter critique <seven.reeds@gmail.com>
        List assignment to array affects scalar results <google@markginsburg.com>
        module for MSCRM? (hymie!)
        reading .ini file without using a module <alfonso.baldaserra@gmail.com>
    Re: reading .ini file without using a module <nospam.gravitalsun@hotmail.com.nospam>
    Re: recursive Pythagorian triples <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 16 Mar 2011 17:08:48 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Autovivification
Message-Id: <87y64elqn3.fsf@quad.sysarch.com>

>>>>> "CD" == C DeRykus <derykus@gmail.com> writes:

  CD> Ah, good explanation. There's almost an optical
  CD> illusion for the unwary since @{$foo->[0]} so
  CD> nearly resembles the ref. chain  $foo->[0][0]
  CD> that does get autovivified.

  CD> And, though the former has no depth, it still
  CD> works as an lvalue:

  CD> perl -Mstrict -wle 'my $foo;print @{$foo->[0]} =()'

well, assigning something always makes something an lvalue by
definition. perl just autovivs what is needed to make the assignment
work. it is just the same for read accessing but the last (deepest)
level won't be autovivified which is part of the confusion here.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Wed, 16 Mar 2011 16:23:12 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: C Compiler question
Message-Id: <fV45K0OBJxbE-pn2-crSdCrdX38RE@localhost>

On Wed, 16 Mar 2011 14:47:31 UTC, Tad McClellan <tadmc@seesig.invalid>
wrote:

> Dave Saville <dave@invalid.invalid> wrote:
> > On Wed, 16 Mar 2011 11:51:13 UTC, Tad McClellan <tadmc@seesig.invalid>
> > wrote:
> >
> >> Dave Saville <dave@invalid.invalid> wrote:
> >> 
> >> > When one installs perl does it "remember" anything about the C 
> >> > compiler, .h files and libs at the time?
> >> 
> >> 
> >> Yes.
> >> 
> >>      perl -V
> >> 
> >>      ...
> >>      Compiler:
> >>      ...
> >>      Linker and Libraries:
> >>      ...
> >>      Dynamic Linking:
> >>      ...
> >> 
> >> 
> >
> > OK Thanks - So how do I update them if needed after a compiler update?
> 
> 
> recompile the perl binary.

I was hoping you were not going to say that as it is a binary distro. 
Problem is, I have the same compiler etc. but all the libs. compiler 
switches, paths etc. are for the machine that built the binary not 
mine. I was hoping I could edit something or run some script to fix 
it. :-(
-- 
Regards
Dave Saville


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

Date: Wed, 16 Mar 2011 09:41:48 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: C Compiler question
Message-Id: <160320110941483769%jimsgibson@gmail.com>

In article <fV45K0OBJxbE-pn2-crSdCrdX38RE@localhost>, Dave Saville
<dave@invalid.invalid> wrote:

> On Wed, 16 Mar 2011 14:47:31 UTC, Tad McClellan <tadmc@seesig.invalid>
> wrote:
> 
> > Dave Saville <dave@invalid.invalid> wrote:
> > > On Wed, 16 Mar 2011 11:51:13 UTC, Tad McClellan <tadmc@seesig.invalid>
> > > wrote:
> > >
> > >> Dave Saville <dave@invalid.invalid> wrote:
> > >> 
> > >> > When one installs perl does it "remember" anything about the C 
> > >> > compiler, .h files and libs at the time?
> > >> 
> > >> 
> > >> Yes.


> > > OK Thanks - So how do I update them if needed after a compiler update?
> > 
> > 
> > recompile the perl binary.
> 
> I was hoping you were not going to say that as it is a binary distro. 
> Problem is, I have the same compiler etc. but all the libs. compiler 
> switches, paths etc. are for the machine that built the binary not 
> mine. I was hoping I could edit something or run some script to fix 
> it. :-(

You have encountered one disadvantage of using binary distributions.
The fix for installing XS modules is to:

1. Get the same compiler used to build the binary.
2. Build your own Perl.

#1 may not be feasible, but #2 usually is. Download the Perl source
from here:

<http://www.cpan.org/src/README.html>

and follow the directions in the README and one of the README.x files.
You should put the new Perl in a location unique from your existing
Perl, so that you do not overwrite your current working Perl
installation. Change your path and the first line of script files so
that you can use your new Perl version.

I've done it myself, so it can't be that hard!

-- 
Jim Gibson


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

Date: Wed, 16 Mar 2011 22:03:46 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: C Compiler question
Message-Id: <fV45K0OBJxbE-pn2-k88LpfJ6NqyI@localhost>

On Wed, 16 Mar 2011 14:47:31 UTC, Tad McClellan <tadmc@seesig.invalid>
wrote:

<snip>

> recompile the perl binary.

I wish. After a lot of faffing about I downloaded 5.12.3 and started 
from
scratch.

Perl 5.12.3 won't build on EMX anymore. Needs some functionality that
is not there.

Tried using gcc 3.3.5 but got errors as the hints file is full of emx
stuff. I don't know enough to hack the hints file :-(

ping Ilya
 
-- 
Regards
Dave Saville


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

Date: Thu, 17 Mar 2011 02:00:38 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: C Compiler question
Message-Id: <slrnio2n9m.7es.hjp-usenet2@hrunkner.hjp.at>

On 2011-03-16 22:03, Dave Saville <dave@invalid.invalid> wrote:
> On Wed, 16 Mar 2011 14:47:31 UTC, Tad McClellan <tadmc@seesig.invalid>
> wrote:
>> recompile the perl binary.
>
> I wish. After a lot of faffing about I downloaded 5.12.3 and started
> from scratch.
>
> Perl 5.12.3 won't build on EMX anymore. Needs some functionality that
> is not there.

| EMX (Eberhard Mattes eXtender), a.k.a. emx+gcc, is a programming
| environment for DOS and OS/2.

???

Hmm, yeah. Platforms are only supported as long as somebody is willing
to support them. For a 32-bit extender for DOS and OS/2 you are very
likely one of the last few people who use it so the person who has to
support it is you. 

The good thing about open source is that support cannot die as long as
there are users who are willing and able to support the project.

The bad thing is that support will die if there aren't any users who are
willing and able to support the project.

> ping Ilya

Yes, Ilya might be the other remaining user of EMX ;-).

	hp


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

Date: Wed, 16 Mar 2011 20:36:47 +0200
From: George Mpouras <nospam.gravitalsun@hotmail.com.nospam>
Subject: Re: convenient module to take statistics for hashed structures?
Message-Id: <ilqvvv$nui$1@news.ntua.gr>


# This one meet your requirements
# It can handle even more data than the previous versions



my @col;
my %data;
ReadData();

$_ = query('01',75);
print "Field=$_->[0],Value=@{$_->[1]}\n";



sub ReadData
{
while (<DATA>) { chomp;
my @a = split /\s*\|\s*/, $_, -1;
if (-1 == $#col){push @col, @a[1..$#a] ;next}
unless (1+$#col==$#a) {warn "Skip line number $. \"$_\" because it have 
".(1+$#a)." fields, while it should have ".(1+$#col)."\n";next}
$data{$a[0]}->[0]++;
for(my $i=1;$i<=$#a;$i++){$data{$a[0]}->[1]->[$i-1]->[0]->{$a[$i]}++}}

	foreach my $id (keys %data)
	{
		foreach my $f ( @{$data{$id}->[1]} )
		{
			foreach my $v ( keys %{$f->[0]} )
			{
			push @{ $f->[1]->{int 100*( $f->[0]->{$v}/$data{$id}->[0])} }, $v
			}
				
		 # remove unnecessary structures
		$f = $f->[1]
		}

	# remove unnecessary structures
	$data{$id} = $data{$id}->[1]
	}

#use Data::Dumper; print Dumper(\%data);exit;
}


sub query
{
	for(my $i=$#{$data{$_[0]}}; $i>=0; $i--)
	{
		foreach my $RANK (keys %{$data{$_[0]}->[$i]})
		{
		return [$col[$i], $data{$_[0]}->[$i]->{$RANK}] if $RANK >= $_[1]
		}
	}

['',[]]
}


__DATA__
ID|B|C|D|E|F|G|H
01|3|7|9|3|4|2|3
01|3|7|9|3|4|2|2
01|3|7|9|5|8|6|6
01|3|7|9|3|4|2|3
02|4|7|9|3|4|2|1
02|4|7|9|3|4|2|2
02|4|7|9|3|4|2|3
02|4|7|9|3|4|2|3


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

Date: Wed, 16 Mar 2011 20:02:55 -0700
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 2.2 How can I get a binary version of perl?
Message-Id: <160320112002550560%brian.d.foy@gmail.com>

In article <4d7e8ce5$0$81474$e4fe514c@news.xs4all.nl>, Dr.Ruud
<rvtol+usenet@xs4all.nl> wrote:

> Another nice one:
> 
>    Citrus Perl
>    http://www.cava.co.uk/

Has anyone used this? Is it good enough to be in the FAQ?


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

Date: Wed, 16 Mar 2011 12:01:53 -0400
From: Art Werschulz <agw@dsm.fordham.edu>
Subject: Re: going from CPAN to RPM
Message-Id: <2mlj0ft5ou.fsf@sobolev.dsm.fordham.edu>

Hi.

Paul Uiterlinden <puiterl@notaimvalley.nl> writes:

> You should protect the * from expansion by putting it in quotes or
> preceding it with a back slash. As it is now, the result completely
> depends on the contents of your current working directory. If by
> chance you have a file or directory named 'perl-blah' in your current
> working directory, you will only search for perl-bla.
>
> So use:
>
>   rpm -qa 'perl-*'

Oops.  Silly blunder on my part, and I should know better. 
But getting back to the original issue: the command
   rpm -ql `rpm -qa perl-\*`|grep vendor  
produces no output.

-- 
Art Werschulz (8-{)}   "Metaphors be with you."  -- bumper sticker
GCS/M (GAT): d? -p+ c++ l++ u+ P++ e--- m* s n+ h f g+ w+ t+ r- 
Net: agw@dsm.fordham.edu http://www.dsm.fordham.edu/~agw
Phone:   Fordham U. (212) 636-6325, Columbia U. (646) 775-6035


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

Date: Wed, 16 Mar 2011 17:58:55 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: going from CPAN to RPM
Message-Id: <fr6758-63b.ln1@news.rtij.nl>

On Wed, 16 Mar 2011 12:01:53 -0400, Art Werschulz wrote:

> Oops.  Silly blunder on my part, and I should know better. But getting
> back to the original issue: the command
>    rpm -ql `rpm -qa perl-\*`|grep vendor
> produces no output.

So this is a dead end. However, as the names of the Perl modules and the 
RPMs correspond one to one in my experience:

- Get a list of installed modules (see FAQ) >installed-modules.txt
- sed 's/::/-/g's/^/perl-/ installed-modules.txt | xargs rpm -q

Haven't tried it, so I cannot say it works, but it should.

HTH,
M4


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

Date: Thu, 17 Mar 2011 02:05:00 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: going from CPAN to RPM
Message-Id: <slrnio2nhs.7es.hjp-usenet2@hrunkner.hjp.at>

On 2011-03-16 16:58, Martijn Lievaart <m@rtij.nl.invlalid> wrote:
> On Wed, 16 Mar 2011 12:01:53 -0400, Art Werschulz wrote:
>> Oops.  Silly blunder on my part, and I should know better. But getting
>> back to the original issue: the command
>>    rpm -ql `rpm -qa perl-\*`|grep vendor
>> produces no output.
>
> So this is a dead end. However, as the names of the Perl modules and the 
> RPMs correspond one to one in my experience:
>
> - Get a list of installed modules (see FAQ) >installed-modules.txt
> - sed 's/::/-/g's/^/perl-/ installed-modules.txt | xargs rpm -q

The RPM is usually named after the distribution, not the module. So that
works for many modules, but not for all. For example, LWP::Simple is
included in the distribution libwww-perl, so the RPM is called
perl-libwww-perl.

	hp


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

Date: Wed, 16 Mar 2011 08:20:46 -0700 (PDT)
From: "seven.reeds" <seven.reeds@gmail.com>
Subject: HTML::TreeBuilder filter critique
Message-Id: <5b7eb3a9-c799-40af-81f2-7bc897b0c3b8@r19g2000prm.googlegroups.com>

 Hi,

I have a simple web form that should accept "plain text" or simple
XHTML that is limited to correct "P" and "A" tags.  The result for
this field should be simple XHTML with obvious paragraphs (in an XHTML
context) wrapped in "P" tags without any attributes (no class, id,
style, etc attributes).  Also, if there are "A" tags then they are
allowed as long as they have an "href" attribute.

The following is a fairly simple filter for this.  It seems to do
what I want on the tests I have run.

My question is: is this too naive?  Is there a gaping hole I am not
seeing?



#!/usr/bin/perl -w

use HTML::TreeBuilder;

#
# Sample input
#
my $tmp = <<EOF;

    one two three four</p>

<p class="foo">Mary Had a little lamb</p>

<p>Its <a href="a b c d">fleece was white as snow </p>

<p>And every <img src />where that Mary went</p>

    one two three fourA
EOF

#
# Init TreeBuilder
#
my $tb = HTML::TreeBuilder->new();
$tb->implicit_tags(1);
$tb->implicit_body_p_tag(1);
$tb->p_strict(1);
$tb->store_comments(0);
$tb->store_declarations(0);
$tb->parse($tmp);
$tb->eof;

#
# Find the initial entry point into the text
#
my $body = $tb->look_down("_tag", "body");

#
# Do the work
#
# This is saying: for each HTML component under "body" call the
"scrub"
# subroutine and print out the possibly edited result.
#
map {&scrub($_);
     print STDOUT $_->as_HTML(undef, undef, {}), "\n";}
    $body->content_list();

#
# Clean up and exit
#
$tb->delete();

exit(0);


sub scrub {
    my ($element) = @_;
    my $replaceContentFlag = 0;

    #
    # If the incoming element is TEXT just return
    #
    return if (! ref($element));

    #
    # Do work based on the element's "tag"
    #
    if (lc($element->tag()) eq "p") {
        #
        # This is a P tag. The map and the "attr($_, undef)" clause
        # removes all attributes from the P tag.
        #
        map {$element->attr($_, undef);}
            $element->all_external_attr_names();
    } elsif (lc($element->tag()) eq "a") {
        #
        # This is an A tag. The map and the "attr($_, undef)" clause
        # removes all attributes from the A tag that are not "href".
        #
        map {$element->attr($_, undef) unless(lc($_) eq "href");}
            $element->all_external_attr_names();
    } else {
        #
        # This is some other tag. It could have useful "content" even
        # if the tag is not allowed. Set this flag before we recurse.
        #
        $replaceContentFlag = 1;
    }

    #
    # Recurse into the content of the incoming tag.
    #
    map {&scrub($_);} $element->content_list();

    if ($replaceContentFlag) {
        #
        # The incoming tag was not a P or A. We have recursed through
        # its content_list so we need to "remove" the incoming tag.
The
        # removal happens by replacing the incoming tag in its
Parent's
        # content_list with this content_list.
        #
        $element->replace_with($element->content_list())->delete;
    }
}


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

Date: Wed, 16 Mar 2011 15:39:59 -0700 (PDT)
From: Mark <google@markginsburg.com>
Subject: List assignment to array affects scalar results
Message-Id: <d9c01582-e73b-4f71-ab8d-c5b73da086f7@n2g2000prj.googlegroups.com>

Why does the introduction of the assignment to @b affect the value of
$cnt?

use strict;
use warnings;

my $cnt;
my($x,$y,$z);
my(@ary) = qw(a b c d e);


$cnt = ( ($x,$y,$z) = @ary );
print "cnt=$cnt\n"; # produces 5

my @b;
$cnt = ( @b = ($x,$y,$z) = @ary );
print "cnt=$cnt\n"; # produces 3


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

Date: 16 Mar 2011 17:16:41 GMT
From: hymie@lactose.homelinux.net (hymie!)
Subject: module for MSCRM?
Message-Id: <4d80f078$0$4996$882e7ee2@usenet-news.net>

Greetings.

My company has recently switched to MS CRM, and I now need to port all of
our perl programs to use the new database.

Is there a perl module for MS CRM?  I couldn't find one on cpan, but my
search-fu is not strong.

Thanks.

--hymie!    http://lactose.homelinux.net/~hymie    hymie@lactose.homelinux.net


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

Date: Wed, 16 Mar 2011 13:03:54 -0700 (PDT)
From: alfonsobaldaserra <alfonso.baldaserra@gmail.com>
Subject: reading .ini file without using a module
Message-Id: <fdc85dde-95bb-4ec1-b06b-a531fe236e7d@s18g2000prg.googlegroups.com>

hello group,

i understand that there are modules to parse and read .ini files but
just to understand data structures better i was playing with this.
the following code is from perl developers dictionary:

use strict;
use warnings;
use Data::Dumper;

open my $fh, '<', "my.ini" or die "$!\n";
my $ini = {};

{
        local $/ = "";
        while (<$fh>) {
                next unless ( s/\[([^]]+)\]// );
                my $header = $1;
                $ini->{$header} = {};
                while (m/(\w+)=(.*)/g) {
                        $ini->{$header}->{$1} = $2;
                }
        }
}
close $fh;

print Dumper $ini;


__DATA__
[Build]
BuildID=20110209115208
Milestone=2.0b11
SourceStamp=f9d66f4d17bf
SourceRepository=http://hg.mozilla.org/mozilla-central
; This file is in the UTF-8 encoding

[Strings]
Title=SeaMonkey Update
Info=SeaMonkey is installing your updates and will start in a few
moments


i could not figure a way to do something like

print $ini->{Build}->{Milestone}
# 2.0b11

print $ini->{Strings}->{Title}
# SeaMonkey Update

could somebody lend me their hand to figure how to make this work?

thanks


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

Date: Wed, 16 Mar 2011 22:35:09 +0200
From: George Mpouras <nospam.gravitalsun@hotmail.com.nospam>
Subject: Re: reading .ini file without using a module
Message-Id: <ilr6tt$1c72$1@news.ntua.gr>

Στις 16/3/2011 10:03 μμ, ο/η alfonsobaldaserra έγραψε:
> use strict;
> use warnings;
> use Data::Dumper;
>
> open my $fh, '<', "my.ini" or die "$!\n";
> my $ini = {};
>
> {
>          local $/ = "";
>          while (<$fh>) {
>                  next unless ( s/\[([^]]+)\]// );
>                  my $header = $1;
>                  $ini->{$header} = {};
>                  while (m/(\w+)=(.*)/g) {
>                          $ini->{$header}->{$1} = $2;
>                  }
>          }
> }
> close $fh;
>
> print Dumper $ini;
>
>
> __DATA__
> [Build]
> BuildID=20110209115208
> Milestone=2.0b11
> SourceStamp=f9d66f4d17bf
> SourceRepository=http://hg.mozilla.org/mozilla-central
> ; This file is in the UTF-8 encoding
>
> [Strings]
> Title=SeaMonkey Update
> Info=SeaMonkey is installing your updates and will start in a few
> moments
>
>
> i could not figure a way to do something like
>
> print $ini->{Build}->{Milestone}
> # 2.0b11
>
> print $ini->{Strings}->{Title}
> # SeaMonkey Update
>
> could somebody lend me their hand to figure how to make this work?
>
> thanks

try to create the my.ini with the same data and give a shot !


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

Date: Thu, 17 Mar 2011 01:49:06 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: recursive Pythagorian triples
Message-Id: <slrnio2mk2.7es.hjp-usenet2@hrunkner.hjp.at>

On 2011-03-16 14:31, Ed <ednotover@gmail.com> wrote:
> On Mar 16, 2:13am, George Mpouras
><nospam.gravital...@hotmail.com.nospam> wrote:
>
> [ much snipped ]
>
>> Did you find any missing triplet ?

I was going to reply that for $iterator->(4) it is apparent that many
triplets are missing and even for $iterator->(8), which produces
triplets with some values > 100 some values < 100 are still missing but


> The code does not produce, say, 9,12,15 (nor does it produce
> 12,9,15).

this is a much better example, because it shows that there are some
triplets that the code can never produce  parameter no matter how large
the parameter of $iterator is.

Because it is clear that the code can never produce 12,9,15 (the second
number  is 2*$i*$j, so it must be even and 9 is not even) and for
9,12,15, the second term can only be produced by $i=3 and $j = 2, which
produces

    $i**2 - $j**2 = 9 - 4     = 5
    2 * $i * $j   = 2 * 3 * 2 = 12
    $i**2 + $j**2 = 9 + 4     = 13

which is not 9,12,15. So the code can never produce 9,12,15, no matter
which parameter $iterator is called. 

Q.E.D.

> See my other post about iterating over a multiplier (the k value
> described in the wiki article).

Yup.

	hp



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

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


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