[33009] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4285 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 18 14:09:25 2014

Date: Thu, 18 Sep 2014 11:09:11 -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, 18 Sep 2014     Volume: 11 Number: 4285

Today's topics:
        accept -vmargs -Xms512m -Xmx1024m using Getopt::Long <mikaelpetterson@hotmail.com>
    Re: accept -vmargs -Xms512m -Xmx1024m using Getopt::Lon <rweikusat@mobileactivedefense.com>
        Debugging help <tuxedo@mailinator.com>
    Re: Debugging help <news@lawshouse.org>
    Re: Debugging help <news@lawshouse.org>
    Re: Debugging help <tuxedo@mailinator.com>
    Re: Debugging help <gamo@telecable.es>
    Re: Debugging help <dmcanzi@uwaterloo.ca>
    Re: Debugging help <jurgenex@hotmail.com>
    Re: Debugging help <jurgenex@hotmail.com>
    Re: Debugging help <justin.1401@purestblue.com>
    Re: Debugging help <jurgenex@hotmail.com>
    Re: Debugging help <rweikusat@mobileactivedefense.com>
    Re: Debugging help <jurgenex@hotmail.com>
    Re: Debugging help (Tim McDaniel)
    Re: Debugging help <jurgenex@hotmail.com>
    Re: Debugging help <justin.1401@purestblue.com>
    Re: Debugging help (Tim McDaniel)
    Re: Debugging help <rweikusat@mobileactivedefense.com>
    Re: Debugging help <jurgenex@hotmail.com>
    Re: Devel::Peek's character count (or bytes, maybe?) <bauhaus@futureapps.invalid>
    Re: Devel::Peek's character count (or bytes, maybe?) <bauhaus@futureapps.invalid>
    Re: Devel::Peek's character count (or bytes, maybe?) <hjp-usenet3@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 18 Sep 2014 07:27:58 -0700 (PDT)
From: mike <mikaelpetterson@hotmail.com>
Subject: accept -vmargs -Xms512m -Xmx1024m using Getopt::Long
Message-Id: <4e5e4712-4cd9-4065-89f9-957ab2e879e9@googlegroups.com>

Hi,

I am trying:


#!/usr/bin/perl 

use strict;
use warnings;
use Getopt::Long; 

my @vmargs;
my ($man, $help);

GetOptions('help|?' => \$help, man => \$man, 'vmargs=s@{,}' => \@vmargs);
print "@vmargs\n";


---------------------
perl myscript.pl -vmargs -Xms512m -Xmx1024m

I get the following output:

Unknown option: xmx1024m
-Xms512m

What am I missing? 

//mike


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

Date: Thu, 18 Sep 2014 16:06:35 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: accept -vmargs -Xms512m -Xmx1024m using Getopt::Long
Message-Id: <87r3z93r44.fsf@sable.mobileactivedefense.com>

mike <mikaelpetterson@hotmail.com> writes:
> I am trying:
>
>
> #!/usr/bin/perl 
>
> use strict;
> use warnings;
> use Getopt::Long; 
>
> my @vmargs;
> my ($man, $help);
>
> GetOptions('help|?' => \$help, man => \$man, 'vmargs=s@{,}' => \@vmargs);
> print "@vmargs\n";
>
>
> ---------------------
> perl myscript.pl -vmargs -Xms512m -Xmx1024m
>
> I get the following output:
>
> Unknown option: xmx1024m
> -Xms512m
>
> What am I missing?

{,} means 'one or more values'. Since -Xms512m is one value, it
satisfies the condition and the next string is interpreted as option
because it starts with a dash.

Why are you passing JVM 'memory control' arguments to Perl, BTW?



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

Date: Tue, 16 Sep 2014 10:54:11 +0200
From: Tuxedo <tuxedo@mailinator.com>
Subject: Debugging help
Message-Id: <lv8trj$en4$1@news.albasani.net>

Hello,

I have a hash like this:

#!/usr/bin/perl -w

use Tie::IxHash;
use strict;
use warnings;

my $obj_list = tie my %list, "Tie::IxHash";

%list =  ('coco' => 'cake',
'mango' => 'chutney',
'fish' => 'soup',
# .... and thousands of more entries between
'strawberry' => 'cream');

When running I get the error: 'Odd number of elements in hash assignment at 
 ./script.pl line n'.

With 'line n' I mean the number of the first line of the %list is returned, 
i.e. where 'coco' => 'cake', is.

So I have a simple syntax error somewhere in the list, just a typing error, 
but it's not on the line indicated and I cannot easily go through the whole 
list to search for the error visually because it contains several thousand 
lines. In other words, the shell does not indicate exactly where the error 
occurrs, it only points to the beginning of the list.

Can anyone can advise on a good procedure to check the syntax to highlight 
where the problem line(s) occur? Each pair is on a line by itself, e.g.:
'mango' => 'chutney',

Many thanks,
Tuxedo


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

Date: Tue, 16 Sep 2014 10:44:12 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: Debugging help
Message-Id: <GtydncHi3rrwm4XJnZ2dnUVZ8k6dnZ2d@giganews.com>

On 16/09/14 09:54, Tuxedo wrote:
> Can anyone can advise on a good procedure to check the syntax to highlight
> where the problem line(s) occur? Each pair is on a line by itself, e.g.:
> 'mango' => 'chutney',

Does your editor not help?  I use both eclipse (Epic) and emacs and they 
both highlight Perl in ways which, while not perfect, can make it easier 
to see missed commas and quotes and such.

Alternatively, could you try a sort-of binary search?  On a copy of the 
code (important!) either delete or comment out half the lines which 
define your hash and see if you still have the error.  Then half again 
if you do, and so on.

My last suggestion would be to try grep -n with some pattern which will 
match a correct hash element definition (something like 
\'.*\'\s+=>\s+\'.*\' but I always have to look up grep's regex); that 
would pull out all the code, of course, but also any hash-definition 
line that was different.

I'm a bit inclined to say that such a huge hash definition in code might 
be better moved out into a simple flat file (tab-separated, for example) 
and then read in.

-- 

Henry Law            Manchester, England


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

Date: Tue, 16 Sep 2014 11:13:19 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: Debugging help
Message-Id: <i-2dnaFSmfTdkIXJnZ2dnUVZ8hCdnZ2d@giganews.com>

On 16/09/14 10:44, Henry Law wrote:
> grep -n

Sorry.  Grep -v

-- 

Henry Law            Manchester, England


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

Date: Tue, 16 Sep 2014 12:32:55 +0200
From: Tuxedo <tuxedo@mailinator.com>
Subject: Re: Debugging help
Message-Id: <lv93ko$prd$1@news.albasani.net>

Henry Law wrote:

> On 16/09/14 09:54, Tuxedo wrote:
> > Can anyone can advise on a good procedure to check the syntax to
> > highlight where the problem line(s) occur? Each pair is on a line by
> > itself, e.g.: 'mango' => 'chutney',
> 
> Does your editor not help?  I use both eclipse (Epic) and emacs and they
> both highlight Perl in ways which, while not perfect, can make it easier
> to see missed commas and quotes and such.
> 
> Alternatively, could you try a sort-of binary search?  On a copy of the
> code (important!) either delete or comment out half the lines which
> define your hash and see if you still have the error.  Then half again
> if you do, and so on.
> 
> My last suggestion would be to try grep -n with some pattern which will
> match a correct hash element definition (something like
> \'.*\'\s+=>\s+\'.*\' but I always have to look up grep's regex); that
> would pull out all the code, of course, but also any hash-definition
> line that was different.
> 
> I'm a bit inclined to say that such a huge hash definition in code might
> be better moved out into a simple flat file (tab-separated, for example)
> and then read in.
> 

You are right of course and that is indeed my plan :-) I just don't know 
the most maintainer-friendly and least error prone way.

Tuxedo



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

Date: Tue, 16 Sep 2014 14:56:38 +0200
From: gamo <gamo@telecable.es>
Subject: Re: Debugging help
Message-Id: <lv9c2n$co8$1@speranza.aioe.org>

El 16/09/14 a las 10:54, Tuxedo escribió:
> # .... and thousands of more entries between
> 'strawberry' => 'cream');
>
> When running I get the error: 'Odd number of elements in hash assignment at
> ./script.pl line n'.

I suggest to write a script that

1. select only lines with =>
a) have a odd number of ' chars
b) have a missing , at the end
and print out that lines.

(untested)

while (<>){
	next unless /\=\>/;
	$ok = 0;
	$ok++ unless (() = /\'/g) % 4 ==0;
	$ok++ unless /\,$/;
	print if $ok;
}	

HTH

-- 
http://www.telecable.es/personales/gamo/


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

Date: Tue, 16 Sep 2014 14:29:32 +0000 (UTC)
From: "David Canzi" <dmcanzi@uwaterloo.ca>
Subject: Re: Debugging help
Message-Id: <lv9hgc$trg$1@rumours.uwaterloo.ca>

Tuxedo  <tuxedo@mailinator.com> wrote:
>Hello,
>
>I have a hash like this:
>
>#!/usr/bin/perl -w
>
>use Tie::IxHash;
>use strict;
>use warnings;
>
>my $obj_list = tie my %list, "Tie::IxHash";
>
>%list =  ('coco' => 'cake',
>'mango' => 'chutney',
>'fish' => 'soup',
># .... and thousands of more entries between
>'strawberry' => 'cream');
>
>When running I get the error: 'Odd number of elements in hash assignment at 
>./script.pl line n'.

I've had this happen to me before when one of the lines in the hash
assignment that should have ended with a comma actually ended with
a period.  If you find one of those lines that ends with a period,
look for others, because it's a long list and the same typo might
have happened more than once.

-- 
David Canzi				| Eternal truths come and go. |


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

Date: Tue, 16 Sep 2014 07:52:22 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Debugging help
Message-Id: <kjig1atsf9clo873p3oifiedi8apulgcsn@4ax.com>

Tuxedo <tuxedo@mailinator.com> wrote:
>Hello,
>
>I have a hash like this:
>
>#!/usr/bin/perl -w
>
>use Tie::IxHash;
>use strict;
>use warnings;
>
>my $obj_list = tie my %list, "Tie::IxHash";
>
>%list =  ('coco' => 'cake',
>'mango' => 'chutney',
>'fish' => 'soup',
># .... and thousands of more entries between

This is prbably be the best way to define such a large data set.
You may want to consider a database or a text-based file which is read
and syntax checked/analysed line by line.

>'strawberry' => 'cream');
>
>When running I get the error: 'Odd number of elements in hash assignment at 
>./script.pl line n'.
>
>With 'line n' I mean the number of the first line of the %list is returned, 
>i.e. where 'coco' => 'cake', is.
>
>So I have a simple syntax error somewhere in the list, just a typing error, 
>but it's not on the line indicated and I cannot easily go through the whole 
>list to search for the error visually because it contains several thousand 
>lines. In other words, the shell does not indicate exactly where the error 
>occurrs, it only points to the beginning of the list.
>
>Can anyone can advise on a good procedure to check the syntax to highlight 
>where the problem line(s) occur? Each pair is on a line by itself, e.g.:
>'mango' => 'chutney',

Use an editor with syntax highlighting. This should at least quickly
tell you if there is a quote character missing somewhere.

Write a one-liner which counts the number of quote characters per line
and points out any line that has less (or more) than 4.
Write a one-liner to check if each line has a => and has a comma at the
end.
Write a one-liner to remove any text between the matching pairs of quote
characters. If afterwards any text other then => and the comma is left
that should stick out like a sore thumb, even if then you have to go by
line number because there is no other reference left.

Use bisection to reduce the possible number of lines containing the
error. Even with thousands of lines you will need only 10-13 iterations.

And most important: for the future use a better data storage format

jue


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

Date: Tue, 16 Sep 2014 07:56:59 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Debugging help
Message-Id: <mqjg1attach563vlc6o34ta74bsmikuk31@4ax.com>

Jürgen Exner <jurgenex@hotmail.com> wrote:
>Tuxedo <tuxedo@mailinator.com> wrote:
>>%list =  ('coco' => 'cake',
>>'mango' => 'chutney',
>>'fish' => 'soup',
>># .... and thousands of more entries between
>

>This is prbably be the best way to define such a large data set.

Somehow this sentence got scrambled . I meant
"This is probably not the best way to define such a large data set."

jue


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

Date: Tue, 16 Sep 2014 15:31:31 +0100
From: Justin C <justin.1401@purestblue.com>
Subject: Re: Debugging help
Message-Id: <37uleb-2bs.ln1@zem.masonsmusic.co.uk>

On 2014-09-16, gamo <gamo@telecable.es> wrote:
> El 16/09/14 a las 10:54, Tuxedo escribió:
>> # .... and thousands of more entries between
>> 'strawberry' => 'cream');
>>
>> When running I get the error: 'Odd number of elements in hash assignment at
>> ./script.pl line n'.
>
> I suggest to write a script that
>
> 1. select only lines with =>
> a) have a odd number of ' chars
> b) have a missing , at the end
> and print out that lines.
>
> (untested)
>
> while (<>){
> 	next unless /\=\>/;
> 	$ok = 0;
> 	$ok++ unless (() = /\'/g) % 4 ==0;

You don't need to quote keys if they're valid variable names, so some
lines may have only quotes around the values. You can change the '% 4'
to '% 2' and be no worse off, and this will ignore those where the keys
have not been (and need not be) quoted.

   Justin.

-- 
Justin C, by the sea.


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

Date: Tue, 16 Sep 2014 08:20:54 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Debugging help
Message-Id: <dqkg1atvp0jc49n38khtu7dh7dmuepocgo@4ax.com>

Justin C <justin.1401@purestblue.com> wrote:
>On 2014-09-16, gamo <gamo@telecable.es> wrote:
>> El 16/09/14 a las 10:54, Tuxedo escribió:
>>> # .... and thousands of more entries between
>>> 'strawberry' => 'cream');
>>>
>>> When running I get the error: 'Odd number of elements in hash assignment at
>>> ./script.pl line n'.
>
>You don't need to quote keys if they're valid variable names, so some
>lines may have only quotes around the values. 

Although technically you are right if _he_ expects the keys to be
enclosed in quotes then he should check if the keys are enclosed in
quotes, even if Perl doesn't care. 

>You can change the '% 4'
>to '% 2' and be no worse off, and this will ignore those where the keys
>have not been (and need not be) quoted.

And it will also ignore lines where the value has not been quoted (but
needs to be quoted) or where there is some other quote mismatch.

It is always easier to deal with false positives than with false
negatives. So use the most restrictive check, not the most lenient
check..

jue


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

Date: Tue, 16 Sep 2014 16:43:45 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Debugging help
Message-Id: <8761gnin9q.fsf@sable.mobileactivedefense.com>

Tuxedo <tuxedo@mailinator.com> writes:
> Hello,
>
> I have a hash like this:
>
> #!/usr/bin/perl -w
>
> use Tie::IxHash;
> use strict;
> use warnings;
>
> my $obj_list = tie my %list, "Tie::IxHash";
>
> %list =  ('coco' => 'cake',
> 'mango' => 'chutney',
> 'fish' => 'soup',
> # .... and thousands of more entries between
> 'strawberry' => 'cream');

If you really have each entry on a line of its own, you could save them
all to a text file and do a

grep -v ',$'

to search for a line which doesn't end with a comma. Or use something
like (assuming the file is called 'a')


tr -d '\n' <a | sed 's/=>\|,/\n/g'

and look for an output line containing more than two apostrophes.




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

Date: Tue, 16 Sep 2014 08:59:12 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Debugging help
Message-Id: <b4ng1a97lfdhjpgqbkb4h7vbbglsgsl11i@4ax.com>

Jürgen Exner <jurgenex@hotmail.com> wrote:
>Tuxedo <tuxedo@mailinator.com> wrote:
>>I have a hash like this:
>>
>>%list =  ('coco' => 'cake',
>>'mango' => 'chutney',
>>'fish' => 'soup',
>># .... and thousands of more entries between
>>'strawberry' => 'cream');
>>
>>When running I get the error: 'Odd number of elements in hash assignment at 
>>./script.pl line n'.
>>
>>So I have a simple syntax error somewhere in the list, just a typing error, 
>>
>>Can anyone can advise on a good procedure to check the syntax to highlight 
>>where the problem line(s) occur? Each pair is on a line by itself, e.g.:
>>'mango' => 'chutney',

Coming to think of it, if your data is really structured this regularly
then I would probably use something like (untested)
	print unless /^\s*'\w*'\s*=>\s*'\w*',\s*$/
to isolate the bad line(s).
If this yields too many false positives e.g. because your keys or values
contain space characters then you have to refine the RE.

jue


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

Date: Tue, 16 Sep 2014 18:16:02 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Debugging help
Message-Id: <lv9up2$9gd$1@reader1.panix.com>

In article <lv8trj$en4$1@news.albasani.net>,
Tuxedo  <tuxedo@mailinator.com> wrote:
>my $obj_list = tie my %list, "Tie::IxHash";
>
>%list =  ('coco' => 'cake',
>'mango' => 'chutney',
>'fish' => 'soup',
># .... and thousands of more entries between
>'strawberry' => 'cream');

The suggestions to grep the source sound good to me.  Failing that, or
to avert future problems, maybe code something like this?

my @list = ();
sub addone($$) { return @_; }
push @list, addone('coco' => 'cake',);
push @list, addone('mango' => 'chutney',);
push @list, addone('fish' => 'soup',);
># .... and thousands of more entries between
push @list, addone('strawberry' => 'cream',);
%list = @list;

?

-- 
Tim McDaniel, tmcd@panix.com


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

Date: Tue, 16 Sep 2014 11:32:13 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Debugging help
Message-Id: <n90h1ahc0kf5r161viu6f97dk1pbt5kcje@4ax.com>

tmcd@panix.com (Tim McDaniel) wrote:
>In article <lv8trj$en4$1@news.albasani.net>,
>Tuxedo  <tuxedo@mailinator.com> wrote:
>>my $obj_list = tie my %list, "Tie::IxHash";
>>
>>%list =  ('coco' => 'cake',
>>'mango' => 'chutney',
>>'fish' => 'soup',
>># .... and thousands of more entries between
>>'strawberry' => 'cream');
>
>The suggestions to grep the source sound good to me.  Failing that, or
>to avert future problems, maybe code something like this?
>
>my @list = ();
>sub addone($$) { return @_; }
>push @list, addone('coco' => 'cake',);
>push @list, addone('mango' => 'chutney',);
>push @list, addone('fish' => 'soup',);

Is there anything wrong with the much simpler 
	$list{'coco'} = 'cake';
	$list{'mango'} = 'chutney';
	$list{'fish'} = 'soup';
instead?

>># .... and thousands of more entries between
>push @list, addone('strawberry' => 'cream',);
>%list = @list;

 ....and then of course no need for the temporary array or the array to
hash conversion, either.

jue


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

Date: Wed, 17 Sep 2014 08:47:04 +0100
From: Justin C <justin.1401@purestblue.com>
Subject: Re: Debugging help
Message-Id: <osqneb-a6v.ln1@zem.masonsmusic.co.uk>

On 2014-09-16, Jürgen Exner <jurgenex@hotmail.com> wrote:
> Justin C <justin.1401@purestblue.com> wrote:
>>On 2014-09-16, gamo <gamo@telecable.es> wrote:
>>> El 16/09/14 a las 10:54, Tuxedo escribió:
>>>> # .... and thousands of more entries between
>>>> 'strawberry' => 'cream');
>>>>
>>>> When running I get the error: 'Odd number of elements in hash assignment at
>>>> ./script.pl line n'.
>>
>>You don't need to quote keys if they're valid variable names, so some
>>lines may have only quotes around the values. 
>
> Although technically you are right if _he_ expects the keys to be
> enclosed in quotes then he should check if the keys are enclosed in
> quotes, even if Perl doesn't care. 
>
>>You can change the '% 4'
>>to '% 2' and be no worse off, and this will ignore those where the keys
>>have not been (and need not be) quoted.
>
> And it will also ignore lines where the value has not been quoted (but
> needs to be quoted) or where there is some other quote mismatch.

