RE: question on Perl determinism with hash keys

2006-05-16 Thread Gavin Bowlby
My program is a simulator for a scripting language that is multi-threaded, although the Perl program itself is single-threaded. The simulator is a mini-OS with threads that are dynamically created, executed, and destroyed. I use hashes to track the internal states of the threads, their variables,

Re: Storable error - Magic number checking on storable file failed

2006-05-16 Thread Tom Phoenix
On 5/14/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: "Magic number checking on storable file failed at blib/lib/Storable.pm That sounds as if the input wasn't a valid Storable file. Could it be some other file format? Was it written by Storable on your machine? Good luck with it! --Tom P

Re: using "our" across blocks

2006-05-16 Thread M. Kristall
Oops, ignore the contradictions in my first message. The code shows what I meant where the words are misleading (or just plain wrong). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: using "our" across blocks

2006-05-16 Thread M. Kristall
Anthony Ettinger wrote: I want to double-check that it is correct to use "our" to import globals. #!/usr/bin/perl -w use strict; BEGIN { our $foo = 'foo'; } sub something { our $foo; our $bar; ...at this point I can see 'foo' and 'bar' values. } END { our $bar = 'bar'; } [snip

RE: question on Perl determinism with hash keys

2006-05-16 Thread Timothy Johnson
Understandable. Why do you need the keys function to return the keys in the same order? What is it that you're trying to do? -Original Message- From: Gavin Bowlby [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 5:57 PM To: Timothy Johnson; beginners@perl.org Subject: RE: questio

RE: question on Perl determinism with hash keys

2006-05-16 Thread Gavin Bowlby
I don't want to do this sorting because I have many hashes within my Perl program that are changing at a high rate, and I'm trying to optimize performance within my Perl program. -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 5:47 PM To: Gav

RE: question on Perl determinism with hash keys

2006-05-16 Thread Timothy Johnson
I personally have never felt the need. One thing I'll often do is a foreach(sort keys %hash){ #do something... } If you know what the keys are going to be ahead of time that might work for you. -Original Message- From: Gavin Bowlby [mailto:[EMAIL PROTEC

Re: question on Perl determinism with hash keys

2006-05-16 Thread John W. Krahn
Gavin Bowlby wrote: > All: Hello, > If I populate a %hash within a Perl program, is there any guarantee that > from run to run of the same Perl program the keys(%hash) function will > return identical sets of keys? Can I assume that you are worried about the order of the keys? Do you want the k

RE: question on Perl determinism with hash keys

2006-05-16 Thread Gavin Bowlby
Timothy et al: Thanks, I did mean in the same order. Any idea on the relative performance of a hash tied to IxHash vs. a vanilla hash? I have a Perl program with many hashes whose entries are created and destroyed at a high rate, and I'm wondering if I can expect a performance hit if I make this

RE: question on Perl determinism with hash keys

