From joshlanza at hotmail.com Tue Feb 3 15:39:02 2004 From: joshlanza at hotmail.com (Joshua Lanza) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: @INC on Windows Message-ID: Anyone know how to permanently add a path to @INC on Windows? The reason I'm not using perl/lib or perl/site/lib is because I'd like to keep custom modules separate from the standard ActiveState install. Thanks, Josh From ced at carios2.ca.boeing.com Tue Feb 3 17:07:59 2004 From: ced at carios2.ca.boeing.com (ced@carios2.ca.boeing.com) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: @INC on Windows Message-ID: <200402032307.PAA12080@carios2.ca.boeing.com> > Anyone know how to permanently add a path to @INC on Windows? The reason I'm > not using perl/lib or perl/site/lib is because I'd like to keep custom > modules separate from the standard ActiveState install. Need a rebuild to add permanently... however there are various ways to add other directories on the fly. From perlfa8: How do I add a directory to my include path at runtime? Here are the suggested ways of modifying your include path: the PERLLIB environment variable the PERL5LIB environment variable the perl -Idir command line flag the use lib pragma, as in use lib "$ENV{HOME}/myown_perllib"; The latter is particularly useful because it knows about machine dependent architectures. The lib.pm pragmatic module was first included with the 5.002 release of Perl. hth, -- Charles DeRykus From joshlanza at hotmail.com Tue Feb 3 20:03:53 2004 From: joshlanza at hotmail.com (Joshua Lanza) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: @INC on Windows References: <200402032307.PAA12080@carios2.ca.boeing.com> Message-ID: Thanks (all) for the responses. I was afraid this might require a rebuild. I'll stick to "use lib" ... Josh ----- Original Message ----- From: To: ; Sent: Tuesday, February 03, 2004 3:07 PM Subject: Re: SPUG: @INC on Windows > > Anyone know how to permanently add a path to @INC on Windows? The reason I'm > > not using perl/lib or perl/site/lib is because I'd like to keep custom > > modules separate from the standard ActiveState install. > > Need a rebuild to add permanently... however there are various > ways to add other directories on the fly. From perlfa8: > > How do I add a directory to my include path at runtime? > > Here are the suggested ways of modifying your include path: > > the PERLLIB environment variable > the PERL5LIB environment variable > the perl -Idir command line flag > the use lib pragma, as in > use lib "$ENV{HOME}/myown_perllib"; > > The latter is particularly useful because it knows about > machine dependent architectures. The lib.pm pragmatic > module was first included with the 5.002 release of Perl. > > > > hth, > -- > Charles DeRykus > From MichaelRWolf at att.net Tue Feb 3 20:10:40 2004 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: The string name of a variable (or any identifier) In-Reply-To: (David Dyck's message of "Wed, 28 Jan 2004 10:10:07 -0800 (PST)") References: Message-ID: David Dyck writes: [...] > use B::Deparse; > my $deparse = B::Deparse->new("-p", "-sC"); [...] > foreach (@stuff_to_debug) { > printf "%s %d\n", $_, eval $_; Inside out -- outside in. Thanks for the two perspectives. -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From wnorth at state.mt.us Wed Feb 4 09:01:12 2004 From: wnorth at state.mt.us (North, Walter) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: Array Naming Question Message-ID: Good Morning all, Maybe this is a dumb question, but here goes anyway: Does anyone know if it possible to include a variable in, or use a variable as the name of an array or hash, and if so how would one do it? thanks in advance. ----------------------------------------------------- Walter North 406-444-2914 Operating Systems Programmer wnorth (at) state (dot) mt (dot) us ----------------------------------------------------- From brianmaddux at yahoo.com Wed Feb 4 09:33:17 2004 From: brianmaddux at yahoo.com (Brian Maddux) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: Array Naming Question In-Reply-To: Message-ID: <20040204153317.90431.qmail@web40201.mail.yahoo.com> Here's a quick program I used to test what I think you are asking for: ------- #!/usr/bin/perl -w @test_array = (1,2,3,4,5); @other_test_array = (9,8,7,6,5,4,3,2,1); print "Normal: ".join(",", @test_array)."\n"; $array_name = "test_array"; print "By Name ($array_name): ".join(",", @{$array_name})."\n"; $array_name = "other_test_array"; print "By Name ($array_name): ".join(",", @{$array_name})."\n"; ------- And here's the output: $ /usr/bin/perl test.pl Name "main::other_test_array" used only once: possible typo at test.pl line 4. Normal: 1,2,3,4,5 By Name (test_array): 1,2,3,4,5 By Name (other_test_array): 9,8,7,6,5,4,3,2,1 I hope this answers your question. Brian Maddux --- "North, Walter" wrote: > > Good Morning all, > > Maybe this is a dumb question, but here goes anyway: > > Does anyone know if it possible to include a > variable in, or use a variable > as > the name of an array or hash, and if so how would > one do it? > > thanks in advance. > > > ----------------------------------------------------- > > Walter North 406-444-2914 > Operating Systems Programmer > wnorth (at) state (dot) mt (dot) us > ----------------------------------------------------- > > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org > http://spugwiki.perlocity.org > ACCOUNT CONFIG: > http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > ===== ------------------------------------------------------- Brian Maddux Whidbey Island, WA brianmaddux@yahoo.com ------------------------------------------------------- __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! http://webhosting.yahoo.com/ps/sb/ From kahn at cpan.org Wed Feb 4 09:52:40 2004 From: kahn at cpan.org (Jeremy G Kahn) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: Array Naming Question In-Reply-To: References: Message-ID: <40211548.5020002@cpan.org> This is a good question, and a FAQ if you know where to look. The FAQ has an explanation for how you might want to go about doing this, and why it's probably a bad idea, and some suggestions for alternatives: perldoc -q 'variable name': Found in /usr/share/perl/5.8.2/pod/perlfaq7.pod How can I use a variable as a variable name? Beginners often think they want to have a variable contain the name of a variable. $fred = 23; $varname = "fred"; ++$$varname; # $fred now 24 This works sometimes, but it is a very bad idea for two reasons. The first reason is that this technique only works on global variables. That means that if $fred is a lexical variable created with my() in the above example, the code wouldn't work at all: you'd ... Hope that's useful. --jeremy North, Walter wrote: >Good Morning all, > >Maybe this is a dumb question, but here goes anyway: > >Does anyone know if it possible to include a variable in, or use a variable >as >the name of an array or hash, and if so how would one do it? > >thanks in advance. > > >----------------------------------------------------- >Walter North 406-444-2914 >Operating Systems Programmer >wnorth (at) state (dot) mt (dot) us >----------------------------------------------------- > >_____________________________________________________________ >Seattle Perl Users Group Mailing List >POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org >ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list >MEETINGS: 3rd Tuesdays, U-District, Seattle WA >WEB PAGE: http://www.seattleperl.org > > > From christopher.w.cantrall at boeing.com Wed Feb 4 10:13:09 2004 From: christopher.w.cantrall at boeing.com (Cantrall, Christopher W) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: Array Naming Question Message-ID: Also, MJD has an article on this subject. http://perl.plover.com/varvarname.html BeginQuote The real root of the problem code is: It's fragile. You're mingling unlike things when you do this. And if two of those unlike things happen to have the same name, they'll collide and you'll get the wrong answer. So you end up having a whole long list of names which you have to be careful not to reuse, and if you screw up, you get a very bizarre error. This is precisely the problem that namespaces were invented to solve, and that's just what a hash is: A portable namespace. ... The real problem is that if your string contains something unexpected, it will sabotage a totally unrelated part of the program, and then you will have one hell of a time figuring out the bug. EndQuote MJD has 3 articles on this. Quite interesting. HTH ____________________________________________ Chris Cantrall, Structural Engineer, 777 Christopher.W.Cantrall@Boeing.com chris@cantrall.org http://perlmonks.org/index.pl?node=Louis_Wu http://spugwiki.perlocity.org/index.cgi?LouisWu > -----Original Message----- > From: Jeremy G Kahn [mailto:kahn@cpan.org] > Sent: Wednesday, February 04, 2004 7:53 AM > To: North, Walter > Cc: spug > Subject: Re: SPUG: Array Naming Question > > > This is a good question, and a FAQ if you know where to look. The FAQ > has an explanation for how you might want to go about doing this, and > why it's probably a bad idea, and some suggestions for alternatives: > > perldoc -q 'variable name': > > Found in /usr/share/perl/5.8.2/pod/perlfaq7.pod > How can I use a variable as a variable name? > > Beginners often think they want to have a variable > contain the name of a variable. > > $fred = 23; > $varname = "fred"; > ++$$varname; # $fred now 24 > > This works sometimes, but it is a very bad idea > for two reasons. > > The first reason is that this technique only works > on global variables. That means that if $fred is > a lexical variable created with my() in the above > example, the code wouldn't work at all: you'd > ... > > Hope that's useful. > > > --jeremy > > North, Walter wrote: > > >Good Morning all, > > > >Maybe this is a dumb question, but here goes anyway: > > > >Does anyone know if it possible to include a variable in, or > use a variable > >as > >the name of an array or hash, and if so how would one do it? > > > >thanks in advance. > > > > > >----------------------------------------------------- > >Walter North 406-444-2914 > >Operating Systems Programmer > >wnorth (at) state (dot) mt (dot) us > >----------------------------------------------------- > > > >_____________________________________________________________ > >Seattle Perl Users Group Mailing List > >POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > >ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > >MEETINGS: 3rd Tuesdays, U-District, Seattle WA > >WEB PAGE: http://www.seattleperl.org > > > > > > > > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > > From mathin at mathin.com Wed Feb 4 10:39:38 2004 From: mathin at mathin.com (Dan Ebert) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: Array Naming Question In-Reply-To: References: Message-ID: <1075912778.13883.10.camel@algernon.lan.enic.cc> I curious to know what problem is trying to be solved by using a string as the name of the variable. Maybe you could use a hash where the string is the key and the value is the array (or hash, or whatever)? i.e. my %names = (array1 => [1,2,3], array2 => [4,5,6]); my $use_this = 'array1'; foreach( @{ $names{$use_this} } ) { print; } Another possibility could be to use references. my @array1 = (1,2,3); my @array2 = (3,4,5); my $arrayref = \@array1; my $use_this = 'array1'; if($use_this eq 'array2') { $arrayref = \@array2; } foreach(@$arrayref) { print; } On Wed, 2004-02-04 at 08:13, Cantrall, Christopher W wrote: > Also, MJD has an article on this subject. http://perl.plover.com/varvarname.html > > > BeginQuote > > The real root of the problem code is: It's fragile. You're mingling unlike things when you do this. And if two of those unlike things happen to have the same name, they'll collide and you'll get the wrong answer. So you end up having a whole long list of names which you have to be careful not to reuse, and if you screw up, you get a very bizarre error. This is precisely the problem that namespaces were invented to solve, and that's just what a hash is: A portable namespace. > > ... > > The real problem is that if your string contains something unexpected, it will sabotage a totally unrelated part of the program, and then you will have one hell of a time figuring out the bug. > > EndQuote > > > MJD has 3 articles on this. Quite interesting. > > HTH > > ____________________________________________ > Chris Cantrall, Structural Engineer, 777 > Christopher.W.Cantrall@Boeing.com > chris@cantrall.org > http://perlmonks.org/index.pl?node=Louis_Wu > http://spugwiki.perlocity.org/index.cgi?LouisWu > > > -----Original Message----- > > From: Jeremy G Kahn [mailto:kahn@cpan.org] > > Sent: Wednesday, February 04, 2004 7:53 AM > > To: North, Walter > > Cc: spug > > Subject: Re: SPUG: Array Naming Question > > > > > > This is a good question, and a FAQ if you know where to look. The FAQ > > has an explanation for how you might want to go about doing this, and > > why it's probably a bad idea, and some suggestions for alternatives: > > > > perldoc -q 'variable name': > > > > Found in /usr/share/perl/5.8.2/pod/perlfaq7.pod > > How can I use a variable as a variable name? > > > > Beginners often think they want to have a variable > > contain the name of a variable. > > > > $fred = 23; > > $varname = "fred"; > > ++$$varname; # $fred now 24 > > > > This works sometimes, but it is a very bad idea > > for two reasons. > > > > The first reason is that this technique only works > > on global variables. That means that if $fred is > > a lexical variable created with my() in the above > > example, the code wouldn't work at all: you'd > > ... > > > > Hope that's useful. > > > > > > --jeremy > > > > North, Walter wrote: > > > > >Good Morning all, > > > > > >Maybe this is a dumb question, but here goes anyway: > > > > > >Does anyone know if it possible to include a variable in, or > > use a variable > > >as > > >the name of an array or hash, and if so how would one do it? > > > > > >thanks in advance. > > > > > > > > >----------------------------------------------------- > > >Walter North 406-444-2914 > > >Operating Systems Programmer > > >wnorth (at) state (dot) mt (dot) us > > >----------------------------------------------------- > > > > > >_____________________________________________________________ > > >Seattle Perl Users Group Mailing List > > >POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > >ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > >MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > >WEB PAGE: http://www.seattleperl.org > > > > > > > > > > > > > > > _____________________________________________________________ > > Seattle Perl Users Group Mailing List > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > WEB PAGE: http://www.seattleperl.org > > > > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > From wnorth at state.mt.us Wed Feb 4 11:19:36 2004 From: wnorth at state.mt.us (North, Walter) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: MORE INFO: Array Naming Question Message-ID: > I curious to know what problem is trying to be solved by > using a string > as the name of the variable. Dan: I collect some data from a storage array and read it into a hash with the date as the key from which I then produce a graph for perusal by management. More storage arrays are on the way and I'd like to combine the data however I haven't been able to come up with how to create a hash with the storage array name as a hash that contains another hash of the data keyed by date. So I figured I could turn out multiple hashes with the date as a key. However I would prefer not to have to modify the script to add another hash each time we get another storage device. Hence I would want to increment the name for example: ST_ARRAY_1 and the next would be ST_ARRAY_2 etc. A hash of hashes seems to be the superior method, but while I have done hashes of arrays I cannot seem to get a satisfactory hash of hashes. Hence my question. As Christopher and Jeremy pointed out using a variable name for a variable name is asking for trouble. > -----Original Message----- > From: Dan Ebert [mailto:mathin@mathin.com] > Sent: Wednesday, February 04, 2004 9:40 AM > Cc: spug > Subject: RE: SPUG: Array Naming Question > > > I curious to know what problem is trying to be solved by > using a string > as the name of the variable. > > Maybe you could use a hash where the string is the key and > the value is > the array (or hash, or whatever)? > > i.e. > > my %names = (array1 => [1,2,3], > array2 => [4,5,6]); > > my $use_this = 'array1'; > > foreach( @{ $names{$use_this} } ) { print; } > > > > Another possibility could be to use references. > > my @array1 = (1,2,3); > my @array2 = (3,4,5); > > my $arrayref = \@array1; > > my $use_this = 'array1'; > > if($use_this eq 'array2') { $arrayref = \@array2; } > > foreach(@$arrayref) { print; } > > > > On Wed, 2004-02-04 at 08:13, Cantrall, Christopher W wrote: > > Also, MJD has an article on this subject. > http://perl.plover.com/varvarname.html > > > > > > BeginQuote > > > > The real root of the problem code is: It's fragile. You're > mingling unlike things when you do this. And if two of those > unlike things happen to have the same name, they'll collide > and you'll get the wrong answer. So you end up having a whole > long list of names which you have to be careful not to reuse, > and if you screw up, you get a very bizarre error. This is > precisely the problem that namespaces were invented to solve, > and that's just what a hash is: A portable namespace. > > > > ... > > > > The real problem is that if your string contains something > unexpected, it will sabotage a totally unrelated part of the > program, and then you will have one hell of a time figuring > out the bug. > > > > EndQuote > > > > > > MJD has 3 articles on this. Quite interesting. > > > > HTH > > > > ____________________________________________ > > Chris Cantrall, Structural Engineer, 777 > > Christopher.W.Cantrall@Boeing.com > > chris@cantrall.org > > http://perlmonks.org/index.pl?node=Louis_Wu > > http://spugwiki.perlocity.org/index.cgi?LouisWu > > > > > -----Original Message----- > > > From: Jeremy G Kahn [mailto:kahn@cpan.org] > > > Sent: Wednesday, February 04, 2004 7:53 AM > > > To: North, Walter > > > Cc: spug > > > Subject: Re: SPUG: Array Naming Question > > > > > > > > > This is a good question, and a FAQ if you know where to > look. The FAQ > > > has an explanation for how you might want to go about > doing this, and > > > why it's probably a bad idea, and some suggestions for > alternatives: > > > > > > perldoc -q 'variable name': > > > > > > Found in /usr/share/perl/5.8.2/pod/perlfaq7.pod > > > How can I use a variable as a variable name? > > > > > > Beginners often think they want to have a variable > > > contain the name of a variable. > > > > > > $fred = 23; > > > $varname = "fred"; > > > ++$$varname; # $fred now 24 > > > > > > This works sometimes, but it is a very bad idea > > > for two reasons. > > > > > > The first reason is that this technique only works > > > on global variables. That means that if $fred is > > > a lexical variable created with my() in the above > > > example, the code wouldn't work at all: you'd > > > ... > > > > > > Hope that's useful. > > > > > > > > > --jeremy > > > > > > North, Walter wrote: > > > > > > >Good Morning all, > > > > > > > >Maybe this is a dumb question, but here goes anyway: > > > > > > > >Does anyone know if it possible to include a variable in, or > > > use a variable > > > >as > > > >the name of an array or hash, and if so how would one do it? > > > > > > > >thanks in advance. > > > > > > > > > > > >----------------------------------------------------- > > > >Walter North 406-444-2914 > > > >Operating Systems Programmer > > > >wnorth (at) state (dot) mt (dot) us > > > >----------------------------------------------------- > > > > > > > >_____________________________________________________________ > > > >Seattle Perl Users Group Mailing List > > > >POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > > >ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > > >MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > > >WEB PAGE: http://www.seattleperl.org > > > > > > > > > > > > > > > > > > > > > _____________________________________________________________ > > > Seattle Perl Users Group Mailing List > > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > > WEB PAGE: http://www.seattleperl.org > > > > > > > > _____________________________________________________________ > > Seattle Perl Users Group Mailing List > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > WEB PAGE: http://www.seattleperl.org > > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > > From mathin at mathin.com Wed Feb 4 11:31:13 2004 From: mathin at mathin.com (Dan Ebert) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: MORE INFO: Array Naming Question In-Reply-To: References: Message-ID: <1075915873.13883.16.camel@algernon.lan.enic.cc> Could you make the key like this: my $base = 'storage_array_'; my $number = 1; # this can be the part that can be dynamic my $key = $base . $number; $hash{$key} = %date_based_hash; On Wed, 2004-02-04 at 09:19, North, Walter wrote: > > I curious to know what problem is trying to be solved by > > using a string > > as the name of the variable. > > Dan: > > I collect some data from a storage array and read it into a hash > with the date as the key from which I then produce a graph for perusal > by management. > > More storage arrays are on the way and I'd like to combine the data > however I haven't been able to come up with how to create a hash > with the storage array name as a hash that contains another hash > of the data keyed by date. > > So I figured I could turn out multiple hashes with the date as > a key. > > However I would prefer not to have to modify the script to add another > hash each time we get another storage device. Hence I would want > to increment the name for example: > > ST_ARRAY_1 and the next would be ST_ARRAY_2 etc. > > A hash of hashes seems to be the superior method, but while I have > done hashes of arrays I cannot seem to get a satisfactory hash of hashes. > > Hence my question. > > As Christopher and Jeremy pointed out using a variable name for a variable > name is asking for trouble. > > > > -----Original Message----- > > From: Dan Ebert [mailto:mathin@mathin.com] > > Sent: Wednesday, February 04, 2004 9:40 AM > > Cc: spug > > Subject: RE: SPUG: Array Naming Question > > > > > > I curious to know what problem is trying to be solved by > > using a string > > as the name of the variable. > > > > Maybe you could use a hash where the string is the key and > > the value is > > the array (or hash, or whatever)? > > > > i.e. > > > > my %names = (array1 => [1,2,3], > > array2 => [4,5,6]); > > > > my $use_this = 'array1'; > > > > foreach( @{ $names{$use_this} } ) { print; } > > > > > > > > Another possibility could be to use references. > > > > my @array1 = (1,2,3); > > my @array2 = (3,4,5); > > > > my $arrayref = \@array1; > > > > my $use_this = 'array1'; > > > > if($use_this eq 'array2') { $arrayref = \@array2; } > > > > foreach(@$arrayref) { print; } > > > > > > > > On Wed, 2004-02-04 at 08:13, Cantrall, Christopher W wrote: > > > Also, MJD has an article on this subject. > > http://perl.plover.com/varvarname.html > > > > > > > > > BeginQuote > > > > > > The real root of the problem code is: It's fragile. You're > > mingling unlike things when you do this. And if two of those > > unlike things happen to have the same name, they'll collide > > and you'll get the wrong answer. So you end up having a whole > > long list of names which you have to be careful not to reuse, > > and if you screw up, you get a very bizarre error. This is > > precisely the problem that namespaces were invented to solve, > > and that's just what a hash is: A portable namespace. > > > > > > ... > > > > > > The real problem is that if your string contains something > > unexpected, it will sabotage a totally unrelated part of the > > program, and then you will have one hell of a time figuring > > out the bug. > > > > > > EndQuote > > > > > > > > > MJD has 3 articles on this. Quite interesting. > > > > > > HTH > > > > > > ____________________________________________ > > > Chris Cantrall, Structural Engineer, 777 > > > Christopher.W.Cantrall@Boeing.com > > > chris@cantrall.org > > > http://perlmonks.org/index.pl?node=Louis_Wu > > > http://spugwiki.perlocity.org/index.cgi?LouisWu > > > > > > > -----Original Message----- > > > > From: Jeremy G Kahn [mailto:kahn@cpan.org] > > > > Sent: Wednesday, February 04, 2004 7:53 AM > > > > To: North, Walter > > > > Cc: spug > > > > Subject: Re: SPUG: Array Naming Question > > > > > > > > > > > > This is a good question, and a FAQ if you know where to > > look. The FAQ > > > > has an explanation for how you might want to go about > > doing this, and > > > > why it's probably a bad idea, and some suggestions for > > alternatives: > > > > > > > > perldoc -q 'variable name': > > > > > > > > Found in /usr/share/perl/5.8.2/pod/perlfaq7.pod > > > > How can I use a variable as a variable name? > > > > > > > > Beginners often think they want to have a variable > > > > contain the name of a variable. > > > > > > > > $fred = 23; > > > > $varname = "fred"; > > > > ++$$varname; # $fred now 24 > > > > > > > > This works sometimes, but it is a very bad idea > > > > for two reasons. > > > > > > > > The first reason is that this technique only works > > > > on global variables. That means that if $fred is > > > > a lexical variable created with my() in the above > > > > example, the code wouldn't work at all: you'd > > > > ... > > > > > > > > Hope that's useful. > > > > > > > > > > > > --jeremy > > > > > > > > North, Walter wrote: > > > > > > > > >Good Morning all, > > > > > > > > > >Maybe this is a dumb question, but here goes anyway: > > > > > > > > > >Does anyone know if it possible to include a variable in, or > > > > use a variable > > > > >as > > > > >the name of an array or hash, and if so how would one do it? > > > > > > > > > >thanks in advance. > > > > > > > > > > > > > > >----------------------------------------------------- > > > > >Walter North 406-444-2914 > > > > >Operating Systems Programmer > > > > >wnorth (at) state (dot) mt (dot) us > > > > >----------------------------------------------------- > > > > > > > > > >_____________________________________________________________ > > > > >Seattle Perl Users Group Mailing List > > > > >POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > > > >ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > > > >MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > > > >WEB PAGE: http://www.seattleperl.org > > > > > > > > > > > > > > > > > > > > > > > > > > > _____________________________________________________________ > > > > Seattle Perl Users Group Mailing List > > > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > > > WEB PAGE: http://www.seattleperl.org > > > > > > > > > > > _____________________________________________________________ > > > Seattle Perl Users Group Mailing List > > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > > WEB PAGE: http://www.seattleperl.org > > > > > _____________________________________________________________ > > Seattle Perl Users Group Mailing List > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > WEB PAGE: http://www.seattleperl.org > > > > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > From cwilkes-spug at ladro.com Wed Feb 4 11:35:44 2004 From: cwilkes-spug at ladro.com (Chris Wilkes) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: MORE INFO: Array Naming Question In-Reply-To: References: Message-ID: <20040204173544.GA12413@www.ladro.com> On Wed, Feb 04, 2004 at 10:19:36AM -0700, North, Walter wrote: > > More storage arrays are on the way and I'd like to combine the data > however I haven't been able to come up with how to create a hash > with the storage array name as a hash that contains another hash > of the data keyed by date. You might want to look into making a perl module so that you can do something like this: open (FOO, "datafile.txt"); while () { chomp; my @items = split; push @storage_units, My::StorageUnit->new($items[0], @items[1..$#items]); } close FOO; so now in the array you have all your storage units and you can then do things like $unit = $storage_units[0]; print "Storage unit " . $unit->getName() . " was purchased on " . $unit->getDatePurchased() . "\n"; so you don't have to remember "Did I make that a hash, hash of hashes, array of hashes?" What's better is that when someone else takes over this code their head won't start spinning and just has to know "To get the date I just do a ->getDatePurchased()" Chris From wnorth at state.mt.us Wed Feb 4 11:46:38 2004 From: wnorth at state.mt.us (North, Walter) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: MORE INFO: Array Naming Question Message-ID: Dan: >>>>>>>Blinding Flash of Light<<<<<<<<< Sometimes the obvious is just too obvious............. Its the key stupid, not the hash name........... Thank you. Also Chris Wilkes for the thought on creating my own perl module. That is definately one I had not thought of. Perhaps as my skills increase........ thanks to all > -----Original Message----- > From: Dan Ebert [mailto:mathin@mathin.com] > Sent: Wednesday, February 04, 2004 10:31 AM > To: North, Walter > Cc: Spug (E-mail) > Subject: Re: SPUG: MORE INFO: Array Naming Question > > > > Could you make the key like this: > > my $base = 'storage_array_'; > > my $number = 1; # this can be the part that can be dynamic > > my $key = $base . $number; > > $hash{$key} = %date_based_hash; > > On Wed, 2004-02-04 at 09:19, North, Walter wrote: > > > I curious to know what problem is trying to be solved by > > > using a string > > > as the name of the variable. > > > > Dan: > > > > I collect some data from a storage array and read it into a hash > > with the date as the key from which I then produce a graph > for perusal > > by management. > > > > More storage arrays are on the way and I'd like to combine the data > > however I haven't been able to come up with how to create a hash > > with the storage array name as a hash that contains another hash > > of the data keyed by date. > > > > So I figured I could turn out multiple hashes with the date as > > a key. > > > > However I would prefer not to have to modify the script to > add another > > hash each time we get another storage device. Hence I would want > > to increment the name for example: > > > > ST_ARRAY_1 and the next would be ST_ARRAY_2 etc. > > > > A hash of hashes seems to be the superior method, but while I have > > done hashes of arrays I cannot seem to get a satisfactory > hash of hashes. > > > > Hence my question. > > > > As Christopher and Jeremy pointed out using a variable name > for a variable > > name is asking for trouble. > > > > > > > -----Original Message----- > > > From: Dan Ebert [mailto:mathin@mathin.com] > > > Sent: Wednesday, February 04, 2004 9:40 AM > > > Cc: spug > > > Subject: RE: SPUG: Array Naming Question > > > > > > > > > I curious to know what problem is trying to be solved by > > > using a string > > > as the name of the variable. > > > > > > Maybe you could use a hash where the string is the key and > > > the value is > > > the array (or hash, or whatever)? > > > > > > i.e. > > > > > > my %names = (array1 => [1,2,3], > > > array2 => [4,5,6]); > > > > > > my $use_this = 'array1'; > > > > > > foreach( @{ $names{$use_this} } ) { print; } > > > > > > > > > > > > Another possibility could be to use references. > > > > > > my @array1 = (1,2,3); > > > my @array2 = (3,4,5); > > > > > > my $arrayref = \@array1; > > > > > > my $use_this = 'array1'; > > > > > > if($use_this eq 'array2') { $arrayref = \@array2; } > > > > > > foreach(@$arrayref) { print; } > > > > > > > > > > > > On Wed, 2004-02-04 at 08:13, Cantrall, Christopher W wrote: > > > > Also, MJD has an article on this subject. > > > http://perl.plover.com/varvarname.html > > > > > > > > > > > > BeginQuote > > > > > > > > The real root of the problem code is: It's fragile. You're > > > mingling unlike things when you do this. And if two of those > > > unlike things happen to have the same name, they'll collide > > > and you'll get the wrong answer. So you end up having a whole > > > long list of names which you have to be careful not to reuse, > > > and if you screw up, you get a very bizarre error. This is > > > precisely the problem that namespaces were invented to solve, > > > and that's just what a hash is: A portable namespace. > > > > > > > > ... > > > > > > > > The real problem is that if your string contains something > > > unexpected, it will sabotage a totally unrelated part of the > > > program, and then you will have one hell of a time figuring > > > out the bug. > > > > > > > > EndQuote > > > > > > > > > > > > MJD has 3 articles on this. Quite interesting. > > > > > > > > HTH > > > > > > > > ____________________________________________ > > > > Chris Cantrall, Structural Engineer, 777 > > > > Christopher.W.Cantrall@Boeing.com > > > > chris@cantrall.org > > > > http://perlmonks.org/index.pl?node=Louis_Wu > > > > http://spugwiki.perlocity.org/index.cgi?LouisWu > > > > > > > > > -----Original Message----- > > > > > From: Jeremy G Kahn [mailto:kahn@cpan.org] > > > > > Sent: Wednesday, February 04, 2004 7:53 AM > > > > > To: North, Walter > > > > > Cc: spug > > > > > Subject: Re: SPUG: Array Naming Question > > > > > > > > > > > > > > > This is a good question, and a FAQ if you know where to > > > look. The FAQ > > > > > has an explanation for how you might want to go about > > > doing this, and > > > > > why it's probably a bad idea, and some suggestions for > > > alternatives: > > > > > > > > > > perldoc -q 'variable name': > > > > > > > > > > Found in /usr/share/perl/5.8.2/pod/perlfaq7.pod > > > > > How can I use a variable as a variable name? > > > > > > > > > > Beginners often think they want to > have a variable > > > > > contain the name of a variable. > > > > > > > > > > $fred = 23; > > > > > $varname = "fred"; > > > > > ++$$varname; # $fred now 24 > > > > > > > > > > This works sometimes, but it is a very bad idea > > > > > for two reasons. > > > > > > > > > > The first reason is that this > technique only works > > > > > on global variables. That means that > if $fred is > > > > > a lexical variable created with my() > in the above > > > > > example, the code wouldn't work at all: you'd > > > > > ... > > > > > > > > > > Hope that's useful. > > > > > > > > > > > > > > > --jeremy > > > > > > > > > > North, Walter wrote: > > > > > > > > > > >Good Morning all, > > > > > > > > > > > >Maybe this is a dumb question, but here goes anyway: > > > > > > > > > > > >Does anyone know if it possible to include a variable in, or > > > > > use a variable > > > > > >as > > > > > >the name of an array or hash, and if so how would one do it? > > > > > > > > > > > >thanks in advance. > > > > > > > > > > > > > > > > > >----------------------------------------------------- > > > > > >Walter North 406-444-2914 > > > > > >Operating Systems Programmer > > > > > >wnorth (at) state (dot) mt (dot) us > > > > > >----------------------------------------------------- > > > > > > > > > > > >_____________________________________________________________ > > > > > >Seattle Perl Users Group Mailing List > > > > > >POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > > > > >ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > > > > >MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > > > > >WEB PAGE: http://www.seattleperl.org > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > _____________________________________________________________ > > > > > Seattle Perl Users Group Mailing List > > > > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > > > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > > > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > > > > WEB PAGE: http://www.seattleperl.org > > > > > > > > > > > > > > _____________________________________________________________ > > > > Seattle Perl Users Group Mailing List > > > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > > > WEB PAGE: http://www.seattleperl.org > > > > > > > _____________________________________________________________ > > > Seattle Perl Users Group Mailing List > > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > > WEB PAGE: http://www.seattleperl.org > > > > > > > > _____________________________________________________________ > > Seattle Perl Users Group Mailing List > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > WEB PAGE: http://www.seattleperl.org > > > From brianmaddux at yahoo.com Wed Feb 4 12:00:58 2004 From: brianmaddux at yahoo.com (Brian Maddux) Date: Mon Aug 2 21:37:15 2004 Subject: SPUG: MORE INFO: Array Naming Question In-Reply-To: Message-ID: <20040204180058.62034.qmail@web40203.mail.yahoo.com> I would suggest getting the Advanced Perl Programming book from O'Reilly. It really helps with hashes, references, etc. Once you get the concept down, its easy to make data structures to fit almost any need. It also has a (small) section on OO Perl and making your own modules. This book has greatly expanded my abilities for solving problems with Perl. Brian --- "North, Walter" wrote: > > Dan: > > >>>>>>>Blinding Flash of Light<<<<<<<<< > > Sometimes the obvious is just too > obvious............. > > Its the key stupid, not the hash name........... > > Thank you. > > Also Chris Wilkes for the thought on creating my own > perl module. That is definately one I had not > thought of. > > Perhaps as my skills increase........ > > thanks to all > > > -----Original Message----- > > From: Dan Ebert [mailto:mathin@mathin.com] > > Sent: Wednesday, February 04, 2004 10:31 AM > > To: North, Walter > > Cc: Spug (E-mail) > > Subject: Re: SPUG: MORE INFO: Array Naming > Question > > > > > > > > Could you make the key like this: > > > > my $base = 'storage_array_'; > > > > my $number = 1; # this can be the part that can be > dynamic > > > > my $key = $base . $number; > > > > $hash{$key} = %date_based_hash; > > > > On Wed, 2004-02-04 at 09:19, North, Walter wrote: > > > > I curious to know what problem is trying to be > solved by > > > > using a string > > > > as the name of the variable. > > > > > > Dan: > > > > > > I collect some data from a storage array and > read it into a hash > > > with the date as the key from which I then > produce a graph > > for perusal > > > by management. > > > > > > More storage arrays are on the way and I'd like > to combine the data > > > however I haven't been able to come up with how > to create a hash > > > with the storage array name as a hash that > contains another hash > > > of the data keyed by date. > > > > > > So I figured I could turn out multiple hashes > with the date as > > > a key. > > > > > > However I would prefer not to have to modify the > script to > > add another > > > hash each time we get another storage device. > Hence I would want > > > to increment the name for example: > > > > > > ST_ARRAY_1 and the next would be ST_ARRAY_2 etc. > > > > > > A hash of hashes seems to be the superior > method, but while I have > > > done hashes of arrays I cannot seem to get a > satisfactory > > hash of hashes. > > > > > > Hence my question. > > > > > > As Christopher and Jeremy pointed out using a > variable name > > for a variable > > > name is asking for trouble. > > > > > > > > > > -----Original Message----- > > > > From: Dan Ebert [mailto:mathin@mathin.com] > > > > Sent: Wednesday, February 04, 2004 9:40 AM > > > > Cc: spug > > > > Subject: RE: SPUG: Array Naming Question > > > > > > > > > > > > I curious to know what problem is trying to be > solved by > > > > using a string > > > > as the name of the variable. > > > > > > > > Maybe you could use a hash where the string is > the key and > > > > the value is > > > > the array (or hash, or whatever)? > > > > > > > > i.e. > > > > > > > > my %names = (array1 => [1,2,3], > > > > array2 => [4,5,6]); > > > > > > > > my $use_this = 'array1'; > > > > > > > > foreach( @{ $names{$use_this} } ) { print; } > > > > > > > > > > > > > > > > Another possibility could be to use > references. > > > > > > > > my @array1 = (1,2,3); > > > > my @array2 = (3,4,5); > > > > > > > > my $arrayref = \@array1; > > > > > > > > my $use_this = 'array1'; > > > > > > > > if($use_this eq 'array2') { $arrayref = > \@array2; } > > > > > > > > foreach(@$arrayref) { print; } > > > > > > > > > > > > > > > > On Wed, 2004-02-04 at 08:13, Cantrall, > Christopher W wrote: > > > > > Also, MJD has an article on this subject. > > > > http://perl.plover.com/varvarname.html > > > > > > > > > > > > > > > BeginQuote > > > > > > > > > > The real root of the problem code is: It's > fragile. You're > > > > mingling unlike things when you do this. And > if two of those > > > > unlike things happen to have the same name, > they'll collide > > > > and you'll get the wrong answer. So you end up > having a whole > > > > long list of names which you have to be > careful not to reuse, > > > > and if you screw up, you get a very bizarre > error. This is > > > > precisely the problem that namespaces were > invented to solve, > > > > and that's just what a hash is: A portable > namespace. > > > > > > > > > > ... > > > > > > > > > > The real problem is that if your string > contains something > > > > unexpected, it will sabotage a totally > unrelated part of the > > > > program, and then you will have one hell of a > time figuring > > > > out the bug. > > > > > > > > > > EndQuote > > > > > > > > > > > > > > > MJD has 3 articles on this. Quite > interesting. > > > > > > > > > > HTH > > > > > > > > > > ____________________________________________ > > > > > Chris Cantrall, Structural Engineer, 777 > > > > > Christopher.W.Cantrall@Boeing.com > > > > > chris@cantrall.org > > > > > > http://perlmonks.org/index.pl?node=Louis_Wu > > > > > > http://spugwiki.perlocity.org/index.cgi?LouisWu > > > > > > > > > > > -----Original Message----- > > > > > > From: Jeremy G Kahn [mailto:kahn@cpan.org] > > > > > > Sent: Wednesday, February 04, 2004 7:53 AM > > > > > > To: North, Walter > > > > > > Cc: spug > > > > > > Subject: Re: SPUG: Array Naming Question > > > > > > > > > > > > > > > > > > This is a good question, and a FAQ if you > know where to > > > > look. The FAQ > > > > > > has an explanation for how you might want > to go about > === message truncated === ===== ------------------------------------------------------- Brian Maddux Whidbey Island, WA brianmaddux@yahoo.com ------------------------------------------------------- __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! http://webhosting.yahoo.com/ps/sb/ From cwilkes-spug at ladro.com Wed Feb 4 12:33:47 2004 From: cwilkes-spug at ladro.com (Chris Wilkes) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: MORE INFO: Array Naming Question In-Reply-To: <20040204180058.62034.qmail@web40203.mail.yahoo.com> References: <20040204180058.62034.qmail@web40203.mail.yahoo.com> Message-ID: <20040204183346.GA19867@www.ladro.com> > --- "North, Walter" wrote: > > > > Dan: > > > > >>>>>>>Blinding Flash of Light<<<<<<<<< > > > > Sometimes the obvious is just too > > obvious............. > > > > Its the key stupid, not the hash name........... > > > > Thank you. > > > > Also Chris Wilkes for the thought on creating my own > > perl module. That is definately one I had not > > thought of. > > > > Perhaps as my skills increase........ On Wed, Feb 04, 2004 at 10:00:58AM -0800, Brian Maddux wrote: > I would suggest getting the Advanced Perl Programming > book from O'Reilly. It really helps with hashes, > references, etc. Also look into picking up Damian Conway's book "Object Oriented Perl": http://www.amazon.com/exec/obidos/tg/detail/-/1884777791 which is both witty and informative. What I like to do is look at my code and think "6 months down the road am I going to remember that $info{name}{date} is the purchase date?" and the answer is usually no. Or "If someone else took over this project can they easily extend what I've done?" -- if all you have are one off scripts then no. When you start writing modules you might think that you're doing a lot of work for little gain. Why am I writing all these getters and setters when it took me 2 seconds to think up $info{name}{date}? Keep reminding yourself that you *read* code 100x more often then you *write* it. So if it takes you an hour to write a good module it will pay off in the long run as you don't have to keep on remembering what data structures you were using. Good luck! Chris From sthoenna at efn.org Wed Feb 4 12:55:33 2004 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: MORE INFO: Array Naming Question In-Reply-To: References: Message-ID: <20040204185533.GA2472@efn.org> On Wed, Feb 04, 2004 at 10:19:36AM -0700, "North, Walter" wrote: > I collect some data from a storage array and read it into a hash > with the date as the key from which I then produce a graph for perusal > by management. > > More storage arrays are on the way and I'd like to combine the data > however I haven't been able to come up with how to create a hash > with the storage array name as a hash that contains another hash > of the data keyed by date. > > So I figured I could turn out multiple hashes with the date as > a key. > > However I would prefer not to have to modify the script to add another > hash each time we get another storage device. Hence I would want > to increment the name for example: > > ST_ARRAY_1 and the next would be ST_ARRAY_2 etc. > > A hash of hashes seems to be the superior method, but while I have > done hashes of arrays I cannot seem to get a satisfactory hash of hashes. To use a hash of hashes in place of your existing hash, wherever you have $oldhash{$date} use $newhash{$storagearray}{$date}. Where you have %oldhash, use %{$newhash{$storagearray}}. Does that help? You might read through perldoc perldsc. From lmzaldivar at mac.com Mon Feb 9 12:27:02 2004 From: lmzaldivar at mac.com (Luis Medrano) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: Creating tables on MySql Message-ID: <1955193.1076351222576.JavaMail.lmzaldivar@mac.com> List, I have a question. I need to verify the existence of tables in MySql using perl and in case that table doesn't exist I need to created using perl of course. Any idea how can I do this?? Thanks, Luis From dan at concolor.org Mon Feb 9 12:39:22 2004 From: dan at concolor.org (Dan Sabath) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: Creating tables on MySql In-Reply-To: <1955193.1076351222576.JavaMail.lmzaldivar@mac.com> References: <1955193.1076351222576.JavaMail.lmzaldivar@mac.com> Message-ID: <20040209183922.GB13465@kell.fairehosting.com> On Mon, Feb 09, 2004 at 10:27:02AM -0800, Luis Medrano wrote: > List, > > I have a question. I need to verify the existence of tables in MySql using perl and in case that table doesn't exist I need to created using perl of course. Any idea how can I do this?? > Use Perl DBI http://dbi.perl.org/ -dan From bri at ifokr.org Mon Feb 9 12:56:12 2004 From: bri at ifokr.org (Brian Hatch) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: Creating tables on MySql In-Reply-To: <20040209183922.GB13465@kell.fairehosting.com> References: <1955193.1076351222576.JavaMail.lmzaldivar@mac.com> <20040209183922.GB13465@kell.fairehosting.com> Message-ID: <20040209185612.GA7331@ifokr.org> > On Mon, Feb 09, 2004 at 10:27:02AM -0800, Luis Medrano wrote: > > List, > > > > I have a question. I need to verify the existence of tables in MySql using perl and in case that table doesn't exist I need to created using perl of course. Any idea how can I do this?? > > > > Use Perl DBI > > http://dbi.perl.org/ Something ala my $sth = $dbi->prepare("desc %"); my $success = $sth->execute(); if ( ! $success ) { $sth = $dbi->prepare("create table blahblahblahblah"); $success = $sth->execute(); if ( ! $success ) { die "Shoot, it didn't work." } } MySQL can check for existance using 'desc' (to 'describe') though you could of course do a 'select *' but that'd be overkill. 'select * limit 1' might be a portable solution that misuse kill the server if it's a huge table. -- Brian Hatch Error 23 occured when Systems and attempting to report Security Engineer error 23. http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://mail.pm.org/pipermail/spug-list/attachments/20040209/c3551cb0/attachment.bin From tim at consultix-inc.com Thu Feb 12 13:31:51 2004 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: Code-Fusion/Perl contract Message-ID: <20040212193151.GA5562@jumpy.consultix-inc.com> required skill-set : knowledge of Perl and Cold Fusion. contract or permanent position : contract for contracts, expected duration and pay range : several hours to a week or so (or longer, depending on where this leads us) placement through recruiter, or directly with company? Directly with company W-2 vs. 1099 status : 1099 status most likely any restrictions on 1099 status: Corporation, etc.? Not that we know of. physical location : 9410 Roosevelt Way NE telecommuting possible? Yes company's product or service : Legal codes (print and electronic via Internet). www.codepublishing.com Our legal codes are divided into titles, chapters and sections. Some customers want to view individual sections, and some want to view the whole chapter or title. Those who want to view individual sections would also like the option to view the entire chapter (at the click of a link). Interested persons can view our codes by choosing a link from the list of cities at http://www.codepublishing.com/municodes.html. Most, but not all, links are to html file sets. Interested persons can call the person listed below, or email to codepublishing@qwest.net with subject line PERL. Margaret O. Bustion Code Publishing Co. PO Box 51164 voice: 206-527-6831 www.codepublishing.com From schieb at centurytel.net Fri Feb 13 18:21:42 2004 From: schieb at centurytel.net (Islandman) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: programmingbids.com Message-ID: <402D6A16.F4BC2C5C@centurytel.net> So I'm freakin' Was looking at http://www.programmingbids.com today. Much of India is on there bidding PERL/PHP/admin/etc jobs at roughly $10-15/hr. Thoughts? -Brian Vashon Island From tim at consultix-inc.com Mon Feb 16 13:40:32 2004 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: Feb. Mtg, Intro to Perl, Part II Message-ID: <20040216194032.GA2983@jumpy.consultix-inc.com> SPUGsters, Hope to see a lot of you, along with your friends who need an easy intro to Perl, at our final Safeco meeting on 2/17. Don't forget to sign up on the Kwiki page (spugwiki.perlocity.org) if you're planning to eat at Cedars. ============================================================== | Tim Maher, Ph.D. tim(AT)teachmeperl.com | | SPUG Founder & Leader spug(AT)teachmeperl.com | | Seattle Perl Users Group http://www.seattleperl.com | | SPUG Wiki Site http://spugwiki.perlocity.org | | Perl Certification Site http://perlcert.perlocity.org | ============================================================== --------------------------------------------------------- February Seattle Perl Users Group Meeting --------------------------------------------------------- What: "Introduction to Perl", Part II Who: Tim Maher, Consultix (timteachmeperl.com) When: Tuesday, Feb. 17, 2004 7-9pm --------------------------------------------------------- Who's right about Perl? "Perl is an immensely powerful language, suitable for a wide range of applications, that allows unparalleled freedom of expression and diversity in coding solutions." "Perl is a write-only, line-noise language that encourages programmers to cultivate incompatible idiosyncratic dialects of cryptic symbols, making it difficult for one programmer to understand or maintain programs written by another." Who's right? Both! Perl is indeed a powerful and important language with lots of features and coding options, and it can be difficult to learn and hard to read. /But it doesn't have to be!/ To make Perl *more accessible* and /more acceptable/ to IT departments, Tim Maher has developed a tiny subset of the language called "Minimal Perl" that is easily learned yet sufficient for writing many useful kinds of highly readable programs. For the February 17th SPUG meeting, Tim will continue his "Intro to Perl", that's based on the "Minimal Perl" dialect. Because this is a beginner's oriented talk, we're especially interested in attracting first-time visitors to SPUG who wouldn't be able to handle the pace of our regular meetings. So please help spread the word to potentially interested parties by forwarding this email to friends and colleagues, and cross-posting it on other mailing lists. -Tim --------------------------------------------------------- February Seattle Perl Users Group Meeting --------------------------------------------------------- What: "Introduction to Perl", Part II Who: Tim Maher, Consultix (timteachmeperl.com) When: Tuesday, Feb. 17, 2004 7-9pm Where: SAFECO bldg, Brooklyn St. and NE 45th St. Seattle WA USA How Much: Free and open to the general public. More Info: http://seattleperl.org/ --------------------------------------------------------- In this talk, veteran UNIX/Linux/Perl trainer Tim Maher will provide an introduction to the Perl language. The emphasis will be on basic features of Perl, especially ones that are easy to learn for those familiar with the UNIX *grep* command and its relatives, and with fundamental shell programming principles (use of variables, arguments, redirection, etc.). Attendees will learn the *easy way* to write Perl programs that can do "file conversion", "data validation", "report generation", and "number crunching", among other things. Tim's talk will feature excerpts from his upcoming book for Manning Press called "Minimal Perl for Shell Users and Programmers", his commercial Perl training courses, and his past presentations at the LinuxFest Northwest conference, YAPC conferences in the US and Europe, and The Perl Conference. Pre- and Post- Meeting Activities --------------------------------- The pre-meeting dinner will be at the Cedars restaurant, at 50th St. and Brooklyn, in the University District, near the Safeco building where the meeting will take place. The phone number is 527-5247. If you are planning to be there, please enter your name on the Kwiki RSVP page (see spugwiki.perlocity.org) by 2pm on the meeting day. (NOTE: Arrival by 5:45pm is recommended for those ordering food). ============================================================== | Tim Maher, Ph.D. tim(AT)teachmeperl.com | | SPUG Founder & Leader spug(AT)teachmeperl.com | | Seattle Perl Users Group http://www.seattleperl.com | | SPUG Wiki Site http://spugwiki.perlocity.org | | Perl Certification Site http://perlcert.perlocity.org | ============================================================== From tim at consultix-inc.com Mon Feb 16 13:42:51 2004 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: SPUG's future Message-ID: <20040216194251.GB2983@jumpy.consultix-inc.com> SPUGsters, As indicated early this year, I'm relinquishing the reins of SPUG after the 2/17th meeting, which happens to also be the last meeting that SPUG will have at Safeco (unless somebody can round up a new Safeco employee as a sponsor). I hope many of you have found the existence of SPUG to be an asset to your professional careers, as I have. If so, I strongly encourage you to step forward and play a part in keeping it going, because it will be much harder to rekindle the flames of SPUG after a hiatus than it will be to keep it alive. If I'm the only guy who cares enough about SPUG to work to preserve it, then it deserves to die along with my retirement (which by the way is exactly what happened to E-SPUG, the East-side chapter, when "Emperor Ryan" retired). But it would be a shame if SPUG were to die just because well-intentioned individuals never got around to doing anything to avoid that eventuality! It's impossible to overemphasize the fact that the future of SPUG is in your hands. Don't sit on them! If you want to help keep SPUG alive, you can help by signing up for some duties over at spugwiki.perlocity.org, and inciting others into action on this list. -Tim ============================================================== | Tim Maher, Ph.D. tim(AT)teachmeperl.com | | SPUG Founder & Leader spug(AT)teachmeperl.com | | Seattle Perl Users Group http://www.seattleperl.com | | SPUG Wiki Site http://spugwiki.perlocity.org | | Perl Certification Site http://perlcert.perlocity.org | ============================================================== From lmzaldivar at mac.com Thu Feb 19 12:34:14 2004 From: lmzaldivar at mac.com (Luis Medrano) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: Tie::File module Message-ID: <229447.1077215654650.JavaMail.lmzaldivar@mac.com> List, I try to experiment with Tie::file module buth I have a question. I'm running this code: tie @lines, 'Tie::File', 'file' or die ...; print "$line[0] \n"; untie @lines; I was specting to print just one line of the file but it print the whole file. Any idea why or how can I do it so it will print just one line?? Thanks, Luis From cwilkes-spug at ladro.com Thu Feb 19 12:47:03 2004 From: cwilkes-spug at ladro.com (Chris Wilkes) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: Tie::File module In-Reply-To: <229447.1077215654650.JavaMail.lmzaldivar@mac.com> References: <229447.1077215654650.JavaMail.lmzaldivar@mac.com> Message-ID: <20040219184703.GA60881@www.ladro.com> On Thu, Feb 19, 2004 at 10:34:14AM -0800, Luis Medrano wrote: > > I try to experiment with Tie::file module buth I have a question. I'm > running this code: > > tie @lines, 'Tie::File', 'file' or die ...; > > print "$line[0] \n"; > untie @lines; > > I was specting to print just one line of the file but it print the > whole file. Any idea why or how can I do it so it will print just > one line?? I was going to say "Check and make sure your file has more than one line" but now I'm going to say "use strict" and you'll see that you put the file into "@lineS" (note the S) and you're printing out "$line" (no S). Chris From sthoenna at efn.org Thu Feb 19 12:45:47 2004 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: Tie::File module In-Reply-To: <229447.1077215654650.JavaMail.lmzaldivar@mac.com> References: <229447.1077215654650.JavaMail.lmzaldivar@mac.com> Message-ID: <20040219184547.GA2900@efn.org> On Thu, Feb 19, 2004 at 10:34:14AM -0800, Luis Medrano wrote: > List, > > I try to experiment with Tie::file module buth I have a question. I'm running this code: > > tie @lines, 'Tie::File', 'file' or die ...; > > print "$line[0] \n"; > untie @lines; > > I was specting to print just one line of the file but it print the whole file. Any idea why or how can I do it so it will print just one line?? Have you messed with $/? Tie::File uses it to determine line endings. From cmeyer at helvella.org Fri Feb 20 19:29:47 2004 From: cmeyer at helvella.org (Colin Meyer) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: SPUG is dead, long live SPUG! Message-ID: <20040221012947.GB1193@funpox.helvella.org> Friends, Our indefatigable leader, Tim, after six years of organizing and promoting SPUG has become fatigued and is stepping down. I'd like to offer a huge THANKS to Tim for all his hard work! Michael Wolf had the idea to throw a SPUG party to show our appreciation for Tim, and all that he has done for us, as well as focus on the new organization and leadership for SPUG. I'm going to host that party. Event: SPUG is dead, long live SPUG party Date: Friday, March 5 Time: 8PM-1AM Location: Colin's house (Skyway neighborhood of Seattle) RSVP: to get driving directions Come prepared so celebrate the greatness of SPUG, and to join in and volunteer to help keep this fantastic group going! Tim will bring along his White Camel award, "so we can anoint it with fine Belgian ales in attempts to appease the Forces of Python. 8-}" I'll supply a Belgian ale or three, some other beers and some whiskey and vodka. Bring along your favorite beverage or snack. Have fun, -Colin. From tim at consultix-inc.com Sat Feb 21 11:44:53 2004 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: SPUG is dead, long live SPUG! In-Reply-To: <20040221012947.GB1193@funpox.helvella.org> References: <20040221012947.GB1193@funpox.helvella.org> Message-ID: <20040221174453.GA11488@jumpy.consultix-inc.com> On Fri, Feb 20, 2004 at 05:29:47PM -0800, Colin Meyer wrote: > Friends, > > Our indefatigable leader, Tim, after six years of organizing and > promoting SPUG has become fatigued and is stepping down. And that just goes to show you how much you can rely on indefatigability to keep you going these days ! 8-} > I'd like to > offer a huge THANKS to Tim for all his hard work! You just did, and I appreciate it! 8-} SPUG has been a great experience for me, and I've learned a lot from it -- about topics other than Perl too! Up until 3/17/98, I had spent lots of effort criticizing the way other people were running their organizations, or bemoaning the non-existence of organizations that would have made my life richer. Creating and running SPUG was a different kind of activity, being "creative" rather than "critical", and it brought with it the satisfactions of making a useful contribution to Perl and the community, and the benefits of putting local JAPHs in touch with each other. It can be easier and more fun to be a critic, but it's ultimately more satisfying to create something important and useful. Aw SPUG, I'm starting to sound like Oprah now, so I'd better shut up. Long live SPUG! ============================================================== | Tim Maher, Ph.D. tim(AT)teachmeperl.com | | SPUG Leader Emeritus spug(AT)teachmeperl.com | | Seattle Perl Users Group http://www.seattleperl.com | | SPUG Wiki Site http://spugwiki.perlocity.org | | Perl Certification Site http://perlcert.perlocity.org | ============================================================== From andrew at sweger.net Sat Feb 21 16:28:14 2004 From: andrew at sweger.net (Andrew Sweger) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: talk proposal: Perl debugger intro Message-ID: I was digging through my archive of SPUG mail and came across someone preaching about the goodness of the Perl debugger. Have we already had a presentation on this recently? Is there interest in having a live walk through with the debugger (as an intro to how it can save your butt and sanity)? I'm willing (and I need the practice). -- Andrew B. Sweger -- The great thing about multitasking is that several things can go wrong at once. From bill at celestial.com Sat Feb 21 16:41:22 2004 From: bill at celestial.com (Bill Campbell) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: talk proposal: Perl debugger intro In-Reply-To: References: Message-ID: <20040221224122.GA42295@alexis.mi.celestial.com> On Sat, Feb 21, 2004, Andrew Sweger wrote: >I was digging through my archive of SPUG mail and came across someone >preaching about the goodness of the Perl debugger. Have we already had a >presentation on this recently? Is there interest in having a live walk >through with the debugger (as an intro to how it can save your butt and >sanity)? I'm willing (and I need the practice). Perhaps with some discussion of using the debugger under the graphic ``ddd'' tool? Bill -- INTERNET: bill@Celestial.COM Bill Campbell; Celestial Software LLC UUCP: camco!bill PO Box 820; 6641 E. Mercer Way FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 URL: http://www.celestial.com/ ``Nobody wants to be called common people, especially common people.'' Will Rogers From tallpeak at hotmail.com Sat Feb 21 16:45:45 2004 From: tallpeak at hotmail.com (Aaron W. West) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: axkit Message-ID: Has anyone used axkit? And can anyone comment on using Embperl vs. using Mason vs. pure mod_perl? But actually, I'll probably just use PerlIS.DLL for now, and switch to another approach if performance becomes poor. As I understand, ActiveState PerlIS.DLL may have to recompile for every hit, whereas AS's PerlEx and Perl for .NET, and Apache's mod_perl and EmbPerl and Mason, all cache compiled code in-memory (but I'm not sure about that.) http://tldp.net/HOWTO/Apache-Overview-HOWTO-17.html Mentions Perl, Embperl, Mason, mod_perl, and axkit (Read no further unless you're bored) ------------ I wrote a long rambling email earlier, but decided that was the only question/comment I had of value in it. (Lies, damn lies, and benchmarks... don't optimize if there's no need, right?) -- Whether to optimize first or last is one of those nagging questions I always have on my mind. Optimize too early-on, and you waste time and mental energy on mundane details of implementation, whereas by the time you are through you may take a totally different approach and throw out all your earlier painstaking optimizations. In general, I think, if optimization means greater code size, save it for later, but if a huge gain can be had cheaply, do it now. That's the approach I've tended to follow, yet admittedly end up wasting time on needless optimization sometimes. Below, comparing unpack, substr and /regex/, I was just doing it for the education (who cares about 4 microseconds in something that is database-constrained, anyway?). -----Original Message----- From: Aaron W. West [mailto:tallpeak@speakeasy.net] Sent: Saturday, February 21, 2004 10:08 AM To: spug-list@pm.org Subject: Comments on line-parsing and other random ramblings... Perhaps I shouldn't go knocking Tim Maher's suggestion to turn on line terminator handling for scripts, but... Is it *really* a good idea to use the -l option in scripts? My issue with it is that it's a global setting. What if you have various modules in your app, and each one likes to handle things differently? What if you decide to put your code into Mason or a templating system, and it breaks because this option is off? Is there a perl variable to control "-l"? It just seems unnatural to rely on #perl -l to set the option. I suppose the solution is the use of local for $/ or $\ in those modules/functions that need it, and designing all modules to be careful not to be sensitive to the -l setting. I'll admit, it gets mildly tedious trying to remember to put "\n" at the end of every "print", but what if I want somewhere to print without a "\n". I know I can use local in a block: $ perl -le '{local ($\)=""; print "a"; print 1;} print 2; print 3' a12 3 hmm... Maybe I'm just an ol' C programmer used to doing things the hard way, and maybe after forgetting chomp or \n a few more times I'll reform and decide he's right... But... Globals such as $/ always have seemed "wrong" to me. The language "should" tie such attributes to the filehandles, or an object. eg: open IN,"record_separator="\n"; # or something like that How could anyone write a safe multithreaded app in Perl, with global variables in different states in different parts of the application? Of course, Perl wasn't really designed for multithreading, initially. But it supports threading, in recent versions. I imagine perl blocks other threads in many situations where globals are used (putting a mutex lock around the block or a portion of it), or creates thread-local versions of those variables ($1, $2, etc), and saves/restores state when switching threads. By the way, I noticed Activestate has a Perl for .NET. They charge a pretty penny, though ($395?) I don't suppose they give Larry any of the proceeds. I suspect Apache+mod_perl should perform as well (on Windows 2003) as ActiveState's products. Does anyone know? Why use Windows 2003, you might ask? Well, as much as I might like Linux, I wasn't confident that OLAP (decision-support/data-mining/aggregations) could be as well in Postgresql/MySQL as they could be in MS SQL Server, which includes Analysis Server for creating ROLAP/MOLAP/HOLAP aggregations. Of course, since an OLAP application has intense query requirements, and is dependent mostly upon the database, even pure CGI may be adequate for Perl. I think I'll be switching from IIS (back) to Apache, for mod_perl & AxKit (Enhydra+XMLC is also interesting, but I'm not sure I can stand Java), or for Mason: http://tldp.net/HOWTO/Apache-Overview-HOWTO-17.html Mentions Perl, Embperl, Mason, mod_perl, and axkit Mason sure has a lot of content management systems available for it (three listed on masonhq). --- (Okay, everyone can stop here and ignore my ramblings about performance...) Perl sure has a lot of ways to do things, eg: (parsing dates): 1) $purchase_stamp =~ /(\d{4})[^\d]*(\d\d)[^\d]*(\d\d)/ || $error=1; $purchase_int = $1 . $2 . $3; 2) #($pyr,$pmo,$pda)=unpack("A4xA2xA2",$purchase_stamp); #$purchase_int="$pyr$pmo$pda"; 3) #$purchase_int = substr($purchase_stamp,0,4) . # substr($purchase_stamp,5,2) . substr($purchase_stamp,8,2); I decided on (1) the regex approach (slowest), since it would work on dates which lack delimiters, should we happen across any. Timing shows substr is faster than unpack which is faster than regex. -------- An example timed command: $ time perl -le '$x="2004-12-29";for(1..1000000){$a=substr($x,0,3);$b=substr($x,5, 2);$c=substr($x,8,2);}' real 0m1.107s user 0m1.081s sys 0m0.030s And my table of results (user time): time command 1.081us $a=substr($x,0,3);$b=substr($x,5,2);$c=substr($x,8,2); 2.052us ($a,$b,$c)=unpack("A4xA2xA2",$x); 2.914us $x =~ /[^\d]*(\d{4})[^\d]*(\d\d)[^\d]*(\d\d)/;$a=$1;$b=$2;$c=$3; 2.613us $x =~ /[^\d]*(\d{4}).(\d\d).(\d\d)/; $a=$1;$b=$2;$c=$3; More interesting results: 1.081us $x =~ /[^\d]*(\d{4}).(\d\d).(\d\d)/; 1.612us $x =~ /[^\d]*(\d{4}).(\d\d).(\d\d)/;($a,$b,$c)=("2004","12","29"); 2.613us $x =~ /[^\d]*(\d{4}).(\d\d).(\d\d)/;($a,$b,$c)=($1,$2,$3) It seems that retrieving captured matches takes some time. Perhaps each retrieval calls substr, but the difference is actually slower than 3 substr's and assignments (first command), so maybe perl is doing something like optimizing out the whole (meaningless) regex. Assignment to a variable from any of $1, $2 or $3 takes 0.66 usec, so I imagine. Assignment of ($a,$b,$c)=("2004","12","29") takes much less time than ($a,$b,$c)=($1,$2,$3), so the actual assignment is relatively time-consuming for some reason. Well, back to optimizing stored procedures and ColdFusion... From andrew at sweger.net Sat Feb 21 16:56:28 2004 From: andrew at sweger.net (Andrew Sweger) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: talk proposal: Perl debugger intro In-Reply-To: <20040221224122.GA42295@alexis.mi.celestial.com> Message-ID: On Sat, 21 Feb 2004, Bill Campbell wrote: > On Sat, Feb 21, 2004, Andrew Sweger wrote: > >I was digging through my archive of SPUG mail and came across someone > >preaching about the goodness of the Perl debugger. Have we already had a > >presentation on this recently? Is there interest in having a live walk > >through with the debugger (as an intro to how it can save your butt and > >sanity)? I'm willing (and I need the practice). > > Perhaps with some discussion of using the debugger under the > graphic ``ddd'' tool? Well, I've never actually used any of Perl's graphical debuggers. That might make for an interesting challenge. But I prefer to get folks started on the bare metal, so to speak, where things are really happening. Maybe I could make the last half cover using ddd (assuming I get it working okay). -- Andrew B. Sweger -- The great thing about multitasking is that several things can go wrong at once. From sthoenna at efn.org Sun Feb 22 01:03:00 2004 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: using -l, benchmarking perl, $1 overhead, etc. In-Reply-To: References: Message-ID: <20040222065942.GA2860@efn.org> On Sat, Feb 21, 2004 at 02:45:45PM -0800, "Aaron W. West" wrote: > Is there a perl variable to control "-l"? It just seems unnatural to rely on > #perl -l to set the option. I almost always use -l in one-liners (for convenience), and almost never otherwise. -l does two things; one is adding an implicit chomp to the line reading loop created by -n or -p, for which there is no variable substitue. The other is setting $\, which you can do manually as well. Its setting $\ that is likely to mess up any module/function that prints and doesn't expect $\ to be set. Sometimes -l will persist in a script that started out as a one-liner, but by the time its grown to a couple dozen lines I usually end up ripping it out. > I suppose the solution is the use of local for $/ or $\ in those > modules/functions that need it, and designing all modules to be careful not > to be sensitive to the -l setting. I'll admit, it gets mildly tedious trying > to remember to put "\n" at the end of every "print", but what if I want > somewhere to print without a "\n". I know I can use local in a block: > > $ perl -le '{local ($\)=""; print "a"; print 1;} print 2; print 3' > > a12 > > 3 > > hmm... > > Maybe I'm just an ol' C programmer used to doing things the hard way, and > maybe after forgetting chomp or \n a few more times I'll reform and decide > he's right... Well, since you are an ol' C programmer, I will note that switching to printf instead of print causes $\ not to be automatically used: $ perl -le 'printf "a"; printf "1"; print 2; print 3' a12 3 > Globals such as $/ always have seemed "wrong" to me. The language "should" > tie such attributes to the filehandles, or an object. eg: > > open IN," > IN->record_separator="\n"; # or something like that Not sure why $\ wasn't made per filehandle (like $., $%, $=, $^, $|), but it's too late to change it now. It would have made sense to me. > How could anyone write a safe multithreaded app in Perl, with global > variables in different states in different parts of the application? Of > course, Perl wasn't really designed for multithreading, initially. But it > supports threading, in recent versions. I imagine perl blocks other threads > in many situations where globals are used (putting a mutex lock around the > block or a portion of it), or creates thread-local versions of those > variables ($1, $2, etc), and saves/restores state when switching threads. 5005threads shared globals, ithreads makes everything thread-local. > (Okay, everyone can stop here and ignore my ramblings about performance...) > > Perl sure has a lot of ways to do things, eg: (parsing dates): > > 1) > > $purchase_stamp =~ /(\d{4})[^\d]*(\d\d)[^\d]*(\d\d)/ || $error=1; > > $purchase_int = $1 . $2 . $3; > > 2) > > #($pyr,$pmo,$pda)=unpack("A4xA2xA2",$purchase_stamp); > > #$purchase_int="$pyr$pmo$pda"; > > 3) > > #$purchase_int = substr($purchase_stamp,0,4) . > > # substr($purchase_stamp,5,2) . substr($purchase_stamp,8,2); > > I decided on (1) the regex approach (slowest), since it would work on dates > which lack delimiters, should we happen across any. > > Timing shows substr is faster than unpack which is faster than regex. Those aren't really equivalent. Your regex is looking for a matching substring, not checking the whole string. Try: /^(\d{4})\D*(\d\d)\D*(\d\d)\z/ (note the ^ and \z anchors, and \D (which is equivalent to [^\d]). Also, the regex is the one to use if you need error checking. > An example timed command: Use perl's Benchmark module instead: ======================================= use Benchmark qw/timethese cmpthese/; use warnings; use strict; my $purchase_stamp = "2004-02-21"; my %test; $test{regex} = sub { my $purchase_int; if ($purchase_stamp =~ /(\d{4})[^\d]*(\d\d)[^\d]*(\d\d)/) { $purchase_int = $1.$2.$3; } $purchase_int; }; $test{regex2} = sub { my $purchase_int; if ($purchase_stamp =~ /^(\d{4})\D*(\d\d)\D*(\d\d)\z/) { $purchase_int = $1.$2.$3; } $purchase_int; }; $test{transliterate} = sub { my $purchase_int; ($purchase_int = $purchase_stamp) =~ tr/0-9//cd; $purchase_int; }; $test{unpck} = sub { my $purchase_int; my ($pyr,$pmo,$pda)=unpack("A4xA2xA2",$purchase_stamp); $purchase_int = $pyr.$pmo.$pda; $purchase_int; }; $test{unpck2} = sub { my $purchase_int; $purchase_int = join "", unpack("A4xA2xA2",$purchase_stamp); $purchase_int; }; $test{sbstr} = sub { my $purchase_int; $purchase_int = substr($purchase_stamp,0,4) . substr($purchase_stamp,5,2) . substr($purchase_stamp,8,2); $purchase_int; }; # test for correct results: for (keys %test) { &{$test{$_}} == 20040221 or die "bad result for $_\n"; } my $results = timethese(-5, \%test); cmpthese($results); ==================================================== my output: Benchmark: running regex, regex2, sbstr, transliterate, unpck, unpck2 for at least 5 CPU seconds... regex: 4 wallclock secs ( 5.16 usr + 0.00 sys = 5.16 CPU) @ 104373.98/s (n=538361) regex2: 6 wallclock secs ( 5.01 usr + 0.00 sys = 5.01 CPU) @ 114378.87/s (n=572695) sbstr: 6 wallclock secs ( 5.33 usr + 0.00 sys = 5.33 CPU) @ 562793.73/s (n=2998565) transliterate: 7 wallclock secs ( 6.34 usr + 0.00 sys = 6.34 CPU) @ 987529.03/s (n=6258959) unpck: 6 wallclock secs ( 5.19 usr + 0.00 sys = 5.19 CPU) @ 69612.76/s (n=361151) unpck2: 6 wallclock secs ( 5.40 usr + 0.00 sys = 5.40 CPU) @ 80283.62/s (n=433371) Rate unpck unpck2 regex regex2 sbstr transliterate unpck 69613/s -- -13% -33% -39% -88% -93% unpck2 80284/s 15% -- -23% -30% -86% -92% regex 104374/s 50% 30% -- -9% -81% -89% regex2 114379/s 64% 42% 10% -- -80% -88% sbstr 562794/s 708% 601% 439% 392% -- -43% transliterate 987529/s 1319% 1130% 846% 763% 75% -- ================================================== When benchmarking, make sure you are using lexicals and/or global variables just as your real code would--it can make a significant difference. There are also often significant differences in benchmarks between perl versions or between threaded and non-threaded perls. > More interesting results: > > 1.081us $x =~ /[^\d]*(\d{4}).(\d\d).(\d\d)/; > > 1.612us $x =~ /[^\d]*(\d{4}).(\d\d).(\d\d)/;($a,$b,$c)=("2004","12","29"); > > 2.613us $x =~ /[^\d]*(\d{4}).(\d\d).(\d\d)/;($a,$b,$c)=($1,$2,$3) > > It seems that retrieving captured matches takes some time. Perhaps each > retrieval calls substr, but the difference is actually slower than 3 > substr's and assignments (first command), so maybe perl is doing something > like optimizing out the whole (meaningless) regex. Assignment to a variable > from any of $1, $2 or $3 takes 0.66 usec, so I imagine. Assignment of > ($a,$b,$c)=("2004","12","29") takes much less time than > ($a,$b,$c)=($1,$2,$3), so the actual assignment is relatively time-consuming > for some reason. All magic variables have to go through extra code when their values are read. They also need to do an extra copy of the value (and may have to allocate a buffer to put it in). >From reading through your post, I get the sense you would be a prime candidate for joining http://perlmonks.org From sthoenna at efn.org Sun Feb 22 01:03:17 2004 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: axkit In-Reply-To: References: Message-ID: <20040222070317.GB2860@efn.org> On Sat, Feb 21, 2004 at 02:45:45PM -0800, "Aaron W. West" wrote: > By the way, I noticed Activestate has a Perl for .NET. They charge a pretty > penny, though ($395?) I don't suppose they give Larry any of the proceeds. Don't know if they contribute monetarily to perl development, but they dontate use of their servers for the perl source repository. IIRC, they have in the past also offered to try to work out arrangements for a day job for a prospective perl pumpking. And they fix a goodly number of perl bugs, not all of them win32 specific. From lee at colleton.net Tue Feb 24 14:06:14 2004 From: lee at colleton.net (Lee Colleton) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: Re: Missed you at SPUG. Next time? In-Reply-To: References: <1074672106.2076.180.camel@raven> <1076181472.4757.109.camel@raven> Message-ID: <1077653174.1299.33.camel@raven> On Wed, 2004-02-18 at 19:32, Michael R.Wolf wrote: > Lee, > > Thanks for the invitation. Sorry I didn't make it -- I was working at > the Museum of Flight. And as you can tell by the timing, I've been > swamped lately. > > I was hoping to see you at SPUG last night. I'd like to continue some > of the discussions we had about your Perl involvement. The next > meeting is going to be a series of lightning talks -- 5-10 minutes > each. You had mentined that you'd be interested in sharing some of the > work you've done. Interested? > > Perlishly, > Michael I've suggested[1] meeting at Espresso Vivace Roasteria next month. I'm willing to speak about my Linux in the Library project for an easily accessible CD Archive. I'm writing the program now and hope to have it at 0.1 by the end of the month. Vivace is a great hangout. I stop by there often so I can sign SPUG up for the meeting spot as soon as they start booking March. -- Lee Colleton [1]http://spugwiki.perlocity.org/index.cgi?PotentialMeetingLocations -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://mail.pm.org/pipermail/spug-list/attachments/20040224/eeb4d8c4/attachment.bin From dan at concolor.org Thu Feb 26 17:15:41 2004 From: dan at concolor.org (Dan Sabath) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: Multiple Server Management...anyone recall? Message-ID: <20040226231541.GC28804@kell.fairehosting.com> Hey guys, Does anyone recall a talk sometime last year about remote server management and keeping inventory of whats installed on which boxen? For some reason I keep thinking the speaker was from Utah but I'm drawing a blank on the rest. Thanks for the help with my senior moment. Dan From paul_farrall at yahoo.com Fri Feb 27 17:41:03 2004 From: paul_farrall at yahoo.com (Paul Farrall) Date: Mon Aug 2 21:37:16 2004 Subject: SPUG: Multiple Server Management...anyone recall? In-Reply-To: <20040226231541.GC28804@kell.fairehosting.com> Message-ID: <20040227234103.64785.qmail@web10806.mail.yahoo.com> That would be me. This is what I talked about: http://www.brains2bytes.com/alist/ I haven't done a whole lot of work on this program over the last 9 months. I started working at AT&T Wireless shortly after I moved here and they have been keeping me very busy managing lots and lots of servers. I have a bunch of updates, I just need to clean them up and put them out on the web site. Feel free to email me directly if you have any questions. Paul --- Dan Sabath wrote: > > Hey guys, > > Does anyone recall a talk sometime last year about remote server > management and keeping inventory of whats installed on which boxen? > For some reason I keep thinking the speaker was from Utah but I'm > drawing a blank on the rest. > > Thanks for the help with my senior moment. > > Dan > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, Location Unknown > WEB PAGE: http://www.seattleperl.org ===== Paul Farrall h: (206)985-8307 c: (206)390-1656 e: paul_farrall@yahoo.com