From andrew at sweger.net Wed Mar 4 15:28:58 2009 From: andrew at sweger.net (Andrew Sweger) Date: Wed, 4 Mar 2009 15:28:58 -0800 (PST) Subject: SPUG: Call for Mentors - Google Summer of Code Message-ID: Hey SPUGers, Are you interested in participating as a mentor for The Perl Foundation in this year's Google Summer of Code? Jonathan Leto has a signup form ready for those who would like to indicate their interest in offering their availability. Note, this is also includes The Parrot Foundation. Deadlines are coming soon! Sign up here: http://bit.ly/Hht5E Note that he is just asking if you are *interested* in doing so. The Perl Foundation will not know if it is a part of GSoC 2009 until Google picks which organizations will be involved on 18 March. For more information, please see the following link or mail Jonathan. http://leto.net/dukeleto.pl/2009/03/gsoc-2009-mentor-signup-form-go.html -- Andrew B. Sweger -- The great thing about multitasking is that several things can go wrong at once. From kirsch.phil at gmail.com Mon Mar 16 05:36:03 2009 From: kirsch.phil at gmail.com (Phil Kirsch) Date: Mon, 16 Mar 2009 05:36:03 -0700 Subject: SPUG: Net::SFTP Connection Message-ID: <49BE47B3.1090508@gmail.com> #!/usr/bin/perl use strict; use Net::SFTP; my $user = "IPX0611B0811_ACI_DATA"; my $host = 'SFTP.impaxlabs.com'; my $pass = "impax"; my $logn = "$user" . "\@" . $host; my $sftp = Net::SFTP->new("$logn", password=>"$pass", debug=>1); print ("Done\.\n"); *The results come out like this:* # ./transfer.pl datafax3: Reading configuration data /root/.ssh/config datafax3: Reading configuration data /etc/ssh_config datafax3: Allocated local port 1023. datafax3: Connecting to IPX0611B0811_ACI_DATA at SFTP.impaxlabs.com , port 22. datafax3: Remote protocol version 2.0, remote software version OpenSSH_5.1 datafax3: Net::SSH::Perl Version 1.34, protocol version 2.0. .atafax3: No compat match: OpenSSH_5.1 datafax3: Connection established. datafax3: Sent key-exchange init (KEXINIT), wait response. datafax3: Algorithms, c->s: 3des-cbc hmac-sha1 none datafax3: Algorithms, s->c: 3des-cbc hmac-sha1 none datafax3: Entering Diffie-Hellman Group 1 key exchange. datafax3: Sent DH public key, waiting for reply. *At this point there is a long pause, followed 15 or 20 seconds later by:* Connection closed by remote host. at /usr/perl5/site_perl/5.8.4/Net/SSH/Perl/Kex/DH1.pm line 41 Because the word "Done" does not print, I am quite certain that the script is simply dying at this point. Does anyone have any ideas for troubleshooting this problem? Thanks! Phil Kirsch -------------- next part -------------- An HTML attachment was scrubbed... URL: From cmeyer at helvella.org Mon Mar 16 08:31:55 2009 From: cmeyer at helvella.org (Colin Meyer) Date: Mon, 16 Mar 2009 08:31:55 -0700 Subject: SPUG: March 2009 Seattle Perl Users Group (SPUG) Meeting Message-ID: <20090316153155.GA10982@infula.helvella.org> NOTE: This meeting is tomorrow. March 2009 Seattle Perl Users Group (SPUG) Meeting ==================================================== Topic: Parrot 1.0 Speaker: Jerry Gay Meeting Date: Tuesday, 17 March 2009 Meeting Time: 6:30 - 8:30 p.m. Location: Marchex - 4th & Pine Cost: Admission is free and open to the public Info: http://seattleperl.org/ ==================================================== Tuesday, March 17, is the next meeting of the THE SEATTLE PERL USERS GROUP. This Month's Talk The Parrot Virtual Machine team has been hard at work towards their landmark release of Parrot version 1.0. More info here: http://www.parrot.org/ About Jerry Gay Jerry is a technology consultant, project team member for Rakudo Perl and the Parrot virtual machine, an active participant in the Perl 6 design process, and the founder of Rakudo Consulting Group. He is comfortable thinking and coding in Perl 5 & 6, Parrot assembly, and C, and both managing and working with a distributed group of hackers on a large project with a heterogeneous, complex codebase. Jerry is also an expert on deploying, customizing, and managing enterprise change management tools such as Serena Dimensions. Pre-Meeting ================ If you are so inclined, please come to the pre-meeting at the Elephant & Castle pub on 5th & Union. We'll be there from 5-6:19PM. Meeting Location ================ Pizza and Beer will be provided at the meeting. Marchex 413 Pine St, Suite 500 Seattle, WA 98101 The building is just south of Westlake Center. Enter on 4th Avenue, near Pine street. The entry is near the Dog In The Park hotdog stand. http://www.baylis.org/static/marchex.png Due to all of the shopping around us there is plenty of parking available in garages, but it can be hard to find street parking in the evening. See you there! From twists at gmail.com Mon Mar 16 09:01:49 2009 From: twists at gmail.com (Joshua ben Jore) Date: Mon, 16 Mar 2009 09:01:49 -0700 Subject: SPUG: Net::SFTP Connection In-Reply-To: <49BE47B3.1090508@gmail.com> References: <49BE47B3.1090508@gmail.com> Message-ID: On Mon, Mar 16, 2009 at 5:36 AM, Phil Kirsch wrote: > #!/usr/bin/perl > > use strict; > use Net::SFTP; > > my $user = "IPX0611B0811_ACI_DATA"; > my $host = 'SFTP.impaxlabs.com'; > my $pass = "impax"; > my $logn = "$user" . "\@" . $host; > my $sftp = Net::SFTP->new("$logn", password=>"$pass", debug=>1); > print ("Done\.\n"); > > The results come out like this: > > # ./transfer.pl > datafax3: Reading configuration data /root/.ssh/config > datafax3: Reading configuration data /etc/ssh_config > datafax3: Allocated local port 1023. > datafax3: Connecting to IPX0611B0811_ACI_DATA at SFTP.impaxlabs.com, port 22. > datafax3: Remote protocol version 2.0, remote software version OpenSSH_5.1 > datafax3: Net::SSH::Perl Version 1.34, protocol version 2.0. > .atafax3: No compat match: OpenSSH_5.1 > datafax3: Connection established. > datafax3: Sent key-exchange init (KEXINIT), wait response. > datafax3: Algorithms, c->s: 3des-cbc hmac-sha1 none > datafax3: Algorithms, s->c: 3des-cbc hmac-sha1 none > datafax3: Entering Diffie-Hellman Group 1 key exchange. > datafax3: Sent DH public key, waiting for reply. > > At this point there is a long pause, followed 15 or 20 seconds later by: > Connection closed by remote host. at > /usr/perl5/site_perl/5.8.4/Net/SSH/Perl/Kex/DH1.pm line 41 > > Because the word "Done" does not print, I am quite certain that the script > is simply dying at this point. Does anyone have any ideas for > troubleshooting this problem? Yes, but with the caveat that this is just basic *NIX debugging and I nothing about the actual perl module. - Tried following the conversation with tcpdump? - Firewalls preventing in or outbound communication? - strace to see if somethink hinky shows up? - try telnetting to the ssh server to see if it shows you its header and it responds to the "garbage" you type back to it Josh From breno at rio.pm.org Mon Mar 16 09:24:46 2009 From: breno at rio.pm.org (breno) Date: Mon, 16 Mar 2009 13:24:46 -0300 Subject: SPUG: Net::SFTP Connection In-Reply-To: References: <49BE47B3.1090508@gmail.com> Message-ID: On Mon, Mar 16, 2009 at 9:36 AM, Phil Kirsch wrote: > > At this point there is a long pause, followed 15 or 20 seconds later by: > Connection closed by remote host. at > /usr/perl5/site_perl/5.8.4/Net/SSH/Perl/Kex/DH1.pm line 41 > > Because the word "Done" does not print, I am quite certain that the script > is simply dying at this point. Does anyone have any ideas for > troubleshooting this problem? > Usually, messages in the format "$string at $file line $N" are fatal errors indications suggesting what went wrong ($string), at which file ($file) in the line ($N). As the only line in your code doing something other than passing strings to variables is your call to Net::SFTP->new(), it's a safe bet something went wrong over there. Since the dying message clearly states "Connection closed by remote host", that's most likely what happened (interrupting the diffie-hellman key exchange and causing a fatal error as you cannot use an SFTP connection when there is none), so you should probably try to connect to another (maybe local) server, to eliminate some variables to your problem. Joshua's tips will most likely be very useful in further troubleshooting the problem (which appears to be on the infrastructure rather then on Net::SFTP itself). If you feel you should be debugging the module, you could browse the source code via CPAN's website or your local copy, but a good place to start is to view a simple trace of your problem by doing something like: # perl -MCarp::Always transfer.pl instead of just "./transfer.pl". Of course, you'll need to have Carp::Always installed on your system. Cheers, -b From byoung at speakeasy.org Mon Mar 16 09:41:02 2009 From: byoung at speakeasy.org (Bradley Young) Date: Mon, 16 Mar 2009 09:41:02 -0700 Subject: SPUG: Net::SFTP Connection Message-ID: <33f2l4whiq9mna8so0mta2r4.1237221662010@email.android.com> Throw the openssh server in debug mode, and look at the logs. My guess would be that the server is unwilling to establish a connection because it can't negotiate a cipher that it likes (or something similar). Bradley Joshua ben Jore wrote: >On Mon, Mar 16, 2009 at 5:36 AM, Phil Kirsch wrote: >> #!/usr/bin/perl >> >> use strict; >> use Net::SFTP; >> >> my $user = "IPX0611B0811_ACI_DATA"; >> my $host = 'SFTP.impaxlabs.com'; >> my $pass = "impax"; >> my $logn = "$user" . "\@" . $host; >> my $sftp = Net::SFTP->new("$logn", password=>"$pass", debug=>1); >> print ("Done\.\n"); >> >> The results come out like this: >> >> # ./transfer.pl >> datafax3: Reading configuration data /root/.ssh/config >> datafax3: Reading configuration data /etc/ssh_config >> datafax3: Allocated local port 1023. >> datafax3: Connecting to IPX0611B0811_ACI_DATA at SFTP.impaxlabs.com, port 22. >> datafax3: Remote protocol version 2.0, remote software version OpenSSH_5.1 >> datafax3: Net::SSH::Perl Version 1.34, protocol version 2.0. >> .atafax3: No compat match: OpenSSH_5.1 >> datafax3: Connection established. >> datafax3: Sent key-exchange init (KEXINIT), wait response. >> datafax3: Algorithms, c->s: 3des-cbc hmac-sha1 none >> datafax3: Algorithms, s->c: 3des-cbc hmac-sha1 none >> datafax3: Entering Diffie-Hellman Group 1 key exchange. >> datafax3: Sent DH public key, waiting for reply. >> >> At this point there is a long pause, followed 15 or 20 seconds later by: >> Connection closed by remote host. at >> /usr/perl5/site_perl/5.8.4/Net/SSH/Perl/Kex/DH1.pm line 41 >> >> Because the word "Done" does not print, I am quite certain that the script >> is simply dying at this point. Does anyone have any ideas for >> troubleshooting this problem? > >Yes, but with the caveat that this is just basic *NIX debugging and I >nothing about the actual perl module. > >- Tried following the conversation with tcpdump? >- Firewalls preventing in or outbound communication? >- strace to see if somethink hinky shows up? >- try telnetting to the ssh server to see if it shows you its header >and it responds to the "garbage" you type back to it > >Josh >_____________________________________________________________ >Seattle Perl Users Group Mailing List > POST TO: spug-list at pm.org >SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays > WEB PAGE: http://seattleperl.org/ -- Sent from my Android phone with K-9. Please excuse my brevity. From paul at goracke.org Mon Mar 16 09:49:08 2009 From: paul at goracke.org (Paul Goracke) Date: Mon, 16 Mar 2009 09:49:08 -0700 Subject: SPUG: Net::SFTP Connection In-Reply-To: <49BE47B3.1090508@gmail.com> References: <49BE47B3.1090508@gmail.com> Message-ID: On Mar 16, 2009, at 5:36 AM, Phil Kirsch wrote: > my $logn = "$user" . "\@" . $host; > my $sftp = Net::SFTP->new("$logn", password=>"$pass", debug=>1); > I haven't used Net::SFTP before, but is "user at host" a valid first param? The POD looks like the first param should simply be $host, and $user should be passed in the trailing hash with the key 'user'. > At this point there is a long pause, followed 15 or 20 seconds later > by: > > Connection closed by remote host. at /usr/perl5/site_perl/5.8.4/Net/ > SSH/Perl/Kex/DH1.pm line 41 > > Because the word "Done" does not print, I am quite certain that the > script is simply dying at this point. Does anyone have any ideas for > troubleshooting this problem? I usually encounter these ssh-related "long pause, then disconnect" when the auth is invalid, or in bizarre cases when the remote host can't do reverse DNS against the script host. First, try removing the script and module from the equation: Can you make the connection manually from the script host to remote host? Second, umm...not sure, many paths. pg From cjac at colliertech.org Mon Mar 16 09:59:19 2009 From: cjac at colliertech.org (C.J. Adams-Collier) Date: Mon, 16 Mar 2009 09:59:19 -0700 Subject: SPUG: Net::SFTP Connection In-Reply-To: <49BE47B3.1090508@gmail.com> References: <49BE47B3.1090508@gmail.com> Message-ID: <73ac667f0903160959i33b66af6k84ed02ff25fab3a0@mail.gmail.com> Wait, I misread :) Have you tried using scp directly to verify that all works in a more simple environment? On Mon, Mar 16, 2009 at 5:36 AM, Phil Kirsch wrote: > #!/usr/bin/perl > > use strict; > use Net::SFTP; > > my $user = "IPX0611B0811_ACI_DATA"; > my $host = 'SFTP.impaxlabs.com'; > my $pass = "impax"; > my $logn = "$user" . "\@" . $host; > my $sftp = Net::SFTP->new("$logn", password=>"$pass", debug=>1); > print ("Done\.\n"); > > *The results come out like this:* > > # ./transfer.pl > datafax3: Reading configuration data /root/.ssh/config > datafax3: Reading configuration data /etc/ssh_config > datafax3: Allocated local port 1023. > datafax3: Connecting to IPX0611B0811_ACI_DATA at SFTP.impaxlabs.com, port 22. > datafax3: Remote protocol version 2.0, remote software version OpenSSH_5.1 > datafax3: Net::SSH::Perl Version 1.34, protocol version 2.0. > .atafax3: No compat match: OpenSSH_5.1 > datafax3: Connection established. > datafax3: Sent key-exchange init (KEXINIT), wait response. > datafax3: Algorithms, c->s: 3des-cbc hmac-sha1 none > datafax3: Algorithms, s->c: 3des-cbc hmac-sha1 none > datafax3: Entering Diffie-Hellman Group 1 key exchange. > datafax3: Sent DH public key, waiting for reply. > > *At this point there is a long pause, followed 15 or 20 seconds later by:* > Connection closed by remote host. at > /usr/perl5/site_perl/5.8.4/Net/SSH/Perl/Kex/DH1.pm line 41 > Because the word "Done" does not print, I am quite certain that the script > is simply dying at this point. Does anyone have any ideas for > troubleshooting this problem? > > Thanks! > > Phil Kirsch > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list at pm.org > SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays > WEB PAGE: http://seattleperl.org/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cxreg at pobox.com Mon Mar 16 11:09:32 2009 From: cxreg at pobox.com (Dave O) Date: Mon, 16 Mar 2009 11:09:32 -0700 (PDT) Subject: SPUG: Net::SFTP Connection In-Reply-To: References: <49BE47B3.1090508@gmail.com> Message-ID: If it turns out to be the DNS issue, you may able to solve it by turning off GSSAPIAuthentication in sshd_config On Mon, 16 Mar 2009, Paul Goracke wrote: > > On Mar 16, 2009, at 5:36 AM, Phil Kirsch wrote: > >> my $logn = "$user" . "\@" . $host; >> my $sftp = Net::SFTP->new("$logn", password=>"$pass", debug=>1); >> > I haven't used Net::SFTP before, but is "user at host" a valid first param? The > POD looks like the first param should simply be $host, and $user should be > passed in the trailing hash with the key 'user'. >> At this point there is a long pause, followed 15 or 20 seconds later by: >> >> Connection closed by remote host. at >> /usr/perl5/site_perl/5.8.4/Net/SSH/Perl/Kex/DH1.pm line 41 >> >> Because the word "Done" does not print, I am quite certain that the script >> is simply dying at this point. Does anyone have any ideas for >> troubleshooting this problem? > > I usually encounter these ssh-related "long pause, then disconnect" when the > auth is invalid, or in bizarre cases when the remote host can't do reverse > DNS against the script host. > > First, try removing the script and module from the equation: Can you make the > connection manually from the script host to remote host? > > Second, umm...not sure, many paths. > > pg > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list at pm.org > SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays > WEB PAGE: http://seattleperl.org/ > > From pdarley at kinesis-cem.com Fri Mar 20 12:35:40 2009 From: pdarley at kinesis-cem.com (Peter Darley) Date: Fri, 20 Mar 2009 12:35:40 -0700 Subject: SPUG: Confusing behaivior with exported variables Message-ID: <000001c9a993$0d515350$27f3f9f0$@com> Folks, It's been a long time since I've bugged y'all with a stupid question, but I've got a new one so I'm hoping someone can help me out. The problem is with exporting variables, and having them available to both a script that uses the module exporting the variable, and the module it's self. I have two modules, one on a machine at work and one on a machine at home. Both are doing something that looks super similar to me. At work I have: package Neo::Web; use ... use CGI qw/:standard/; use CGI::Cookie; use Apache::DBI; use Apache::Session::Postgres; use Data::Dumper; BEGIN { use Exporter (); @ISA = qw(Exporter); @EXPORT = qw(%Session $SessionID &TieSession &UntieSession ... ); ConnectDB(DBName=>'Sessions'); } sub TieSession { tie %Session, 'Apache::Session::Postgres', $SessionID, {Handle=>$Neo::DB::Sessions, Commit=>0}; $SessionID = $Session{_session_id}; } The scripts using this package can get at %Session, and this module can get at %Session. They are the same variable and have the same contents. At home I have: package Darley::Supers; use ... ; use Data::Dumper; BEGIN { my (%CurrentUser); use Exporter (); @ISA = qw(Exporter); @EXPORT = qw(%CurrentUser &Power &Challenge &GetUser &GetOrg &GetCity); } sub SetCurrentOrgSetting { my (%Args) = @_; # Args: Setting = Setting to store # Value = Value to store StoreOrgSetting(OrgID=>$CurrentUser{Org}{org_id}, Setting=>$Args{Setting}, Value=>$Args{Value}); $CurrentUser{Org}{Settings}{$Args{Setting}} = $Args{Value}; return 1; } And the script using this module can get at %CurrentUser, but when this package uses it, it's empty. I can't figure out why the exported hash is the same in the first example, but has two different values in the second. Thanks for any help, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.mertel at yahoo.com Fri Mar 20 13:36:48 2009 From: mark.mertel at yahoo.com (Mark Mertel) Date: Fri, 20 Mar 2009 13:36:48 -0700 (PDT) Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <000001c9a993$0d515350$27f3f9f0$@com> References: <000001c9a993$0d515350$27f3f9f0$@com> Message-ID: <413294.18913.qm@web50110.mail.re2.yahoo.com> Not sure, and this may be a stupid answer, but could it be you didn't tie the second variable? Its hard for me to?debug?out of context. ?--- Mark Mertel 206.441.4663 mark.mertel at yahoo.com http://www.linkedin.com/in/markmertel http://www.seattlejobs.com/13147468 ________________________________ From: Peter Darley To: spug-list at pm.org Sent: Friday, March 20, 2009 12:35:40 PM Subject: SPUG: Confusing behaivior with exported variables Folks, ? ??????????????? It?s been a long time since I?ve bugged y?all with a stupid question, but I?ve got a new one so I?m hoping someone can help me out. ? ??????????????? The problem is with exporting variables, and having them available to both a script that uses the module exporting the variable, and the module it?s self.? I have two modules, one on a machine at work and one on a machine at home.? Both are doing something that looks super similar to me. ? ??????????????? At work I have: ? package Neo::Web; ? use ... ? use CGI qw/:standard/; use CGI::Cookie; use Apache::DBI; use Apache::Session::Postgres; use Data::Dumper; ? BEGIN { ??????????????? use Exporter?? (); ??????????????? @ISA???????? = qw(Exporter); ??????????????? @EXPORT????? = qw(%Session $SessionID ??????????????????????????????????????????????? ? &TieSession &UntieSession ... ); ??????????????? ??????????????? ConnectDB(DBName=>'Sessions'); } ? sub TieSession { ??????????????? tie %Session, 'Apache::Session::Postgres', $SessionID, {Handle=>$Neo::DB::Sessions, Commit=>0}; ??????????????? $SessionID = $Session{_session_id}; } ? ??????????????? The scripts using this package can get at %Session, and this module can get at %Session.? They are the same variable and have the same contents. ? ??????????????? At home I have: ? package Darley::Supers; ? use ... ; ? use Data::Dumper; ? BEGIN { ??????????????? my (%CurrentUser); ??????????????? ??????? use Exporter?? (); ??????? @ISA???????? = qw(Exporter); ??????? @EXPORT????? = qw(%CurrentUser ??????? ??????????????????????? ??&Power &Challenge &GetUser &GetOrg &GetCity); } ? ? sub SetCurrentOrgSetting { ??????????????? my (%Args) = @_; ??????????????? # Args: Setting = Setting to store ??????????????? #???????????? Value = Value to store ??????????????? ??????????????? StoreOrgSetting(OrgID=>$CurrentUser{Org}{org_id}, Setting=>$Args{Setting}, Value=>$Args{Value}); ??????????????? $CurrentUser{Org}{Settings}{$Args{Setting}} = $Args{Value}; ??????????????? ??????????????? return 1; } ? ??????????????? And the script using this module can get at %CurrentUser, but when this package uses it, it?s empty.? I can?t figure out why the exported hash is the same in the first example, but has two different values in the second. ? Thanks for any help, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: From tyemq at cpan.org Fri Mar 20 13:00:25 2009 From: tyemq at cpan.org (Tye McQueen) Date: Fri, 20 Mar 2009 13:00:25 -0700 Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <000001c9a993$0d515350$27f3f9f0$@com> References: <000001c9a993$0d515350$27f3f9f0$@com> Message-ID: "my" and Exporter.pm don't get along. Use "our" or "use vars" (or, you can roll your own import() method that knows how to export a lexical, but that seems almost silly). Tye -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.mertel at yahoo.com Fri Mar 20 14:16:14 2009 From: mark.mertel at yahoo.com (Mark Mertel) Date: Fri, 20 Mar 2009 14:16:14 -0700 (PDT) Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <000001c9a993$0d515350$27f3f9f0$@com> References: <000001c9a993$0d515350$27f3f9f0$@com> Message-ID: <649877.61563.qm@web50107.mail.re2.yahoo.com> probably should 'use strict' as well. the first package doesn't declare the %Session hash, so it becomes global, and the second package scopes the %CurrentUser inside the BEGIN block. 'use strict' should point these things out. ?--- Mark Mertel 206.441.4663 mark.mertel at yahoo.com http://www.linkedin.com/in/markmertel http://www.seattlejobs.com/13147468 ________________________________ From: Peter Darley To: spug-list at pm.org Sent: Friday, March 20, 2009 12:35:40 PM Subject: SPUG: Confusing behaivior with exported variables Folks, ? ??????????????? It?s been a long time since I?ve bugged y?all with a stupid question, but I?ve got a new one so I?m hoping someone can help me out. ? ??????????????? The problem is with exporting variables, and having them available to both a script that uses the module exporting the variable, and the module it?s self.? I have two modules, one on a machine at work and one on a machine at home.? Both are doing something that looks super similar to me. ? ??????????????? At work I have: ? package Neo::Web; ? use ... ? use CGI qw/:standard/; use CGI::Cookie; use Apache::DBI; use Apache::Session::Postgres; use Data::Dumper; ? BEGIN { ??????????????? use Exporter?? (); ??????????????? @ISA???????? = qw(Exporter); ??????????????? @EXPORT????? = qw(%Session $SessionID ??????????????????????????????????????????????? ? &TieSession &UntieSession ... ); ??????????????? ??????????????? ConnectDB(DBName=>'Sessions'); } ? sub TieSession { ??????????????? tie %Session, 'Apache::Session::Postgres', $SessionID, {Handle=>$Neo::DB::Sessions, Commit=>0}; ??????????????? $SessionID = $Session{_session_id}; } ? ??????????????? The scripts using this package can get at %Session, and this module can get at %Session.? They are the same variable and have the same contents. ? ??????????????? At home I have: ? package Darley::Supers; ? use ... ; ? use Data::Dumper; ? BEGIN { ??????????????? my (%CurrentUser); ??????????????? ??????? use Exporter?? (); ??????? @ISA???????? = qw(Exporter); ??????? @EXPORT????? = qw(%CurrentUser ??????? ??????????????????????? ??&Power &Challenge &GetUser &GetOrg &GetCity); } ? ? sub SetCurrentOrgSetting { ??????????????? my (%Args) = @_; ??????????????? # Args: Setting = Setting to store ??????????????? #???????????? Value = Value to store ??????????????? ??????????????? StoreOrgSetting(OrgID=>$CurrentUser{Org}{org_id}, Setting=>$Args{Setting}, Value=>$Args{Value}); ??????????????? $CurrentUser{Org}{Settings}{$Args{Setting}} = $Args{Value}; ??????????????? ??????????????? return 1; } ? ??????????????? And the script using this module can get at %CurrentUser, but when this package uses it, it?s empty.? I can?t figure out why the exported hash is the same in the first example, but has two different values in the second. ? Thanks for any help, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: From pdarley at kinesis-cem.com Mon Mar 23 12:10:14 2009 From: pdarley at kinesis-cem.com (Peter Darley) Date: Mon, 23 Mar 2009 12:10:14 -0700 Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <649877.61563.qm@web50107.mail.re2.yahoo.com> References: <000001c9a993$0d515350$27f3f9f0$@com> <649877.61563.qm@web50107.mail.re2.yahoo.com> Message-ID: <005201c9abea$ff8038e0$fe80aaa0$@com> Mark and Tye, I would have sworn that I took out the my declaration in the second module. I?ll try removing that and see how it works. I usually do use strict as a default, but the first module didn?t have it so I removed it in my efforts to figure out what was going on. Thanks, Peter From: Mark Mertel [mailto:mark.mertel at yahoo.com] Sent: Friday, March 20, 2009 2:16 PM To: Peter Darley; spug-list at pm.org Subject: Re: SPUG: Confusing behaivior with exported variables probably should 'use strict' as well. the first package doesn't declare the %Session hash, so it becomes global, and the second package scopes the %CurrentUser inside the BEGIN block. 'use strict' should point these things out. --- Mark Mertel 206.441.4663 mark.mertel at yahoo.com http://www.linkedin.com/in/markmertel http://www.seattlejobs.com/13147468 _____ From: Peter Darley To: spug-list at pm.org Sent: Friday, March 20, 2009 12:35:40 PM Subject: SPUG: Confusing behaivior with exported variables Folks, It?s been a long time since I?ve bugged y?all with a stupid question, but I?ve got a new one so I?m hoping someone can help me out. The problem is with exporting variables, and having them available to both a script that uses the module exporting the variable, and the module it?s self. I have two modules, one on a machine at work and one on a machine at home. Both are doing something that looks super similar to me. At work I have: package Neo::Web; use ... use CGI qw/:standard/; use CGI::Cookie; use Apache::DBI; use Apache::Session::Postgres; use Data::Dumper; BEGIN { use Exporter (); @ISA = qw(Exporter); @EXPORT = qw(%Session $SessionID &TieSession &UntieSession ... ); ConnectDB(DBName=>'Sessions'); } sub TieSession { tie %Session, 'Apache::Session::Postgres', $SessionID, {Handle=>$Neo::DB::Sessions, Commit=>0}; $SessionID = $Session{_session_id}; } The scripts using this package can get at %Session, and this module can get at %Session. They are the same variable and have the same contents. At home I have: package Darley::Supers; use ... ; use Data::Dumper; BEGIN { my (%CurrentUser); use Exporter (); @ISA = qw(Exporter); @EXPORT = qw(%CurrentUser &Power &Challenge &GetUser &GetOrg &GetCity); } sub SetCurrentOrgSetting { my (%Args) = @_; # Args: Setting = Setting to store # Value = Value to store StoreOrgSetting(OrgID=>$CurrentUser{Org}{org_id}, Setting=>$Args{Setting}, Value=>$Args{Value}); $CurrentUser{Org}{Settings}{$Args{Setting}} = $Args{Value}; return 1; } And the script using this module can get at %CurrentUser, but when this package uses it, it?s empty. I can?t figure out why the exported hash is the same in the first example, but has two different values in the second. Thanks for any help, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.mertel at yahoo.com Mon Mar 23 15:24:57 2009 From: mark.mertel at yahoo.com (Mark Mertel) Date: Mon, 23 Mar 2009 15:24:57 -0700 (PDT) Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <005201c9abea$ff8038e0$fe80aaa0$@com> References: <000001c9a993$0d515350$27f3f9f0$@com> <649877.61563.qm@web50107.mail.re2.yahoo.com> <005201c9abea$ff8038e0$fe80aaa0$@com> Message-ID: <407473.78902.qm@web50107.mail.re2.yahoo.com> Globals are not recommended. You?could make them package variables and declare them with 'my' or 'our', and then access them using the package name $Neo::Web::Session, or $Darley::Supers::CurrentUser when?from outside the package. Personally, I'd make an object and fetch them using an accessor,?i.e. my $web =?new Neo::Web; $web->session; package Neo::Web; sub new { ... } sub session { ... }?--- Mark Mertel 206.441.4663 mark.mertel at yahoo.com http://www.linkedin.com/in/markmertel http://www.seattlejobs.com/13147468 ________________________________ From: Peter Darley To: Mark Mertel ; spug-list at pm.org Sent: Monday, March 23, 2009 12:10:14 PM Subject: RE: SPUG: Confusing behaivior with exported variables Mark and Tye, ? ??????????????? I would have sworn that I took out the my declaration in the second module.? I?ll try removing that and see how it works. ??????????????? I usually do use strict as a default, but the first module didn?t have it so I removed it in my efforts to figure out what was going on. ? Thanks, Peter ? From:Mark Mertel [mailto:mark.mertel at yahoo.com] Sent: Friday, March 20, 2009 2:16 PM To: Peter Darley; spug-list at pm.org Subject: Re: SPUG: Confusing behaivior with exported variables ? probably should 'use strict' as well. the first package doesn't declare the %Session hash, so it becomes global, and the second package scopes the %CurrentUser inside the BEGIN block. 'use strict' should point these things out. ? --- Mark Mertel 206.441.4663 mark.mertel at yahoo.com http://www.linkedin.com/in/markmertel http://www.seattlejobs.com/13147468 ? ? ________________________________ From:Peter Darley To: spug-list at pm.org Sent: Friday, March 20, 2009 12:35:40 PM Subject: SPUG: Confusing behaivior with exported variables Folks, ? ??????????????? It?s been a long time since I?ve bugged y?all with a stupid question, but I?ve got a new one so I?m hoping someone can help me out. ? ??????????????? The problem is with exporting variables, and having them available to both a script that uses the module exporting the variable, and the module it?s self.? I have two modules, one on a machine at work and one on a machine at home.? Both are doing something that looks super similar to me. ? ??????????????? At work I have: ? package Neo::Web; ? use ... ? use CGI qw/:standard/; use CGI::Cookie; use Apache::DBI; use Apache::Session::Postgres; use Data::Dumper; ? BEGIN { ??????????????? use Exporter?? (); ??????????????? @ISA???????? = qw(Exporter); ??????????????? @EXPORT????? = qw(%Session $SessionID ??????????????????????????????????????????????? ? &TieSession &UntieSession ... ); ??????????????? ??????????????? ConnectDB(DBName=>'Sessions'); } ? sub TieSession { ??????????????? tie %Session, 'Apache::Session::Postgres', $SessionID, {Handle=>$Neo::DB::Sessions, Commit=>0}; ??????????????? $SessionID = $Session{_session_id}; } ? ??????????????? The scripts using this package can get at %Session, and this module can get at %Session.? They are the same variable and have the same contents. ? ??????????????? At home I have: ? package Darley::Supers; ? use ... ; ? use Data::Dumper; ? BEGIN { ??????????????? my (%CurrentUser); ??????????????? ??????? use Exporter?? (); ??????? @ISA???????? = qw(Exporter); ??????? @EXPORT????? = qw(%CurrentUser ??????? ??????????????????????? ??&Power &Challenge &GetUser &GetOrg &GetCity); } ? ? sub SetCurrentOrgSetting { ??????????????? my (%Args) = @_; ??????????????? # Args: Setting = Setting to store ??????????????? #???????????? Value = Value to store ??????????????? ??????????????? StoreOrgSetting(OrgID=>$CurrentUser{Org}{org_id}, Setting=>$Args{Setting}, Value=>$Args{Value}); ??????????????? $CurrentUser{Org}{Settings}{$Args{Setting}} = $Args{Value}; ??????????????? ??????????????? return 1; } ? ??????????????? And the script using this module can get at %CurrentUser, but when this package uses it, it?s empty.? I can?t figure out why the exported hash is the same in the first example, but has two different values in the second. ? Thanks for any help, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: From jarich at perltraining.com.au Mon Mar 23 16:31:49 2009 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Tue, 24 Mar 2009 10:31:49 +1100 Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <000001c9a993$0d515350$27f3f9f0$@com> References: <000001c9a993$0d515350$27f3f9f0$@com> Message-ID: <49C81BE5.4050702@perltraining.com.au> As far as I can tell, your code works fine - by accident. So the only theory I have is that you might be looking at the hash before it's been populated. The code, with scaffolding that I'm using is: ######################################## # Darley/Supers.pm package Darley::Supers; use Data::Dumper; BEGIN { # This line creates the lexical variable and then it's discarded # at the end of the block my (%CurrentUser); use Exporter (); @ISA = qw(Exporter); # This cannot export lexicals, so %CurrentUser here is the package # variable so far undeclared. The ampersands are best omitted. @EXPORT = qw(%CurrentUser &Power &Challenge &GetUser &GetOrg &GetCity); } sub SetCurrentOrgSetting { my (%Args) = @_; # Args: Setting = Setting to store # Value = Value to store #StoreOrgSetting( # OrgID => $CurrentUser{Org}{org_id}, # Setting => $Args{Setting}, # Value => $Args{Value} #); # Since there isn't a lexical %CurrentUser in scope, this must be the # package variable $CurrentUser{Org}{Settings}{ $Args{Setting} } = $Args{Value}; return 1; } sub Show { print Dumper \%CurrentUser; } 1; ######################################## # test.pl use Darley::Supers qw(%CurrentUser); use strict; use Data::Dumper; print "Before setting\n"; print Dumper \%CurrentUser; Darley::Supers::SetCurrentOrgSetting(Setting => "ABC", Value => 123); print "After setting\n"; print Dumper \%CurrentUser; print "Module internals\n"; Darley::Supers::Show(); ########################## # Output: Before setting $VAR1 = {}; After setting $VAR1 = { 'Org' => { 'Settings' => { 'ABC' => 123 } } }; Module internals $VAR1 = { 'Org' => { 'Settings' => { 'ABC' => 123 } } }; ######################################## Now you don't actually need that BEGIN block in your module at all, because all you're doing is declaring a couple of things. If you were calling a method that absolutely had to be called before the rest of the module was compiled, then you'd put it in a BEGIN block. Here's the strict compliant, non-BEGIN way of writing the same module: ######################################## # Darley/Supers.pm package Darley::Supers; use strict; use Data::Dumper; # use base qw(Exporter) does the same as use Exporter; our @ISA = qw(Exporter); use base qw(Exporter); # These don't need to be in a begin block, they're just declarations. # Ampersands are not required to denote subroutines our @EXPORT = qw(%CurrentUser Power Challenge GetUser GetOrg GetCity); our (%CurrentUser); sub SetCurrentOrgSetting { my (%Args) = @_; # Args: Setting = Setting to store # Value = Value to store #StoreOrgSetting( # OrgID => $CurrentUser{Org}{org_id}, # Setting => $Args{Setting}, # Value => $Args{Value} #); $CurrentUser{Org}{Settings}{ $Args{Setting} } = $Args{Value}; return 1; } sub Show { print Dumper \%CurrentUser; } 1; ######################################## With the same test script, this yields the same output as above. All the best, J -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | From tyemq at cpan.org Mon Mar 23 18:06:33 2009 From: tyemq at cpan.org (Tye McQueen) Date: Mon, 23 Mar 2009 18:06:33 -0700 Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <407473.78902.qm@web50107.mail.re2.yahoo.com> References: <000001c9a993$0d515350$27f3f9f0$@com> <649877.61563.qm@web50107.mail.re2.yahoo.com> <005201c9abea$ff8038e0$fe80aaa0$@com> <407473.78902.qm@web50107.mail.re2.yahoo.com> Message-ID: On Mon, Mar 23, 2009 at 3:24 PM, Mark Mertel wrote: > Globals are not recommended. You could make them package variables and > declare them with 'my' or 'our', and then access them using the package name > $Neo::Web::Session, or $Darley::Supers::CurrentUser when from outside the > package. > You are muddling several different things together there. Complaining about "globals" and then recommending "our" is contradictory since "our" is used to declare a global variable. Recommending "my" along with "using the package name" is bad advice since it won't work (you would be accessing different variables). I'll leave the in-depth explaining of the differences between "lexical variables" and "package globals" to other sources, but those are the two choices. :) Tye -------------- next part -------------- An HTML attachment was scrubbed... URL: From pdarley at kinesis-cem.com Mon Mar 23 18:23:16 2009 From: pdarley at kinesis-cem.com (Peter Darley) Date: Mon, 23 Mar 2009 18:23:16 -0700 Subject: SPUG: Confusing behavior with exported variables In-Reply-To: <407473.78902.qm@web50107.mail.re2.yahoo.com> References: <000001c9a993$0d515350$27f3f9f0$@com> <649877.61563.qm@web50107.mail.re2.yahoo.com> <005201c9abea$ff8038e0$fe80aaa0$@com> <407473.78902.qm@web50107.mail.re2.yahoo.com> Message-ID: <003001c9ac1f$1c19db30$544d9190$@com> Mark, Since there is only going to be one instance I don?t see what value creating an object has. It just makes the code harder to read. Especially since they would have properties, but never any methods. Is there something I?m missing? Thanks, Peter From: spug-list-bounces+pdarley=kinesis-cem.com at pm.org [mailto:spug-list-bounces+pdarley=kinesis-cem.com at pm.org] On Behalf Of Mark Mertel Sent: Monday, March 23, 2009 3:25 PM To: Peter Darley; spug-list at pm.org Subject: Re: SPUG: Confusing behaivior with exported variables Globals are not recommended. You could make them package variables and declare them with 'my' or 'our', and then access them using the package name $Neo::Web::Session, or $Darley::Supers::CurrentUser when from outside the package. Personally, I'd make an object and fetch them using an accessor, i.e. my $web = new Neo::Web; $web->session; package Neo::Web; sub new { ... } sub session { ... } --- Mark Mertel 206.441.4663 mark.mertel at yahoo.com http://www.linkedin.com/in/markmertel http://www.seattlejobs.com/13147468 _____ From: Peter Darley To: Mark Mertel ; spug-list at pm.org Sent: Monday, March 23, 2009 12:10:14 PM Subject: RE: SPUG: Confusing behaivior with exported variables Mark and Tye, I would have sworn that I took out the my declaration in the second module. I?ll try removing that and see how it works. I usually do use strict as a default, but the first module didn?t have it so I removed it in my efforts to figure out what was going on. Thanks, Peter From: Mark Mertel [mailto:mark.mertel at yahoo.com] Sent: Friday, March 20, 2009 2:16 PM To: Peter Darley; spug-list at pm.org Subject: Re: SPUG: Confusing behaivior with exported variables probably should 'use strict' as well. the first package doesn't declare the %Session hash, so it becomes global, and the second package scopes the %CurrentUser inside the BEGIN block. 'use strict' should point these things out. --- Mark Mertel 206.441.4663 mark.mertel at yahoo.com http://www.linkedin.com/in/markmertel http://www.seattlejobs.com/13147468 _____ From: Peter Darley To: spug-list at pm.org Sent: Friday, March 20, 2009 12:35:40 PM Subject: SPUG: Confusing behaivior with exported variables Folks, It?s been a long time since I?ve bugged y?all with a stupid question, but I?ve got a new one so I?m hoping someone can help me out. The problem is with exporting variables, and having them available to both a script that uses the module exporting the variable, and the module it?s self. I have two modules, one on a machine at work and one on a machine at home. Both are doing something that looks super similar to me. At work I have: package Neo::Web; use ... use CGI qw/:standard/; use CGI::Cookie; use Apache::DBI; use Apache::Session::Postgres; use Data::Dumper; BEGIN { use Exporter (); @ISA = qw(Exporter); @EXPORT = qw(%Session $SessionID &TieSession &UntieSession ... ); ConnectDB(DBName=>'Sessions'); } sub TieSession { tie %Session, 'Apache::Session::Postgres', $SessionID, {Handle=>$Neo::DB::Sessions, Commit=>0}; $SessionID = $Session{_session_id}; } The scripts using this package can get at %Session, and this module can get at %Session. They are the same variable and have the same contents. At home I have: package Darley::Supers; use ... ; use Data::Dumper; BEGIN { my (%CurrentUser); use Exporter (); @ISA = qw(Exporter); @EXPORT = qw(%CurrentUser &Power &Challenge &GetUser &GetOrg &GetCity); } sub SetCurrentOrgSetting { my (%Args) = @_; # Args: Setting = Setting to store # Value = Value to store StoreOrgSetting(OrgID=>$CurrentUser{Org}{org_id}, Setting=>$Args{Setting}, Value=>$Args{Value}); $CurrentUser{Org}{Settings}{$Args{Setting}} = $Args{Value}; return 1; } And the script using this module can get at %CurrentUser, but when this package uses it, it?s empty. I can?t figure out why the exported hash is the same in the first example, but has two different values in the second. Thanks for any help, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: From rick.croote at philips.com Mon Mar 23 22:12:26 2009 From: rick.croote at philips.com (Croote, Rick) Date: Tue, 24 Mar 2009 06:12:26 +0100 Subject: SPUG: Confusing behavior with exported variables In-Reply-To: <003001c9ac1f$1c19db30$544d9190$@com> References: <000001c9a993$0d515350$27f3f9f0$@com> <649877.61563.qm@web50107. mail.re2.yahoo.com> <005201c9abea$ff8038e0$fe80aaa0$@com><407473.78902.qm@web50107.mail.re2.yahoo.com> <003001c9ac1f$1c19db30$544d9190$@com> Message-ID: <6A00D845EC61DF46810F2D5BCB5F6E044F2FC0D1E0@NLCLUEXM06.connect1.local> Creating the object is simple, and the advantage is that it becomes the place holder for future related implementation, extending the interface rather than rewriting it to a class at that time. No different than organizing within subdirectories. Thanks, Rick Croote Software Development Engineer Philips Healthcare - Ultrasound R&D Work: 425.487.7834 Mobile: 425.346.6246 E-mail: rick.croote at philips.com From: spug-list-bounces+rick.croote=philips.com at pm.org [mailto:spug-list-bounces+rick.croote=philips.com at pm.org] On Behalf Of Peter Darley Sent: 2009 Mar 23 6:23 PM To: 'Mark Mertel'; spug-list at pm.org Subject: Re: SPUG: Confusing behavior with exported variables Mark, Since there is only going to be one instance I don?t see what value creating an object has. It just makes the code harder to read. Especially since they would have properties, but never any methods. Is there something I?m missing? Thanks, Peter From: spug-list-bounces+pdarley=kinesis-cem.com at pm.org [mailto:spug-list-bounces+pdarley=kinesis-cem.com at pm.org] On Behalf Of Mark Mertel Sent: Monday, March 23, 2009 3:25 PM To: Peter Darley; spug-list at pm.org Subject: Re: SPUG: Confusing behaivior with exported variables Globals are not recommended. You could make them package variables and declare them with 'my' or 'our', and then access them using the package name $Neo::Web::Session, or $Darley::Supers::CurrentUser when from outside the package. Personally, I'd make an object and fetch them using an accessor, i.e. my $web = new Neo::Web; $web->session; package Neo::Web; sub new { ... } sub session { ... } --- Mark Mertel 206.441.4663 mark.mertel at yahoo.com http://www.linkedin.com/in/markmertel http://www.seattlejobs.com/13147468 ________________________________ From: Peter Darley To: Mark Mertel ; spug-list at pm.org Sent: Monday, March 23, 2009 12:10:14 PM Subject: RE: SPUG: Confusing behaivior with exported variables Mark and Tye, I would have sworn that I took out the my declaration in the second module. I?ll try removing that and see how it works. I usually do use strict as a default, but the first module didn?t have it so I removed it in my efforts to figure out what was going on. Thanks, Peter From: Mark Mertel [mailto:mark.mertel at yahoo.com] Sent: Friday, March 20, 2009 2:16 PM To: Peter Darley; spug-list at pm.org Subject: Re: SPUG: Confusing behaivior with exported variables probably should 'use strict' as well. the first package doesn't declare the %Session hash, so it becomes global, and the second package scopes the %CurrentUser inside the BEGIN block. 'use strict' should point these things out. --- Mark Mertel 206.441.4663 mark.mertel at yahoo.com http://www.linkedin.com/in/markmertel http://www.seattlejobs.com/13147468 ________________________________ From: Peter Darley To: spug-list at pm.org Sent: Friday, March 20, 2009 12:35:40 PM Subject: SPUG: Confusing behaivior with exported variables Folks, It?s been a long time since I?ve bugged y?all with a stupid question, but I?ve got a new one so I?m hoping someone can help me out. The problem is with exporting variables, and having them available to both a script that uses the module exporting the variable, and the module it?s self. I have two modules, one on a machine at work and one on a machine at home. Both are doing something that looks super similar to me. At work I have: package Neo::Web; use ... use CGI qw/:standard/; use CGI::Cookie; use Apache::DBI; use Apache::Session::Postgres; use Data::Dumper; BEGIN { use Exporter (); @ISA = qw(Exporter); @EXPORT = qw(%Session $SessionID &TieSession &UntieSession ... ); ConnectDB(DBName=>'Sessions'); } sub TieSession { tie %Session, 'Apache::Session::Postgres', $SessionID, {Handle=>$Neo::DB::Sessions, Commit=>0}; $SessionID = $Session{_session_id}; } The scripts using this package can get at %Session, and this module can get at %Session. They are the same variable and have the same contents. At home I have: package Darley::Supers; use ... ; use Data::Dumper; BEGIN { my (%CurrentUser); use Exporter (); @ISA = qw(Exporter); @EXPORT = qw(%CurrentUser &Power &Challenge &GetUser &GetOrg &GetCity); } sub SetCurrentOrgSetting { my (%Args) = @_; # Args: Setting = Setting to store # Value = Value to store StoreOrgSetting(OrgID=>$CurrentUser{Org}{org_id}, Setting=>$Args{Setting}, Value=>$Args{Value}); $CurrentUser{Org}{Settings}{$Args{Setting}} = $Args{Value}; return 1; } And the script using this module can get at %CurrentUser, but when this package uses it, it?s empty. I can?t figure out why the exported hash is the same in the first example, but has two different values in the second. Thanks for any help, Peter ________________________________ The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.mertel at yahoo.com Tue Mar 24 12:25:39 2009 From: mark.mertel at yahoo.com (Mark Mertel) Date: Tue, 24 Mar 2009 12:25:39 -0700 (PDT) Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: References: <000001c9a993$0d515350$27f3f9f0$@com> <649877.61563.qm@web50107.mail.re2.yahoo.com> <005201c9abea$ff8038e0$fe80aaa0$@com> <407473.78902.qm@web50107.mail.re2.yahoo.com> Message-ID: <327550.2795.qm@web50102.mail.re2.yahoo.com> ________________________________ From: Tye McQueen To: Mark Mertel Cc: Peter Darley ; spug-list at pm.org Sent: Monday, March 23, 2009 6:06:33 PM Subject: Re: SPUG: Confusing behaivior with exported variables On Mon, Mar 23, 2009 at 3:24 PM, Mark Mertel wrote: Globals are not recommended. You?could make them package variables and declare them with 'my' or 'our', and then access them using the package name $Neo::Web::Session, or $Darley::Supers::CurrentUser when?from outside the package. You are muddling several different things together there. Complaining about "globals" and then recommending "our" is contradictory since "our" is used to declare a global variable. Using 'our' is only global within the package and its descendents. For the external scripts it would not be visible, hence, not global. Recommending "my" along with "using the package name" is bad advice since it won't work (you would be accessing different variables). It does work: package Foo; my $bar = "foo bar\n"; 1; ... ? use Foo; use strict; ? print $Foo::bar; # prints 'foo bar' ? print $bar; # should throw an error I'll leave the in-depth explaining of the differences between "lexical variables" and "package globals" to other sources, but those are the two choices. :) Tye -------------- next part -------------- An HTML attachment was scrubbed... URL: From twists at gmail.com Tue Mar 24 12:57:40 2009 From: twists at gmail.com (Joshua ben Jore) Date: Tue, 24 Mar 2009 12:57:40 -0700 Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <327550.2795.qm@web50102.mail.re2.yahoo.com> References: <000001c9a993$0d515350$27f3f9f0$@com> <649877.61563.qm@web50107.mail.re2.yahoo.com> <005201c9abea$ff8038e0$fe80aaa0$@com> <407473.78902.qm@web50107.mail.re2.yahoo.com> <327550.2795.qm@web50102.mail.re2.yahoo.com> Message-ID: On Tue, Mar 24, 2009 at 12:25 PM, Mark Mertel wrote: > Using 'our' is only global within the package and its descendents. For the > external scripts it would not be visible, hence, not global. No, you're wrong. my $Foo = 'bar'; { our $Foo = 42; } print "$Foo\n"; # prints bar print "$main::Foo\n"; # prints 42 our() declares a global. All globals are visible to all other code though often other code must go to the effort of giving a fully qualified name. Other code can avoid going to that trouble if it was exported. our() also has some additional magic in the parser but that doesn't change that it's just a global. my() is never a global. Other code that has an idea about where a lexical lives can never access it. Rules-breaking code which inspects perl internals can do it anyway but as stated - that is normally against the rules. If you put everything into a single file, or use do() or eval(), that makes this more complicated but the above is still true. Josh From rjk-spug at tamias.net Tue Mar 24 13:37:33 2009 From: rjk-spug at tamias.net (Ronald J Kimball) Date: Tue, 24 Mar 2009 16:37:33 -0400 Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <327550.2795.qm@web50102.mail.re2.yahoo.com> References: <000001c9a993$0d515350$27f3f9f0$@com> <649877.61563.qm@web50107.mail.re2.yahoo.com> <005201c9abea$ff8038e0$fe80aaa0$@com> <407473.78902.qm@web50107.mail.re2.yahoo.com> <327550.2795.qm@web50102.mail.re2.yahoo.com> Message-ID: <20090324203733.GA67114@penkwe.pair.com> On Tue, Mar 24, 2009 at 12:25:39PM -0700, Mark Mertel wrote: > > It does work: > > package Foo; > my $bar = "foo bar\n"; > 1; > ... > > use Foo; > use strict; > > print $Foo::bar; # prints 'foo bar' > > print $bar; # should throw an error Did you actually execute this code? It /does not/ do what you say it does. It would be a very good idea for you to take the time to understand how my()/our() and lexical/package variables actually work before you spread more misinformation on this subject. Variables declared with my() are lexically scoped. They are not stored in the symbol table. They are accessible only from within that lexical scope. Variables declared with our() are package variables. They are stored in the symbol table. They are accessible globally, but may need to be fully qualified. package Foo; use strict; { my $foo = 'foo'; # sets lexical $foo print "$foo\n"; # prints 'foo' } #print "$foo\n"; # error under use strict, prints undef otherwise { my $foo; # a different lexical $foo print "$foo\n"; # prints undef } { our $bar = 'bar'; # sets $Foo::bar print "$bar\n"; # prints 'bar' } #print "$bar\n"; # error under use strict, prints 'bar' otherwise print "$Foo::bar\n"; # prints 'bar' { our $bar; # same $Foo::bar print "$bar\n"; # prints 'bar' } Ronald From jarich at perltraining.com.au Tue Mar 24 15:37:29 2009 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Wed, 25 Mar 2009 09:37:29 +1100 Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <327550.2795.qm@web50102.mail.re2.yahoo.com> References: <000001c9a993$0d515350$27f3f9f0$@com> <649877.61563.qm@web50107.mail.re2.yahoo.com> <005201c9abea$ff8038e0$fe80aaa0$@com> <407473.78902.qm@web50107.mail.re2.yahoo.com> <327550.2795.qm@web50102.mail.re2.yahoo.com> Message-ID: <49C960A9.7030305@perltraining.com.au> Mark Mertel wrote: > *It does work:* > ** > > *package Foo;* > *my $bar = "foo bar\n";* > *1;* > *...* > ** > *use Foo;* > *use strict;* > ** > *print $Foo::bar; # prints 'foo bar'* > ** > *print $bar; # should throw an error* > > > I'll leave the in-depth explaining of the differences between "lexical > variables" and "package globals" to other sources, but those are the two > choices. :) Technically you're both wrong. Declaring variables with "our" does not make them global. It makes them package variables. However, as Mark has hopefully discovered now, declaring variables with *my* does not cause them to behave the way he thought they did. Lexical variables (those declared with my) exist for their smallest enclosing scope. This is either a block (as defined by curly brackets) or the file they're declared in. Thus: #!/usr/bin/perl -w use strict; my $foo; # Visible to the whole file while(<>) { my $bar; # Visible only to the end of the while block } Variables declared with my cannot ever be seen outside the file they are declared in. Package variables (those declared with our, or created when you mention a variable without strict turned on) are visible from the point they are created to the end of their file; and are accessible to other files as well (when exported or when their full name is used): # Foo.pm package Foo; use strict; my $foo = "This is lexical"; our $bar = "This is a package variable"; # test.pl #!/usr/bin/perl -w use strict; use Foo; print "foo: $Foo::foo\n"; # foo: (looks for package var) print "bar: $Foo::bar\n"; # bar: This is a package variable of course, if you stick them both in the *same* file, you can see the lexical variable: package Foo; use strict; my $foo = "This is lexical"; our $bar = "This is a package variable"; package main; use strict; use Foo; print "foo: $foo\n"; # foo: This is lexical print "bar: $bar\n"; # bar: This is a package variable print "foo: $Foo::foo\n"; # foo: print "bar: $Foo::bar\n"; # bar: This is a package variable because the scope of these variables is their smallest enclosing block or file. Packages do not denote blocks. To get the "correct" effect you'd need more braces: { package Foo; use strict; my $foo = "This is lexical"; our $bar = "This is a package variable"; } package main; use strict; use Foo; print "foo: $Foo::foo\n"; # foo: print "bar: $Foo::bar\n"; # bar: This is a package variable Perl's true globals are its special variables, which are visible and changable by everything - whether you want them to be or not. Package variables are often called globals, but they're not real globals in the computer science sense. Close enough though. J -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | From mark.mertel at yahoo.com Tue Mar 24 16:06:22 2009 From: mark.mertel at yahoo.com (Mark Mertel) Date: Tue, 24 Mar 2009 16:06:22 -0700 (PDT) Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <20090324203733.GA67114@penkwe.pair.com> References: <000001c9a993$0d515350$27f3f9f0$@com> <649877.61563.qm@web50107.mail.re2.yahoo.com> <005201c9abea$ff8038e0$fe80aaa0$@com> <407473.78902.qm@web50107.mail.re2.yahoo.com> <327550.2795.qm@web50102.mail.re2.yahoo.com> <20090324203733.GA67114@penkwe.pair.com> Message-ID: <112116.96525.qm@web50111.mail.re2.yahoo.com> apologies - i'll abstain from further coding examples until i am able to compile them. i have no computer at present, and am attempting to?get it from memory - kind of a?pseudo coder. i did read up a little on the break, and i think my opinion about this was to not use global variables, but if they couldn't be avoided, use package variables instead. again, my apologies to the list. ?--- Mark Mertel 206.441.4663 mark.mertel at yahoo.com http://www.linkedin.com/in/markmertel http://www.seattlejobs.com/13147468 ________________________________ From: Ronald J Kimball To: spug-list at pm.org Sent: Tuesday, March 24, 2009 1:37:33 PM Subject: Re: SPUG: Confusing behaivior with exported variables On Tue, Mar 24, 2009 at 12:25:39PM -0700, Mark Mertel wrote: > > It does work: > > package Foo; > my $bar = "foo bar\n"; > 1; > ... > > use Foo; > use strict; > > print $Foo::bar; # prints 'foo bar' > > print $bar; # should throw an error Did you actually execute this code?? It /does not/ do what you say it does. It would be a very good idea for you to take the time to understand how my()/our() and lexical/package variables actually work before you spread more misinformation on this subject. Variables declared with my() are lexically scoped.? They are not stored in the symbol table.? They are accessible only from within that lexical scope. Variables declared with our() are package variables.? They are stored in the symbol table.? They are accessible globally, but may need to be fully qualified. package Foo; use strict; { ? my $foo = 'foo';? # sets lexical $foo ? print "$foo\n";? ? # prints 'foo' } #print "$foo\n";? ? # error under use strict, prints undef otherwise { ? my $foo;? ? ? ? ? # a different lexical $foo ? print "$foo\n";? ? # prints undef } { ? our $bar = 'bar';? # sets $Foo::bar ? print "$bar\n";? ? # prints 'bar' } #print "$bar\n";? ? # error under use strict, prints 'bar' otherwise print "$Foo::bar\n"; # prints 'bar' { ? our $bar;? ? ? ? ? # same $Foo::bar ? print "$bar\n";? ? # prints 'bar' } Ronald _____________________________________________________________ Seattle Perl Users Group Mailing List ? ? POST TO: spug-list at pm.org SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list ? ? MEETINGS: 3rd Tuesdays ? ? WEB PAGE: http://seattleperl.org/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From tyemq at cpan.org Tue Mar 24 20:10:38 2009 From: tyemq at cpan.org (Tye McQueen) Date: Tue, 24 Mar 2009 20:10:38 -0700 Subject: SPUG: Confusing behaivior with exported variables In-Reply-To: <49C960A9.7030305@perltraining.com.au> References: <000001c9a993$0d515350$27f3f9f0$@com> <649877.61563.qm@web50107.mail.re2.yahoo.com> <005201c9abea$ff8038e0$fe80aaa0$@com> <407473.78902.qm@web50107.mail.re2.yahoo.com> <327550.2795.qm@web50102.mail.re2.yahoo.com> <49C960A9.7030305@perltraining.com.au> Message-ID: On Tue, Mar 24, 2009 at 3:37 PM, Jacinta Richardson < jarich at perltraining.com.au> wrote: > > I'll leave the in-depth explaining of the differences between "lexical > > variables" and "package globals" to other sources, but those are the two > > choices. :) > > Technically you're both wrong. Declaring variables with "our" does not > make them global. It makes them package variables. By that definition, Perl doesn't implement global variables. In Perl, "global variables" are "package variable" are "package globals". Package variables are globally accessible but have names partitioned into namespaces (and the namespaces are called "packages"). Package variables (those declared with our, or created when you mention a > variable without strict turned on) are visible from the point they are > created > to the end of their file; and are accessible to other files as well (when > exported or when their full name is used): > $foo::bar is certainly a global variable. The shorter form, $bar, can sometimes be used to access the global variable. There are lots of ways to make that happen ["package foo;" w/o "use strict" or w/ "our $bar;" or w/ "use vars qw($bar)" or "bar" actually something special like "ISA", importing, "bar" actually being a punctuation mark and "foo" being "main", etc.] and the details of each (especially "our") can get a bit complicated, even confusing. But in such cases, $bar is not a different variable from $foo::bar, so $bar is just a convenient name for the global variable, even though whatever trick you used to make the short form usable may not apply globally. Your "visible from the point they are created to the end of their file" is sort-of close to true for most of the tricks for making the short form usable. The 'our' trick is actually lexically scoped (which is what makes 'our' such a complex case). Lots of the other tricks work in any code compiled after the trick was executed (which often seems close to "from here to the end of the file" but is rather different in several ways). > Perl's true globals are its special variables, which are visible and > changable > by everything - whether you want them to be or not. Um, Perl's punctuation variables /are/ package variables. $_ is just short for $main::_. It is just that $_ is almost always short for $main::_ (even if the current package is not "main"). Package variables are often > called globals, but they're not real globals in the computer science sense. > Close enough though. > Package variables are visible and changeable by everything, whether you want them to be or not. The /variables/ are global. Their long names are global. Their short names are partitioned into (global) packages (and can be "enabled" in several ways, even including a few ways to enable the short name outside of the package it lives in). But that doesn't make the variables "not really globals" even if you add "in the computer science sense". Technically. Calling them "package globals" hints at some of these complexities regarding the names of these global variables. Tye -------------- next part -------------- An HTML attachment was scrubbed... URL: From ingmar at site42.com Thu Mar 26 13:55:29 2009 From: ingmar at site42.com (Ingmar Ellenberger) Date: Thu, 26 Mar 2009 13:55:29 -0700 Subject: SPUG: Camel Book on Chuck Message-ID: <347dd89c0903261355pb338121g3dd6a7e3ba043901@mail.gmail.com> It seems the Camel Book made it's appearance on Chuck Monday night: http://ikeapimp.blogspot.com/2009/03/chuck-vs-camel.html A bit of amusement for those that didn't notice :) - Ingmar -------------- next part -------------- An HTML attachment was scrubbed... URL: