[30392] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1635 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 12 16:09:47 2008

Date: Thu, 12 Jun 2008 13:09:13 -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, 12 Jun 2008     Volume: 11 Number: 1635

Today's topics:
        DirectoryIndex not working with AuthDBI <jcharth@gmail.com>
    Re: DirectoryIndex not working with AuthDBI <smallpond@juno.com>
    Re: How to unpack long long ? <ben@morrow.me.uk>
    Re: How to unpack long long ? <tzz@lifelogs.com>
        Learning Perl <elizabethbarnwell@gmail.com>
    Re: Learning Perl <uri@stemsystems.com>
    Re: Range of number <baxter.brad@gmail.com>
        Reading a line from a CVS file into an array. <colin@yoursupport.biz>
    Re: Reading a line from a CVS file into an array. <yankeeinexile@gmail.com>
    Re: Reading a line from a CVS file into an array. <jurgenex@hotmail.com>
    Re: Reading a line from a CVS file into an array. <colin@yoursupport.biz>
    Re: Reading a line from a CVS file into an array. <smallpond@juno.com>
    Re: Reading a line from a CVS file into an array. <danrumney@warpmail.net>
    Re: sorting a hash / 2008-06-01 <dave@nospam.deezee.org>
    Re: sorting a hash / 2008-06-01 xhoster@gmail.com
    Re: sorting a hash / 2008-06-01 <dave@nospam.deezee.org>
    Re: sorting a hash / 2008-06-01 <uri@stemsystems.com>
    Re: sorting a hash / 2008-06-01 <dave@nospam.deezee.org>
    Re: XML::Simple how to force hash generation for keys <news@nana.franken.de>
    Re: XML::Simple how to force hash generation for keys xhoster@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 12 Jun 2008 10:54:07 -0700 (PDT)
From: joe <jcharth@gmail.com>
Subject: DirectoryIndex not working with AuthDBI
Message-Id: <8d84528f-ab41-4f6e-9416-67284d52ed35@79g2000hsk.googlegroups.com>

Hello I manage to get AuthDBI to work but now the directory does not
recognize index.php or index.htm when typing www.domain.com   i get
403 and I get a list of files if I add  Options Indexes. I believe it
could be related to not having perlhander but if I add apache::asp as
the perlhandler it does not work. Any suggestions? Thanks


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

Date: Thu, 12 Jun 2008 15:21:16 -0400
From: smallpond <smallpond@juno.com>
Subject: Re: DirectoryIndex not working with AuthDBI
Message-Id: <211d7$4851773b$27423@news.teranews.com>

joe wrote:
> Hello I manage to get AuthDBI to work but now the directory does not
> recognize index.php or index.htm when typing www.domain.com   i get
> 403 and I get a list of files if I add  Options Indexes. I believe it
> could be related to not having perlhander but if I add apache::asp as
> the perlhandler it does not work. Any suggestions? Thanks

403 Access Forbidden - not a perl problem.  Look at the web server error logs.

** Posted from http://www.teranews.com **


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

Date: Thu, 12 Jun 2008 18:20:55 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to unpack long long ?
Message-Id: <ng28i5-mld.ln1@osiris.mauzo.dyndns.org>


Quoth Golan <ghadad@gmail.com>:
> How do i unpack "long long" int  type ( 8 bytes )  ?

'q'. Note that your perl needs to be built with 64bit integers.

Ben

-- 
                Outside of a dog, a book is a man's best friend.
                Inside of a dog, it's too dark to read.
ben@morrow.me.uk                                                  Groucho Marx


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

Date: Thu, 12 Jun 2008 14:31:37 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to unpack long long ?
Message-Id: <86skvio3fq.fsf@lifelogs.com>

On Thu, 12 Jun 2008 18:20:55 +0100 Ben Morrow <ben@morrow.me.uk> wrote: 

BM> Quoth Golan <ghadad@gmail.com>:
>> How do i unpack "long long" int  type ( 8 bytes )  ?

BM> 'q'. Note that your perl needs to be built with 64bit integers.

That seems like an unnecessary restriction.  Is it really impossible for
a 32-bit Perl to decode 64-bit numbers?  We know the endianness, is
there anything else needed?

Ted


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

Date: Thu, 12 Jun 2008 09:52:52 -0700 (PDT)
From: Elizabeth Barnwell <elizabethbarnwell@gmail.com>
Subject: Learning Perl
Message-Id: <dfa1a2b1-0455-4bf1-9cf8-9525335f1ed5@56g2000hsm.googlegroups.com>

Here is a set of flashcards our developers have been using to learn
Perl with very good results:

http://www.yoyobrain.com/subjects/show/3121

Add the subject to your study materials, click on try a learning
drill.

This is an example of one person's study materials, but you can make
your own as well. We are adding features to the site to allow users to
comment on existing content/build learning material together/attribute
content to various sources. With this, we're hoping that the quality
of the information will improve, providing a resource to the
community.

In the mean time, I hope it finds you well.

Best,

Elizabeth


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

Date: Thu, 12 Jun 2008 19:04:46 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Learning Perl
Message-Id: <x763sescdt.fsf@mail.sysarch.com>

>>>>> "EB" == Elizabeth Barnwell <elizabethbarnwell@gmail.com> writes:

  EB> Here is a set of flashcards our developers have been using to learn
  EB> Perl with very good results:

  EB> http://www.yoyobrain.com/subjects/show/3121

  EB> Add the subject to your study materials, click on try a learning
  EB> drill.

i will have to take a peek as i do with most proffered perl web
tutorials. 

  EB> This is an example of one person's study materials, but you can make
  EB> your own as well. We are adding features to the site to allow users to
  EB> comment on existing content/build learning material together/attribute
  EB> content to various sources. With this, we're hoping that the quality
  EB> of the information will improve, providing a resource to the
  EB> community.

the problem is that most learning users of perl don't know enough perl
or how to teach to explain things correctly and with enough depth and
coverage. 

	Operator to force a list into scalar context

ok, that is classicly wrong. there is no such thing as a list in scalar
context. it should be an array, not list.

these flash cards don't seem to be useful IMO. they are not deep enough
and there is no explanations of anything, just a simple question and
answer. there could be links to the docs, more info in each answer,
better grouping of questions, etc.

	Syntax for looping through the values in a list
	foreach $var @array {
	}

that should be my $var.

	Operators to add and remove items from the beginning of array
	unshift(@array, new_item)
	shift(@array)