In my tests I found that the errors you mention would throw syntax
or other compile time errors. These would, of course, mention the 
same line number for the error and therefore be no more helpful.


> It is always easier to deal with false positives than with false
> negatives. So use the most restrictive check, not the most lenient
> check..

Yes, on consideration, I concur.


   Justin.

-- 
Justin C, by the sea.


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

Date: Wed, 17 Sep 2014 15:58:22 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Debugging help
Message-Id: <lvcb2t$8nm$1@reader1.panix.com>

In article <n90h1ahc0kf5r161viu6f97dk1pbt5kcje@4ax.com>,
J_rgen Exner  <jurgenex@hotmail.com> wrote:
>tmcd@panix.com (Tim McDaniel) wrote:
>>In article <lv8trj$en4$1@news.albasani.net>,
>>Tuxedo  <tuxedo@mailinator.com> wrote:
>>>my $obj_list = tie my %list, "Tie::IxHash";
>>>
>>>%list =  ('coco' => 'cake',
>>>'mango' => 'chutney',
>>>'fish' => 'soup',
>>># .... and thousands of more entries between
>>>'strawberry' => 'cream');
>>
>>The suggestions to grep the source sound good to me.  Failing that, or
>>to avert future problems, maybe code something like this?
>>
>>my @list = ();
>>sub addone($$) { return @_; }
>>push @list, addone('coco' => 'cake',);
>>push @list, addone('mango' => 'chutney',);
>>push @list, addone('fish' => 'soup',);
>
>Is there anything wrong with the much simpler 
>	$list{'coco'} = 'cake';
>	$list{'mango'} = 'chutney';
>	$list{'fish'} = 'soup';
>instead?