2006-05-16 Thread Timothy Johnson
If you mean in the same order, then no. perldoc -q order -Original Message- From: Gavin Bowlby [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 5:25 PM To: beginners@perl.org Subject: question on Perl determinism with hash keys All: If I populate a %hash within a Perl program,

question on Perl determinism with hash keys

2006-05-16 Thread Gavin Bowlby
All: If I populate a %hash within a Perl program, is there any guarantee that from run to run of the same Perl program the keys(%hash) function will return identical sets of keys? thanks for any insights on this, Gavin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail

getter setter and database

2006-05-16 Thread Ken Perl
suppose I have a table person with following columns, name, age, salary. If use OOP to write a class like this, package Person; sub new{ $class=shift; my $self = {}; $self->{_name} = undef; $self->{_age} = undef; $self->{_salary}= undef; bless ($self,$class); return $self; }

RE: hash assign not working

2006-05-16 Thread Smith, Derek
From: Wagner, David --- Senior Programmer Analyst --- WGO [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 2:06 PM To: Smith, Derek; beginners@perl.org Subject: RE: hash assign not working Smith, Derek wrote: > My hash creations are not working as I expected: %hash = ( @mir, > @mir2 ); >

RE: reading a line at a time inefficient?

2006-05-16 Thread Bliss, Kevin
>I figured the OS would load the file in blocks, but I thought the blocks >might only be 12k or something like that. >I am surprised at the levels of concern over memory reading in <20 MB files. >Don't most people have 1+ GB now? I've got 2... I'm just surprised that >using at most 1% of my to

Re: reading a line at a time inefficient?

2006-05-16 Thread Chad Perrin
On Tue, May 16, 2006 at 11:54:58AM -0700, Bryan R Harris wrote: > > I figured the OS would load the file in blocks, but I thought the blocks > might only be 12k or something like that. > > I am surprised at the levels of concern over memory reading in <20 MB files. > Don't most people have 1+ GB

Re: reading a line at a time inefficient?

2006-05-16 Thread Bryan R Harris
> Bryan Harris schreef: > >> If I'm reading in many-megabyte files, is it considered to be more >> efficient to read it into an array, then loop over the array? > > Line-by-line is fine. > > Your Operating System will read from disk in blocks, so stop believing > that each line needs a disk ac

RE: hash assign not working

2006-05-16 Thread Charles K. Clarkson
Charles K. Clarkson wrote: : It does not handle them special just because : there's a hash on the right hand side. Whoopsie! Should be left hand side not right. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: hash assign not working

2006-05-16 Thread Paul Johnson
On Tue, May 16, 2006 at 11:06:02AM -0700, Wagner, David --- Senior Programmer Analyst --- WGO wrote: > while ( @mir ) { > $hash{shift(@mir)} = shift(@mir2); > } @[EMAIL PROTECTED] = @mir2; -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mai

RE: hash assign not working

2006-05-16 Thread Charles K. Clarkson
Wagner, David --- Senior Programmer Analyst --- WGO wrote: : while ( @mir ) { : $hash{shift(@mir)} = shift(@mir2); :} We can also use a hash slice. my %hash; @[EMAIL PROTECTED] = @mir2; HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Pr

RE: hash assign not working

2006-05-16 Thread Charles K. Clarkson
Smith, Derek wrote: : My hash creations are not working as I expected: %hash = ( @mir, : @mir2 ); : : Why? Because nothing magical happens on the right hand side of the assignment. If I have a series of arrays over there perl flattens them into one list. It does not handle them special just

Re: hash assign not working

2006-05-16 Thread Tom Phoenix
On 5/16/06, Smith, Derek <[EMAIL PROTECTED]> wrote: My hash creations are not working as I expected: %hash = ( @mir, @mir2 ); Why? Probably because that expression isn't a list of key-value pairs. If you're collecting @mir (a list of keys?) and @mir2 (a list of corresponding values?), no won

RE: hash assign not working

2006-05-16 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Smith, Derek wrote: > My hash creations are not working as I expected: %hash = ( @mir, > @mir2 ); > > Why? > To populate a hash requires two fields: Key and data. What you are assuming is that it will take one from @mir and one from @mir2 which is a wrong assumption. Yes the second wor

hash assign not working

2006-05-16 Thread Smith, Derek
My hash creations are not working as I expected: %hash = ( @mir, @mir2 ); Why? But do work at %hash = ( $mir[0], $mir2[0] ); Obviously I need the entire arrays and their associated key/value pairs, and have tried various methods unsuccessfully from Programming Perl CD such as array of hashes

Re: reading a line at a time inefficient?

2006-05-16 Thread Dr.Ruud
Bryan Harris schreef: > If I'm reading in many-megabyte files, is it considered to be more > efficient to read it into an array, then loop over the array? Line-by-line is fine. Your Operating System will read from disk in blocks, so stop believing that each line needs a disk access. (unless each

Re: reading a line at a time inefficient?

2006-05-16 Thread Michael Goldshteyn
In a nutshell, use File::Slurp to read the entire file all at once. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: reading a line at a time inefficient?

2006-05-16 Thread Tom Phoenix
On 5/16/06, Bryan Harris <[EMAIL PROTECTED]> wrote: If I'm reading in many-megabyte files, is it considered to be more efficient to read it into an array, then loop over the array? Or is reading a line at a time okay? Processing a file one line at a time is always okay. I realize the second

RE: reading a line at a time inefficient?

2006-05-16 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Bryan Harris wrote: > If I'm reading in many-megabyte files, is it considered to be more > efficient to read it into an array, then loop over the array? Or is > reading a line at a time okay? > Depends really on the size and what you trying to do. Almost all that I do, I read a line at t

reading a line at a time inefficient?

2006-05-16 Thread Bryan Harris
If I'm reading in many-megabyte files, is it considered to be more efficient to read it into an array, then loop over the array? Or is reading a line at a time okay? e.g. ** while (<>) { # do some process with each line } **

RE: hash assignments

2006-05-16 Thread Smith, Derek
> > foreach my $lv (@lvs) { > > push @mir => (grep /mirror/i, `lvdisplay $lv`); > > push @mir2 => (grep /lvol\d+/i, `lvdisplay $lv`); > Try replacing the above line with > push @mir2 => (grep s/^LV Name\s*//, `lvdisplay $lv`); > Or > push @mir2 => (grep {/lvol\d

Re: not forking

2006-05-16 Thread Tom Allison
Paul Johnson wrote: On Mon, May 15, 2006 at 04:46:07PM -0400, Tom Allison wrote: I've got a *bunch* of code that I've been rewriting recently and ran into a rather weird problem. it won't fork. If I write the following: foreach my $file ( @$files ) { my $pid = fork(); print "$pid --> $fil

Re: format output from Data::Dumper

2006-05-16 Thread Mr. Shawn H. Corey
On Mon, 2006-15-05 at 17:46 -0700, chen li wrote: > Hi all, > > I get data from Data::Dumper in an array format. > I just wonder if there is a means to format the > content in alphabetic order, something like "sort keys > or sort values". Data::Dumper can output hashes sorted by keys: $Data::D

RE: format output from Data::Dumper

2006-05-16 Thread chen li
Hi all, I use the following script to find out the methods available from a class of Bio::Seq. #!c:/Perl/bin/Perl.exe use warnings; use strict; use Bio::Seq; use Data::Dumper; use Class::Inspector; my $methods=Class::Inspector->methods('Bio::Seq', 'full','public'); print Data::Dumper->Dump([$m

Re: format output from Data::Dumper

2006-05-16 Thread Dr.Ruud
Jeff Pang schreef: > print Dumper @sort; I always go for the whole thing: print Data:Dumper->Dump( [EMAIL PROTECTED], [qw(*sort)] ); perl -MData::Dumper -e ' @s = sort( 1, 7, 3, 2, 5 ) ; print Data::Dumper->Dump( [ [EMAIL PROTECTED] ], [ qw(*s) ] ) ' @s = ( 1, 2, 3,