what is new_item? unless that is a predeclared sub with a prototype it
is illegal. and it doesn't mention unshift takes a list. nor does it say
which function adds or removes (sure they are in the order mentioned in
the question but it should be pointed out. the same is true for the
push/pop slide.

the slides always say operator for what most call functions. sure they
are operators in some sense (they don't always need parens) but it is
poor terminology to always say operator.

	When using qw how do you include the characters in strings that
	you are using for qw delimiter
	escape them with backslash

	qw! string\!1 string\!2 ....!

wow. i can't recall ever needing to escape inside a qw! and most qw's
use matched delimiters or maybe //. no one uses ! !!!

	When using qw (quote word) shorcut what other symbols can be
	used as the delimiter besides ( )

        any

        qw# string1 string2 #
        qw! string1 string2 !

another wow. explaining about alternate delimiters in general (given the
8 or so ops that support them) would be better. this is why this single
question flash card thing is not a good idea IMO. it stresses studying
for the test (like an MSCE!) and not deeper understanding.

	What is the syntax for a list literal
	( value1, value2, ....)

huh? that is a list. literals are possible values in the list.

	What is the effect of using negative number for an array index
	it starts counting from the end of the array backwards

that is from the department of redundant answers department.

	How do you access an element in an array	 
	use [ ]
	x[3];

i see a syntax bug there!

	What value do variables hold until defined
	undef

hmm. do arrays and hashes hold undef? that should be scalar variables.

	Comparison operator for numbers
	==

hmm, i wonder what >, <, >= and <= have to say about that?
s/Comparison/Equality/

	How are all numbers stored interally by Perl
	double-precision floating-point values

hmm, i wonder what IV's have to say about that?


	How can you run Perl with warnings enabled
	-e
	perl -e program_name

whoops!! that flash card should be flashing red!

so as you can see, this site needs plenty of fixes and editing and it
doesn't seem to be too helpful. simple questions like these is not the
way to learn programming in any language.

uri

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


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

Date: Thu, 12 Jun 2008 11:03:24 -0700 (PDT)
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: Range of number
Message-Id: <d82ce720-0378-42ba-99ad-69c189fd1dbb@m36g2000hse.googlegroups.com>

On May 23, 4:43 am, "Dr.Ruud" <rvtol+n...@isolution.nl> wrote:
> In Perl6 you can write
>
>    if ( $MINNUM <= $number <= $MAXNUM )

sub in_range { $_[2] <= $_[1] and $_[1] <= $_[0] }

print "Yes\n" if in_range( $MAXNUM => $number => $MINNUM );

--
Brad


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

Date: Thu, 12 Jun 2008 11:34:47 -0700 (PDT)
From: coffeevictim <colin@yoursupport.biz>
Subject: Reading a line from a CVS file into an array.
Message-Id: <fa8cb022-415a-484b-bc8a-9dee66ecbdaf@x35g2000hsb.googlegroups.com>

Hi,

I have the fairly simply task of manipulating a CSV file containing
marketing data (name, address, business description etc.) so it can be
imported into a CRM system.

The problem is that some of the text fields also contain commas so I
am a bit stumped as to how to construct a command that will accurately
split the line at the actual separators. The text containing commas
that are not separators is quoted so Excel does not have a problem
understanding it but I can not think how to get my script to ignore
the ones in quotes.

My standard attempt to split the line looks like...

@LEAD =3D split (/\,/, $SOURCELINE);

but this of course treats any comma as a separator and so the result
is unpredictable.

A sample of the source data follows.

Sort Id,Company Name,Address 1,Address 2,City,Description
5,Aploda,"C/ San Romualdo, 43, 5=BA planta",Local A4,Madrid,=94Some text,
maybe.=94
27,Degna Solutions,"Mallorca, 182, Principal 2a",,Barcelona,=94Some more
text, probably.=94

Any help would be greatly appreciated.

coffeevictim


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

Date: 12 Jun 2008 13:49:45 -0500
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: Reading a line from a CVS file into an array.
Message-Id: <877icuzdx2.fsf@hummer.cluon.com>

coffeevictim <colin@yoursupport.biz> writes:


> Hi,
> 
> I have the fairly simply task of manipulating a CSV file containing
> marketing data (name, address, business description etc.) so it can be
> imported into a CRM system.
> 
> The problem is that some of the text fields also contain commas so I
> am a bit stumped as to how to construct a command that will accurately
> split the line at the actual separators. The text containing commas
> that are not separators is quoted so Excel does not have a problem
> understanding it but I can not think how to get my script to ignore
> the ones in quotes.
> 

use Text::CSV;

If you have it, Text::CSV_XS;



-- 
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
place them into the correct order.


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

Date: Thu, 12 Jun 2008 18:52:30 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Reading a line from a CVS file into an array.
Message-Id: <3tr254l2a9n57bhrn4v8ko10db82j8qjla@4ax.com>

coffeevictim <colin@yoursupport.biz> wrote:
>The problem is that some of the text fields also contain commas so I
>am a bit stumped as to how to construct a command that will accurately
>split the line at the actual separators. 

I don't know the file format CVS, but if you are talking about CSV then
is there anything wrong with Text::CSV?

jue


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

Date: Thu, 12 Jun 2008 12:28:56 -0700 (PDT)
From: coffeevictim <colin@yoursupport.biz>
Subject: Re: Reading a line from a CVS file into an array.
Message-Id: <a71c3fb2-a56b-47a2-871e-f02e5e873662@j22g2000hsf.googlegroups.com>

On 12 Jun, 19:52, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> coffeevictim <co...@yoursupport.biz> wrote:
> >The problem is that some of the text fields also contain commas so I
> >am a bit stumped as to how to construct a command that will accurately
> >split the line at the actual separators.
>
> I don't know the file format CVS, but if you are talking about CSV then
> is there anything wrong with Text::CSV?
>
> jue

CSV. My mistake.

Since I wish to execute the script at the Windows command line and
make it as portable as possible, I was hoping to to use just perl.exe.


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

Date: Thu, 12 Jun 2008 15:48:23 -0400
From: smallpond <smallpond@juno.com>
Subject: Re: Reading a line from a CVS file into an array.
Message-Id: <2e1a3$48517d97$30757@news.teranews.com>

  wrote:
> coffeevictim <colin@yoursupport.biz> wrote:
>> The problem is that some of the text fields also contain commas so I
>> am a bit stumped as to how to construct a command that will accurately
>> split the line at the actual separators. 
> 
> I don't know the file format CVS, but if you are talking about CSV then
> is there anything wrong with Text::CSV?
> 
> jue


CVS is the pharmaceutical record format for dyslexia.

** Posted from http://www.teranews.com **


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

Date: Thu, 12 Jun 2008 15:51:31 -0400
From: Dan Rumney <danrumney@warpmail.net>
Subject: Re: Reading a line from a CVS file into an array.
Message-Id: <48517e45$0$30226$4c368faf@roadrunner.com>

coffeevictim wrote:
> On 12 Jun, 19:52, Jürgen Exner <jurge...@hotmail.com> wrote:
>> coffeevictim <co...@yoursupport.biz> wrote:
>>> The problem is that some of the text fields also contain commas so I
>>> am a bit stumped as to how to construct a command that will accurately
>>> split the line at the actual separators.
>> I don't know the file format CVS, but if you are talking about CSV then
>> is there anything wrong with Text::CSV?
>>
>> jue
> 
> CSV. My mistake.
> 
> Since I wish to execute the script at the Windows command line and
> make it as portable as possible, I was hoping to to use just perl.exe.

Run perl -h

You'll see that there is a parameter:

  -M

Which allows you to pull in Modules via the command line


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

Date: 12 Jun 2008 15:19:46 GMT
From: "Dave Saville" <dave@nospam.deezee.org>
Subject: Re: sorting a hash / 2008-06-01
Message-Id: <fV45K0OBJxbE-pn2-nFoMIIOWKWKr@localhost>

On Thu, 12 Jun 2008 14:53:11 UTC, Uri Guttman <uri@stemsystems.com> 
wrote:

>> i highly doubt this is a perl bug. my gut feeling is that you have 
a
> scoping problem. the first sort keeps $a and $b inside the sort block
> and those will be set correctly. if you lexically declared $a and $b in your
> code before the by_value sub, those will be used and screw up your
> sort. or maybe a different $site is being used because it is in a
> different scope. you need to post more code so we can see the
> problem. it isn't just with the above code.

I suspect your are right and I have done something *really* stupid - 
but I get the same on a Solaris system. $a & $b are correct and from 
the correct $site.  

==================
#!/usr/bin/perl

use strict;
use warnings;

my $site;
my %sites;
my %urls;

  $sites{DEEZEE}++;
  $sites{SSL}++;
  $sites{Web2}++;

  $urls{DEEZEE}{url_1}[0]++; # count
  $urls{DEEZEE}{url_1}[1] = 'yyyy/mm/dd';
  $urls{DEEZEE}{url_2}[0]++; # count
  $urls{DEEZEE}{url_2}[1] = 'yyyy/mm/dd';
  $urls{DEEZEE}{url_2}[0]++; # count
  $urls{DEEZEE}{url_2}[1] = 'yyyy/mm/dd';
  $urls{SSL}{url_2}[0]++; # count
  $urls{SSL}{url_2}[1] = 'yyyy/mm/dd';
  $urls{SSL}{url_3}[0]++; # count
  $urls{SSL}{url_3}[1] = 'yyyy/mm/dd';

foreach $site (keys %sites)
{
  print "\nSite: $site\n";

  foreach my $url (sort {$urls{$site}{$b}[0] <=> $urls{$site}{$a}[0] 
or $a cmp $b} keys %{$urls{$site}})
  {
    print "$site $url $urls{$site}{$url}[0] $urls{$site}{$url}[1]\n";
  }
}

foreach $site (keys %sites)
{
  print "\nSite: $site\n";

  foreach my $url (sort by_value keys %{$urls{$site}})
  {
    print "$site $url $urls{$site}{$url}[0] $urls{$site}{$url}[1]\n";
  }
}

sub by_value
{
  print "Sort site: >$site< $a $b\n";
  $urls{$site}{$b}[0] <=> $urls{$site}{$a}[0] or $a cmp $b;
}

==========

Yeilds:

==============
Site: SSL
SSL url_2 1 yyyy/mm/dd
SSL url_3 1 yyyy/mm/dd

Site: DEEZEE
DEEZEE url_2 2 yyyy/mm/dd
DEEZEE url_1 1 yyyy/mm/dd

Site: Web2

Site: SSL
Use of uninitialized value in concatenation (.) or string at try.pl 
line 50.
Sort site: >< url_3 url_2
Use of uninitialized value in hash element at try.pl line 51.
Use of uninitialized value in hash element at try.pl line 51.
Use of uninitialized value in hash element at try.pl line 51.
Use of uninitialized value in numeric comparison (<=>) at try.pl line 
51.
Use of uninitialized value in numeric comparison (<=>) at try.pl line 
51.
SSL url_2 1 yyyy/mm/dd
SSL url_3 1 yyyy/mm/dd

Site: DEEZEE
Use of uninitialized value in concatenation (.) or string at try.pl 
line 50.
Sort site: >< url_1 url_2
Use of uninitialized value in hash element at try.pl line 51.
Use of uninitialized value in hash element at try.pl line 51.
Use of uninitialized value in numeric comparison (<=>) at try.pl line 
51.
Use of uninitialized value in numeric comparison (<=>) at try.pl line 
51.
DEEZEE url_1 1 yyyy/mm/dd
DEEZEE url_2 2 yyyy/mm/dd

Site: Web2

==========

In this case $site has no value in the sub. In the real program it had
one of the other sites as a value rather than the correct one.

-- 
Regards
Dave Saville

NB Remove nospam. for good email address


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

Date: 12 Jun 2008 15:57:37 GMT
From: xhoster@gmail.com
Subject: Re: sorting a hash / 2008-06-01
Message-Id: <20080612115739.424$k9@newsreader.com>

"Dave Saville" <dave@nospam.deezee.org> wrote:
> On Thu, 12 Jun 2008 14:53:11 UTC, Uri Guttman <uri@stemsystems.com>
> wrote:
>
> >> i highly doubt this is a perl bug. my gut feeling is that you have
> a
> > scoping problem. the first sort keeps $a and $b inside the sort block
> > and those will be set correctly. if you lexically declared $a and $b in
> > your code before the by_value sub, those will be used and screw up your
> > sort. or maybe a different $site is being used because it is in a
> > different scope. you need to post more code so we can see the
> > problem. it isn't just with the above code.
>
> I suspect your are right and I have done something *really* stupid -
> but I get the same on a Solaris system. $a & $b are correct and from
> the correct $site.
>

>
> my $site;

You should declare variables in the tightest scope you can, otherwise
use strict will be less helpful in finding such scoping problems.

 ...

> foreach $site (keys %sites)

it would be better to use "foreach my $site"

> {
>   print "\nSite: $site\n";
>
>   foreach my $url (sort by_value keys %{$urls{$site}})
>   {
>     print "$site $url $urls{$site}{$url}[0] $urls{$site}{$url}[1]\n";
>   }
> }

The way foreach works, the $site inside the loop is not the same
as the $site declared outside the loop.


>
> sub by_value
> {
>   print "Sort site: >$site< $a $b\n";
>   $urls{$site}{$b}[0] <=> $urls{$site}{$a}[0] or $a cmp $b;
> }


The $site used by by_value is the one from outside the foreach loop, not
the one inside the foreach loop.  Usually you'd just pass in $site as an
argument, but when the sub is called automatically from sort, that doesn't
work.

There are a variety ways around this, but none of them are entirely
satisfactory.  One would be to make the sub an ordinary subroutine,
rather than one made specifically to be used by sort, then invoke
it explicitly rather than implicitly:

foreach my $url (sort {by_value($a,$b,$site)} keys %{$urls{$site}})
 ...
sub by_value
{
  my ($a,$b,$site)=@_;
  print "Sort site: >$site< $a $b\n";
  $urls{$site}{$b}[0] <=> $urls{$site}{$a}[0] or $a cmp $b;
}


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: 12 Jun 2008 16:10:04 GMT
From: "Dave Saville" <dave@nospam.deezee.org>
Subject: Re: sorting a hash / 2008-06-01
Message-Id: <fV45K0OBJxbE-pn2-kIpIDVVUqC82@localhost>

On Thu, 12 Jun 2008 15:57:37 UTC, xhoster@gmail.com wrote:

> "Dave Saville" <dave@nospam.deezee.org> wrote:
> > my $site;
> 
> You should declare variables in the tightest scope you can, otherwise
> use strict will be less helpful in finding such scoping problems.
> 
> ...
> 
> > foreach $site (keys %sites)
> 
> it would be better to use "foreach my $site"
> 
> > {
> >   print "\nSite: $site\n";
> >
> >   foreach my $url (sort by_value keys %{$urls{$site}})
> >   {
> >     print "$site $url $urls{$site}{$url}[0] $urls{$site}{$url}[1]\n";
> >   }
> > }
> 
> The way foreach works, the $site inside the loop is not the same
> as the $site declared outside the loop.

Ah Ah. I did not know that. Many thanks for pointing it out, that of 
course explains everything. 

-- 
Regards
Dave Saville

NB Remove nospam. for good email address


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

Date: Thu, 12 Jun 2008 16:37:58 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: sorting a hash / 2008-06-01
Message-Id: <x7lk1atxqx.fsf@mail.sysarch.com>

>>>>> "x" == xhoster  <xhoster@gmail.com> writes:

  x> "Dave Saville" <dave@nospam.deezee.org> wrote:
  >> On Thu, 12 Jun 2008 14:53:11 UTC, Uri Guttman <uri@stemsystems.com>
  >> wrote:
  >> 
  >> my $site;

  >> foreach $site (keys %sites)

  x> The way foreach works, the $site inside the loop is not the same
  x> as the $site declared outside the loop.

i was smelling a scoping issue since the sort sub used external stuff
and also the loop variable. i didn't spot the extra my $site. but i was
right in general! :)

  x> There are a variety ways around this, but none of them are entirely
  x> satisfactory.  One would be to make the sub an ordinary subroutine,
  x> rather than one made specifically to be used by sort, then invoke
  x> it explicitly rather than implicitly:

or he could use a different name for the for loop variable. since for
variables are localized, it would be seen in the sort sub as he wrote
it. it was the my $site outside that was being seen by the sort
sub. regardless, it isn't a good idea to use sort subs that refer to
external variables - too dangerous as we have seen here.

uri

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


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

Date: 12 Jun 2008 17:28:50 GMT
From: "Dave Saville" <dave@nospam.deezee.org>
Subject: Re: sorting a hash / 2008-06-01
Message-Id: <fV45K0OBJxbE-pn2-Xxpp4nv1EVvd@localhost>

Thank you both very much for the education. Much appreciated.

-- 
Regards
Dave Saville

NB Remove nospam. for good email address


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

Date: Thu, 12 Jun 2008 17:31:10 +0200
From: Wolfgang Thomas <news@nana.franken.de>
To: =?ISO-8859-1?Q?Andreas_P=FCrzer?= <pue@gmx.net>
Subject: Re: XML::Simple how to force hash generation for keys
Message-Id: <4851413E.3040007@nana.franken.de>

Andreas Pürzer wrote:
> You want the 'ForceArray' option:
 > ...
> my $xml = XMLin(
>     \*DATA,
>     ForceArray => ['anything'],
>     KeyAttr => ['id'],

This generates exactly the output, that I expected. Thank you!

But honestly, I do not understand why: From the description of this 
option I would expect that this option creates arrays, which I do not 
want. But used, as you proposed, the option does not create arrays, but 
the hash I was missing.


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

Date: 12 Jun 2008 16:20:25 GMT
From: xhoster@gmail.com
Subject: Re: XML::Simple how to force hash generation for keys
Message-Id: <20080612122026.991$7N@newsreader.com>

Wolfgang Thomas <news@nana.franken.de> wrote:
> Andreas Pürzer wrote:
> > You want the 'ForceArray' option:
>  > ...
> > my $xml = XMLin(
> >     \*DATA,
> >     ForceArray => ['anything'],
> >     KeyAttr => ['id'],
>
> This generates exactly the output, that I expected. Thank you!
>
> But honestly, I do not understand why: From the description of this
> option I would expect that this option creates arrays, which I do not
> want. But used, as you proposed, the option does not create arrays, but
> the hash I was missing.

KeyAttr controls how arrays are turned into hashes.  But if there is no
array there, it won't be turned into a hash.  So you have to force
single-element entries to be treated as an array of 1, so it can then be
detected and folded into a hash.

The docs are kind of written from the package creator's perspective rather
than the user's perspective.  Unless you know that arrays are an
intermediate step between XML and final hash-based output, it is rather
confusing to have to think about arrays that are behind the scene which you
never see.  (But on the other hand, the docs do tell you that you should
almost always have ForceArray on, and that having the default be for it to
be off was a mistake.)

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

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 V11 Issue 1635
***************************************


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