I blush, for I didn't think of it.

There could be a slight difference.  I had a similar problem recently
where I left out one value (as a placeholder) but it was valid syntax.
If the placeholder here were

    $list{'rum'};

then there'd be an undetected problem, but one should do

    $list{'rum'} = ;

and get the same syntax benefit as addone($$).  If that were done,
then yes,
    $list{'rum'} = 'cola';
is indeed far superior (unless you also want to do other processing,
logging, checking, whatever, of course).

-- 
Tim McDaniel, tmcd@panix.com


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

Date: Wed, 17 Sep 2014 17:39:37 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Debugging help
Message-Id: <878ulii4l2.fsf@sable.mobileactivedefense.com>

tmcd@panix.com (Tim McDaniel) writes:
> In article <n90h1ahc0kf5r161viu6f97dk1pbt5kcje@4ax.com>,
> J_rgen Exner  <jurgenex@hotmail.com> wrote:
>>tmcd@panix.com (Tim McDaniel) wrote:
>>>In article <lv8trj$en4$1@news.albasani.net>,
>>>Tuxedo  <tuxedo@mailinator.com> wrote:
>>>>my $obj_list = tie my %list, "Tie::IxHash";
>>>>
>>>>%list =  ('coco' => 'cake',
>>>>'mango' => 'chutney',
>>>>'fish' => 'soup',
>>>># .... and thousands of more entries between
>>>>'strawberry' => 'cream');
>>>
>>>The suggestions to grep the source sound good to me.  Failing that, or
>>>to avert future problems, maybe code something like this?
>>>
>>>my @list = ();
>>>sub addone($$) { return @_; }
>>>push @list, addone('coco' => 'cake',);
>>>push @list, addone('mango' => 'chutney',);
>>>push @list, addone('fish' => 'soup',);
>>
>>Is there anything wrong with the much simpler 
>>	$list{'coco'} = 'cake';
>>	$list{'mango'} = 'chutney';
>>	$list{'fish'} = 'soup';
>>instead?
>
> I blush, for I didn't think of it.

What's wrong with both of them: A lot of uselessly repeated text for no
real benefit.

Another way to verify the 'well-formedness' of the hash contents:

perl -ne '/^(\s*\S+\s*=>\s*\S+\s*,\s*)+$/ or print'

[...]

>     $list{'rum'} = 'cola';
> is indeed far superior

Don't try to tell this to someone who ordered rum :-).


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

Date: Wed, 17 Sep 2014 09:51:29 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Debugging help
Message-Id: <hmej1a5uoaspqesl3k3bmkl35se5mfnjgl@4ax.com>

Rainer Weikusat <rweikusat@mobileactivedefense.com> wrote:
>tmcd@panix.com (Tim McDaniel) writes:
>> In article <n90h1ahc0kf5r161viu6f97dk1pbt5kcje@4ax.com>,
>> J_rgen Exner  <jurgenex@hotmail.com> wrote:
>>>tmcd@panix.com (Tim McDaniel) wrote:
>>>>In article <lv8trj$en4$1@news.albasani.net>,
>>>>Tuxedo  <tuxedo@mailinator.com> wrote:
>>>>>my $obj_list = tie my %list, "Tie::IxHash";
>>>>>
>>>>>%list =  ('coco' => 'cake',
>>>>>'mango' => 'chutney',
>>>>>'fish' => 'soup',
>>>>># .... and thousands of more entries between
>>>>>'strawberry' => 'cream');
>>>>
>>>>The suggestions to grep the source sound good to me.  Failing that, or
>>>>to avert future problems, maybe code something like this?
>>>>
>>>>my @list = ();
>>>>sub addone($$) { return @_; }
>>>>push @list, addone('coco' => 'cake',);
>>>>push @list, addone('mango' => 'chutney',);
>>>>push @list, addone('fish' => 'soup',);
>>>
>>>Is there anything wrong with the much simpler 
>>>	$list{'coco'} = 'cake';
>>>	$list{'mango'} = 'chutney';
>>>	$list{'fish'} = 'soup';
>>>instead?
>>
>> I blush, for I didn't think of it.
>
>What's wrong with both of them: A lot of uselessly repeated text for no
>real benefit.

Well, the real drawback is that the hash (or in the other version the
array) is constructed incrementally, i.e. you are adding thousands of
items one by one with all the known drawbacks of increasing the size of
the hash/array again and again and again.
But it does give you the benefit that in case of a typo it will point
you exactly to the right line and that's what the OP was asking for.

>Another way to verify the 'well-formedness' of the hash contents:
>
>perl -ne '/^(\s*\S+\s*=>\s*\S+\s*,\s*)+$/ or print'

I think I wrote something very similar yesterday

jue


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

Date: Mon, 15 Sep 2014 18:44:38 +0200
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: Devel::Peek's character count (or bytes, maybe?)
Message-Id: <lv751n$fso$1@dont-email.me>

On 12.09.14 21:59, Rainer Weikusat wrote:
> "G.B." <bauhaus@futureapps.invalid> writes:
>> starting here, looking for CUR:
>>
>> $ perl -w -e 'use Devel::Peek; $a = "\x{20AC}"; Dump($a);'
>> SV = PV(0x7fe8f2003080) at 0x7fe8f202ddd8
>>    REFCNT = 1
>>    FLAGS = (POK,pPOK,UTF8)
>>    PV = 0x7fe8f1c0d980 "\342\202\254"\0 [UTF8 "\x{20ac}"]
>>    CUR = 3
>>    LEN = 16
>>
>> just to make sure, see the same for two occurrences of "\x{20AC}"
>>
>> $ perl -w -e 'use Devel::Peek; $a = "\x{20AC}\x{20AC}"; Dump($a);'
>> SV = PV(0x7fe883003080) at 0x7fe88302ddd8
>>    REFCNT = 1
>>    FLAGS = (POK,pPOK,UTF8)
>>    PV = 0x7fe882c0d980 "\342\202\254\342\202\254"\0 [UTF8
>> "\x{20ac}\x{20ac}"]
>>    CUR = 6
>>    LEN = 16
>>
>> Is CUR the number of bytes as opposed to Perl characters, currently
>> present in ${a}'s PV up to \0?
>
> CUR is the actual length of the SVPV (scalar holding a string) and LEN
> is the size of the currently allocated char array. perl always keeps a
> trailing 0 at the end of any string.
>

That's a C array of C char components, then, judging by looking at
all the names containing S/vpv/i, and duly noting "bytes of storage
allocated", I gather.



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

Date: Mon, 15 Sep 2014 18:53:38 +0200
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: Devel::Peek's character count (or bytes, maybe?)
Message-Id: <lv75ij$jr5$1@dont-email.me>

On 13.09.14 19:56, Peter J. Holzer wrote:
> On 2014-09-12 19:41, G.B. <bauhaus@futureapps.invalid> wrote:
>> $ perl -w -e 'use Devel::Peek; $a = "\x{20AC}"; Dump($a);'
>> SV = PV(0x7fe8f2003080) at 0x7fe8f202ddd8
>>     REFCNT = 1
>>     FLAGS = (POK,pPOK,UTF8)
>>     PV = 0x7fe8f1c0d980 "\342\202\254"\0 [UTF8 "\x{20ac}"]
>>     CUR = 3
>>     LEN = 16
> [...]
>> Is CUR the number of bytes as opposed to Perl characters, currently
>> present in ${a}'s PV up to \0?
>
> Yes.
>
>> (The docs say "characters" for CUR,
>> do they mean C characters?)
>
> Probably. Or "the docs" (you don't say which docs) haven't been updated
> since 5.005.

In Devel::Peek, EXAMPLES
"CUR indicates the number of characters in the PV.
  LEN indicates the number of bytes requested for the PV
  (one more than CUR, in this case, because LEN includes
  an extra byte for the end-of-string marker)."

The latter sentence happens to be true about "hello"\0 of
the example (CUR=5, LEN=8), then, since the string (C or Perl)
has only characters whose ord number is < 128 (and there is
no offset).



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

Date: Mon, 15 Sep 2014 21:48:18 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: Devel::Peek's character count (or bytes, maybe?)
Message-Id: <slrnm1egk2.ekf.hjp-usenet3@hrunkner.hjp.at>

On 2014-09-15 16:53, G.B. <bauhaus@futureapps.invalid> wrote:
> On 13.09.14 19:56, Peter J. Holzer wrote:
>> On 2014-09-12 19:41, G.B. <bauhaus@futureapps.invalid> wrote:
>>> $ perl -w -e 'use Devel::Peek; $a = "\x{20AC}"; Dump($a);'
>>> SV = PV(0x7fe8f2003080) at 0x7fe8f202ddd8
>>>     REFCNT = 1
>>>     FLAGS = (POK,pPOK,UTF8)
>>>     PV = 0x7fe8f1c0d980 "\342\202\254"\0 [UTF8 "\x{20ac}"]
>>>     CUR = 3
>>>     LEN = 16
>> [...]
>>> Is CUR the number of bytes as opposed to Perl characters, currently
>>> present in ${a}'s PV up to \0?
>>
>> Yes.
>>
>>> (The docs say "characters" for CUR,
>>> do they mean C characters?)
>>
>> Probably. Or "the docs" (you don't say which docs) haven't been updated
>> since 5.005.
>
> In Devel::Peek, EXAMPLES
> "CUR indicates the number of characters in the PV.
>   LEN indicates the number of bytes requested for the PV
>   (one more than CUR, in this case, because LEN includes
>   an extra byte for the end-of-string marker)."

The first sentence has been unchanged since at least 5.8.0 (the oldest
version of perl I still use). There is a good chance that it originated
before Perl started to distinguish between bytes and characters. The
latter sentence has been edited slightly.

        hp


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

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


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