From roberthpike at yahoo.com Mon Jul 6 06:15:50 2009 From: roberthpike at yahoo.com (Robert Pike) Date: Mon, 6 Jul 2009 06:15:50 -0700 (PDT) Subject: [kw-pm] Sessions in CGI Apps written in Perl Message-ID: <408730.7564.qm@web58704.mail.re1.yahoo.com> Can anyone suggest a reliable approach to handling sessions within perl? The application(s) I'm writing will be running on Windows (running IIS) and Linux (running Apache). Any info would be appreciated. Thanks. Rob __________________________________________________________________ Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now http://ca.toolbar.yahoo.com. From singpolyma at singpolyma.net Fri Jul 10 18:56:16 2009 From: singpolyma at singpolyma.net (Stephen Paul Weber) Date: Fri, 10 Jul 2009 18:56:16 -0700 Subject: [kw-pm] Keysigning and Introductory Session this Fall Message-ID: <20090711015616.GA22657@singpolyma-mini> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 BarCampWaterloo at googlegroups.com Bcc: Subject: Keysigning and Instructional Session this Fall Reply-To: Jabber-ID: singpolyma at gmail.com OpenPGP: id=CE519CDE; url=https://singpolyma.net/public.asc X-URL: https://singpolyma.net I've been talking to different people for a couple weeks about organising a keysigning event this fall. Given it is fall and there's the influx of student activity in the Waterloo area, it might also make an excellent opportunity to help people who have never used OpenPGP or other crypto technologies to understand / set it up. I am writing these lists/people as the first ones that came to my mind in the area that might be interested. If there is anyone else or any other group you think might be interested, please forward this on to them. One of the things I'm not sure about yet is venue. Obviously not someplace loun or crowded. The Working Centre (where KWLUG meets) and the small room at the back/front of the Accelerator Centre (where BarCamps happen) come to mind as ideal, but I'm not sure what logistics/rules are about getting in to such places. We could always hold it somewhere at UW. I'll be enrolled as a student and able to book rooms. I'm thinking an evening in September just now. It depends on when people are available. Please cc me on all replies, since I may not monitor all of these lists. Thanks, - -- Stephen Paul Weber, @singpolyma Please see for how I prefer to be contacted. edition right joseph -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iQIcBAEBCAAGBQJKV/FAAAoJENEcKRHOUZze/QcP/1DuM5rsz8/RMgM83cO+XNv+ 5EGjaYMlWN1zxTiPBalXHAVXUpyT7Hfy9NottLlVky5NhNwGeguOjGwLTMmeslhO Ymo7Xt03sIDTRKPoLPQ9VWK8wFsb5OjPdgwhg/zfF08oD2Z8xwPgv1q4q3DgeFmj s3mQGL537mJs+0fHZ2aKx1l0CRs1c/asztAnvYNHS02/pLc+J2x76N7+ieEg2FiP Ma5mctCs4D7dMxZOKvXhpFZqDaroyAKFrYQ4ZOkZwpCM8lnVzG3/J0QdK90Qc/UF uwFojqgDdESeX1ELuqOGSiyZUgUp9rubs7Nl2Yh7zoiMvtTF54IQQN7FGzZRa0XB U7HCUfGKS4RTbr744CHKtmMtwfvy3ynCpTzVMg6fjpNGULgxqMLWQqVlh1KitjQY gx3sGNWBiJoYJyIe6DzK0imna1s6KGl0F9smV9FP2AuT+qjUF1uYpeSW1gpMZbBF 2DCd6Be6Kcw6+aJRPfC50zq4AoSvaXDpfkGZQZWTK0CSbklwZAUC7CqRsakjs9kR DJypskBlRUHhNwjsTE3gAOUDdqBOXTURY3BW2I3ZEhoH2OIu4V0QCQfdKv6FSbDT ulg6AEnOBGdmwELqPDJCJ6nZOmgDXXA3W58X52b4xJJsl+lnG+m9YXZ3d0EiOLnR oOlwwqDvjCpPUW+V5RoO =RQUy -----END PGP SIGNATURE----- From daniel at coder.com Mon Jul 13 07:11:39 2009 From: daniel at coder.com (Daniel R. Allen) Date: Mon, 13 Jul 2009 10:11:39 -0400 (EDT) Subject: [kw-pm] Perl Mongers Meeting this WEDNESDAY Message-ID: As promised last month, this month's meeting, about microcontrollers, is a night early, Wednesday the 15th at 7pm in DC3323. The topic is "Interfacing Stuff with Microcontrollers" by Andrew Kohlsmith. Andrew's got tons of experience with hardware, perl, and various content domains (VoIP, Linux, microcontroller gadgets...) As usual, we've got pizza; before 5pm Wednesday please add your name to http://kw.pm.org/wiki/index.cgi?PizzaList See you there! -Daniel From roberthpike at yahoo.com Mon Jul 13 12:13:22 2009 From: roberthpike at yahoo.com (Robert Pike) Date: Mon, 13 Jul 2009 12:13:22 -0700 (PDT) Subject: [kw-pm] Issue with $ENV{"HTTP_COOKIE"} Message-ID: <870479.98632.qm@web58707.mail.re1.yahoo.com> I'll try and outline this as best I can. I have a Perl (CGI) script that sets up a bunch of cookies (i.e. print "Set-Cookie: variable........" (it's an older script that doesn't utilize any modules such as CGI). Later in the script it redirects to another website (again a simple print statement with Location: .......). On that website a form is filled out, something runs on that server to process, and then the user gets redirected to a HTML page (on my server). This is a very simple HTML page that merely is set up to redirect back to the original script that generated the cookies. At this point if I try and print out what is in $ENV{"HTTP_COOKIE"} I get absolutely nothing. I was hoping to get the cookies that were originally set up in the initial call of the script. This does sound like a strange sequence of calls (and it has a lengthy explanation) but I would appreciate any help anyone could give. Thanks. __________________________________________________________________ Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/ From broadswd at gmail.com Mon Jul 13 16:24:24 2009 From: broadswd at gmail.com (Raymond) Date: Mon, 13 Jul 2009 19:24:24 -0400 Subject: [kw-pm] Issue with $ENV{"HTTP_COOKIE"} In-Reply-To: <870479.98632.qm@web58707.mail.re1.yahoo.com> References: <870479.98632.qm@web58707.mail.re1.yahoo.com> Message-ID: Oops, replying to the group. 2009/7/13 Robert Pike : > > I'll try and outline this as best I can. > I have a Perl (CGI) script that sets up a bunch of cookies (i.e. print "Set-Cookie: variable........" (it's an older script that doesn't utilize any modules such as CGI). Later in the script it redirects to another website (again a simple print statement with Location: .......). > On that website a form is filled out, something runs on that server to process, and then the user gets redirected to a HTML page (on my server). This is a very simple HTML page that merely is set up to redirect back to the original script that generated the cookies. At this point if I try and print out what is in $ENV{"HTTP_COOKIE"} I get absolutely nothing. I was hoping to get the cookies that were originally set up in the initial call of the script. > This does sound like a strange sequence of calls (and it has a lengthy explanation) but I would appreciate any help anyone could give. Thanks. I'd question a couple things: 1) Are they actually set? Check your browser's cookie store to see if they're there or establish a telnet HTTP session and see if it's in the response. Setting cookies and doing a HTTP redirect in the same header doesn't work on some servers (notably older IISes). 2) If they are set, do they have the correct url and path? 3) Is your environment cleansing them? This is unlikely but depending on your webserver, make sure there aren't any handlers eating the cookies before they get to you. From rdice at pobox.com Tue Jul 14 07:10:22 2009 From: rdice at pobox.com (Richard Dice) Date: Tue, 14 Jul 2009 10:10:22 -0400 Subject: [kw-pm] Details on Damian Conway talk, Monday 27 July 2009 In-Reply-To: <5bef4baf0907140707l2a935661o129b8fad355896fb@mail.gmail.com> References: <5bef4baf0907140707l2a935661o129b8fad355896fb@mail.gmail.com> Message-ID: <5bef4baf0907140710o63915b19ycac9f1a5b3447559@mail.gmail.com> Hi everyone, Damian Conway, an inspiration and friend to Perl community around the world, will be delivering a free public talk in Toronto on Monday 27 July. Please consider attending -- the drive isn't too bad, and the talk will be a ton of Perl fun. Here are the details: Presenter: Dr. Damian Conway, the Mad Scientist of Perl http://damian.conway.org/About_us//Bio_formal.html http://www.googlism.com/index.htm?ism=damian+conway&type=1 Talk Title: The Missing Link Details: What do watching trees grow, debugging debuggers, Greek mythology, code that writes code that writes code that writes code, the hazards of LaTeX, successful failures, the treacherous Vorta, objective syntax, anti-stacks, Danish mind-control, active null statements, synthetic standup, and the prospect of certain death all have in common? Watch as Damian weaves them together into a new and improbably useful module that demonstrates the awesome power and beauty of Perl 5.10. Date: Monday 27 July 2009 Time: 7pm - 9pm show up early to get a seat, find place to park if you're driving, etc. Location: Bahen Centre for IT Room 1160 (i.e. the major lecture theater on the ground floor) University of Toronto St. George (downtown) campus 40 St. George Street (just North of College on the East side of St. George) Parking: See the following URL for information about parking on UofT St. George campus http://tinyurl.com/u-of-t-parking Looks like there is an underground lot directly beneath Bahen Centre (marker #17). I also find it convenient to park on King's College Circle (marker #13). Transit: St. George subway Stn, St. George St. exit, walk south approx. 7 minutes _or_ Queen's Park subway Stn., walk west approx. 5 minutes _or_ College streetcar westbound from either College Stn or Queen's Park Stn (but walking may be faster than waiting for a car, especially if you're at Queen's Park Stn) Hope to see you there! Cheers, - Richard -------------- next part -------------- An HTML attachment was scrubbed... URL: From roberthpike at yahoo.com Wed Jul 15 10:57:25 2009 From: roberthpike at yahoo.com (Robert Pike) Date: Wed, 15 Jul 2009 10:57:25 -0700 (PDT) Subject: [kw-pm] Activestate's CGI::Session module Message-ID: <164160.64489.qm@web58701.mail.re1.yahoo.com> Has anyone dealt with this module before? I'm having an issue with setting and retrieving hash values from within a set session. Any help would be appreciated. __________________________________________________________________ The new Internet Explorer? 8 - Faster, safer, easier. Optimized for Yahoo! Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/ From daniel at coder.com Mon Jul 20 12:47:37 2009 From: daniel at coder.com (Daniel R. Allen) Date: Mon, 20 Jul 2009 15:47:37 -0400 (EDT) Subject: [kw-pm] Last Wednesday's talk on microcontroller interfacing Message-ID: The slides for Andrew's talk are on the website: http://kw.pm.org/talks/2009-07-interfacing-to-microcontrollers.odp (open-office presenter format) Thanks again to Andrew for the presentation, and $anonymous for pizza. Upcoming in August: our annual barbecue, location TBA. -Daniel From rdice at pobox.com Thu Jul 23 19:03:24 2009 From: rdice at pobox.com (Richard Dice) Date: Thu, 23 Jul 2009 22:03:24 -0400 Subject: [kw-pm] Reminder - Damian Conway event, Monday 27 July 2009 Message-ID: <5bef4baf0907231903r1a2cf1c1u1e5392693bf046e3@mail.gmail.com> Hi everyone, A reminder for Damian's talk next Monday evening, details below. (Note that there was a small mistake in the details the last time I sent them; Bahen Centre is really on the /West/ side of St. George.) Presenter: Dr. Damian Conway, the Mad Scientist of Perl http://damian.conway.org/About_us//Bio_formal.html http://www.googlism.com/index.htm?ism=damian+conway&type=1 Talk Title: The Missing Link Details: What do watching trees grow, debugging debuggers, Greek mythology, code that writes code that writes code that writes code, the hazards of LaTeX, successful failures, the treacherous Vorta, objective syntax, anti-stacks, Danish mind-control, active null statements, synthetic standup, and the prospect of certain death all have in common? Watch as Damian weaves them together into a new and improbably useful module that demonstrates the awesome power and beauty of Perl 5.10. Date: Monday 27 July 2009 Time: 7pm - 9pm show up early to get a seat, find place to park if you're driving, etc. Location: Bahen Centre for IT Room 1160 (i.e. the major lecture theater on the ground floor) University of Toronto St. George (downtown) campus 40 St. George Street (just North of College on the West side of St. George) Parking: See the following URL for information about parking on UofT St. George campus http://tinyurl.com/u-of-t-parking Looks like there is an underground lot directly beneath Bahen Centre (marker #17). I also find it convenient to park on King's College Circle (marker #13). Transit: St. George subway Stn, St. George St. exit, walk south approx. 7 minutes _or_ Queen's Park subway Stn., walk west approx. 5 minutes _or_ College streetcar westbound from either College Stn or Queen's Park Stn (but walking may be faster than waiting for a car, especially if you're at Queen's Park Stn) -------------- next part -------------- An HTML attachment was scrubbed... URL: From roberthpike at yahoo.com Mon Jul 27 11:57:06 2009 From: roberthpike at yahoo.com (Robert Pike) Date: Mon, 27 Jul 2009 11:57:06 -0700 (PDT) Subject: [kw-pm] Redirection in Perl CGI Message-ID: <523185.96615.qm@web58705.mail.re1.yahoo.com> CGI application: what's the best way to take content passed in to a perl script from a form and have that content passed on/redirected to another script? Anyone know how to accomplish this without having to tack onto the url? Thanks. __________________________________________________________________ Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/ From broadswd at gmail.com Mon Jul 27 14:46:06 2009 From: broadswd at gmail.com (Raymond) Date: Mon, 27 Jul 2009 17:46:06 -0400 Subject: [kw-pm] Redirection in Perl CGI In-Reply-To: <523185.96615.qm@web58705.mail.re1.yahoo.com> References: <523185.96615.qm@web58705.mail.re1.yahoo.com> Message-ID: You can always open another connection (using LWP for example) and post the sanitised variables to that script and do whatever you want with the response (eg. display to the user). A lot of payment gateways are used in this manner. On 7/27/09, Robert Pike wrote: > CGI application: what's the best way to take content passed in to a perl > script from a form and have that content passed on/redirected to another > script? Anyone know how to accomplish this without having to tack onto the > url? Thanks. > > > __________________________________________________________________ > Looking for the perfect gift? Give the gift of Flickr! > > http://www.flickr.com/gift/ > > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm > -- Sent from my mobile device From max at alleged.net Mon Jul 27 14:48:19 2009 From: max at alleged.net (Max) Date: Mon, 27 Jul 2009 17:48:19 -0400 Subject: [kw-pm] Redirection in Perl CGI In-Reply-To: References: <523185.96615.qm@web58705.mail.re1.yahoo.com> Message-ID: <4A6E20A3.1030902@alleged.net> Normally you would use POST and provide the parameters as the data of the POST (properly encoded), and decode them on the other end, rather than using GET and URL parameters. Raymond wrote: > You can always open another connection (using LWP for example) and > post the sanitised variables to that script and do whatever you want > with the response (eg. display to the user). > > A lot of payment gateways are used in this manner. > > On 7/27/09, Robert Pike wrote: > >> CGI application: what's the best way to take content passed in to a perl >> script from a form and have that content passed on/redirected to another >> script? Anyone know how to accomplish this without having to tack onto the >> url? Thanks. >> >> >> __________________________________________________________________ >> Looking for the perfect gift? Give the gift of Flickr! >> >> http://www.flickr.com/gift/ >> >> _______________________________________________ >> kw-pm mailing list >> kw-pm at pm.org >> http://mail.pm.org/mailman/listinfo/kw-pm >> >> > > From broadswd at gmail.com Mon Jul 27 16:28:34 2009 From: broadswd at gmail.com (Raymond) Date: Mon, 27 Jul 2009 19:28:34 -0400 Subject: [kw-pm] Redirection in Perl CGI In-Reply-To: <4A6E20A3.1030902@alleged.net> References: <523185.96615.qm@web58705.mail.re1.yahoo.com> <4A6E20A3.1030902@alleged.net> Message-ID: If you're just asking to have the POST go to a different script, just change the "action" in the form. Which is what Max is talking about. I thought you were asking how to redirect a POST, which you can't guarantee browser behaviour for. That's why I suggested acting as the user and handling/proxying the response with the second location. Basically the HTTP standard says a user agent may only follow a redirect without user interaction if the method is GET or HEAD, some browsers will follow the 3xx (rediect) after a pop-up about the POST but others won't. Which are you asking about? 2009/7/27 Max : > Normally you would use POST and provide the parameters as the data of the > POST (properly encoded), and decode them on the other end, rather than using > GET and URL parameters. > > Raymond wrote: >> >> You can always open another connection (using LWP for example) and >> post the sanitised variables to that script and do whatever you want >> with the response (eg. display to the user). >> >> A lot of payment gateways are used in this manner. >> >> On 7/27/09, Robert Pike wrote: >> >>> >>> CGI application: what's the best way to take content passed in to a perl >>> script from a form and have that content passed on/redirected to another >>> script? Anyone know how to accomplish this without having to tack onto >>> the >>> url? Thanks. >>> >>> >>> ? ? ?__________________________________________________________________ >>> Looking for the perfect gift? Give the gift of Flickr! >>> >>> http://www.flickr.com/gift/ >>> >>> _______________________________________________ >>> kw-pm mailing list >>> kw-pm at pm.org >>> http://mail.pm.org/mailman/listinfo/kw-pm >>> >>> >> >> > > From ceeshek at gmail.com Mon Jul 27 16:32:28 2009 From: ceeshek at gmail.com (Cees Hek) Date: Tue, 28 Jul 2009 09:32:28 +1000 Subject: [kw-pm] Redirection in Perl CGI In-Reply-To: <523185.96615.qm@web58705.mail.re1.yahoo.com> References: <523185.96615.qm@web58705.mail.re1.yahoo.com> Message-ID: Making a POST request to another URL from perl is easy with the HTTP::Request::Common module: use HTTP::Request::Common; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->request(POST 'http://somewhere/foo', [foo => bar, bar => foo]); Cheers, Cees On Tue, Jul 28, 2009 at 4:57 AM, Robert Pike wrote: > CGI application: what's the best way to take content passed in to a perl > script from a form and have that content passed on/redirected to another > script? Anyone know how to accomplish this without having to tack onto the > url? Thanks. > > > __________________________________________________________________ > Looking for the perfect gift? Give the gift of Flickr! > > http://www.flickr.com/gift/ > > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roberthpike at yahoo.com Wed Jul 29 11:14:37 2009 From: roberthpike at yahoo.com (Robert Pike) Date: Wed, 29 Jul 2009 11:14:37 -0700 (PDT) Subject: [kw-pm] Problem with hash Message-ID: <617605.72544.qm@web58702.mail.re1.yahoo.com> First off, thanks to all that supplied me with feedback in regards to the issue I was having with redirection in perl. I loop through an array, split the values, and put certain values in a hash. Hopefully this will be enough info to get some feedback. my %vHash; $vHsh{"101010"}{"S0"} = "text"; $vHsh{"101010USED"}{"S0"} = "text"; my @aA = ("101010~S0", "101010USED~S0"); #if I were to do this for (my $cC=0$cC<=$#aA;$cC++) { ($itm1, $itm2) = split(/\~/,$aA[$cC]); if (!exists($vHsh{$itm1}{"S".$itm2}{"SYSTEM"})) { #--- also tried defined $vHsh{$itm1}{"S".$itm2}{"SYSTEM"} = "TEXT"; } } The if statement (with the defined/exists check) criteria passes first pass but fails in the second. Can anyone tell me why? __________________________________________________________________ Connect with friends from any web browser - no download required. Try the new Yahoo! Canada Messenger for the Web BETA at http://ca.messenger.yahoo.com/webmessengerpromo.php From abez at abez.ca Wed Jul 29 11:52:54 2009 From: abez at abez.ca (abez) Date: Wed, 29 Jul 2009 14:52:54 -0400 Subject: [kw-pm] Problem with hash In-Reply-To: <617605.72544.qm@web58702.mail.re1.yahoo.com> (sfid-20090729_142105_989900_9DDBDD10) References: <617605.72544.qm@web58702.mail.re1.yahoo.com> (sfid-20090729_142105_989900_9DDBDD10) Message-ID: <4A709A86.1010309@abez.ca> This doesn't parse: > for (my $cC=0$cC<=$#aA;$cC++) { Space everything out, I think you're missing a semi-colon for ( my $cC = 0 ; $cC <= $#aA ; $cC++ ) { put use strict; up at the top. It'll tell you that vHash != vHsh (misspelling). Then add a: use Data::Dumper; print Dumper(\%vHsh); at the end of your program and you'll see the hash it makes. You'll notice you're checking for SS0 and S0 because you have this "S".$item2 everywhere. As well you're checking for $vHsh{$itm1}{$itm2}{"SYSTEM"} but in your examples you never set "SYSTEM", you in fact set $vHsh{$itm1}{$itm2} to a scalar value, not a hashref "use strict;" will attempt to spell check your variables. I recommend always using it. I've attached my code at the end of this message. abram Robert Pike wrote: > First off, thanks to all that supplied me with feedback in regards to the issue I was having with redirection in perl. > I loop through an array, split the values, and put certain values in a hash. Hopefully this will be enough info to get some feedback. > > my %vHash; > $vHsh{"101010"}{"S0"} = "text"; > $vHsh{"101010USED"}{"S0"} = "text"; > > my @aA = ("101010~S0", "101010USED~S0"); > #if I were to do this > for (my $cC=0$cC<=$#aA;$cC++) { > ($itm1, $itm2) = split(/\~/,$aA[$cC]); > if (!exists($vHsh{$itm1}{"S".$itm2}{"SYSTEM"})) { #--- also tried defined > $vHsh{$itm1}{"S".$itm2}{"SYSTEM"} = "TEXT"; > } > } > > The if statement (with the defined/exists check) criteria passes first pass but fails in the second. Can anyone tell me why? > > > __________________________________________________________________ > Connect with friends from any web browser - no download required. Try the new Yahoo! Canada Messenger for the Web BETA at http://ca.messenger.yahoo.com/webmessengerpromo.php > > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm use strict; use Data::Dumper; { #make a new scope # this version does not work properly # this is a minor modification to the original version my %vHsh; $vHsh{"101010"}{"S0"} = "text"; $vHsh{"101010USED"}{"S0"} = "text"; my @aA = ("101010~S0", "101010USED~S0"); #if I were to do this my ($itm1, $itm2); #satisfy use strict for (my $cC=0;$cC<=$#aA;$cC++) { ($itm1, $itm2) = split(/\~/,$aA[$cC]); if (!exists($vHsh{$itm1}{"S".$itm2}{"SYSTEM"})) { #--- also tried defined warn "Found [$itm1 $itm2]"; $vHsh{$itm1}{"S".$itm2}{"SYSTEM"} = "TEXT"; } } print Dumper(\%vHsh); } print "$/ Now again but correctly $/"; { # this is the new verison my %vHsh; $vHsh{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; $vHsh{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; my @aA = ("101010~S0", "101010USED~S0"); #if I were to do this for ( my $cC = 0 ; $cC <= $#aA ; $cC++ ) { my ($itm1, $itm2) = split(/\~/,$aA[$cC]); # note the scope if (!exists($vHsh{$itm1}{$itm2}{"SYSTEM"})) { #--- also tried defined warn "Found [$itm1 $itm2]"; $vHsh{$itm1}{$itm2}{"SYSTEM"} = "TEXT"; } } print Dumper(\%vHsh); } -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 260 bytes Desc: OpenPGP digital signature URL: From abez at abez.ca Wed Jul 29 12:52:09 2009 From: abez at abez.ca (abez) Date: Wed, 29 Jul 2009 15:52:09 -0400 Subject: [kw-pm] Problem with hash In-Reply-To: <43855.13091.qm@web58706.mail.re1.yahoo.com> (sfid-20090729_152813_983575_B6171695) References: <43855.13091.qm@web58706.mail.re1.yahoo.com> (sfid-20090729_152813_983575_B6171695) Message-ID: <4A70A869.9060907@abez.ca> Perl is doing exactly what you told it to do. The problem is that you made a mistake and you didn't your code carefully enough to see it. do you see how you're testing {"SYSTEM"}, that's a key in "S0"'s hash. Except you assigned "S0" to a scalar. you're actually trying to overwrite a scalar with a hash that looks like this: { SYSTEM => "TEXT" } when you go $prodFnd{$a}{$b}{SYSTEM} = $c; you really mean is $prodFnd{$a}->{$b}->{SYSTEM} = $c; but $prodFnd{$a}->{$b} is not hash/hashref! You made $prodFnd{$a}->{$b} be "text"; not { SYSTEM => "text" }. There's a difference. Perl is auto-vivifying your hash. It brings it to life, it generates new hashes. Just run this and you'll see that your initial assignments are to things you're not even looking for. Step through it. Look at it. You don't even have the same strings. use Data::Dumper; $prodFnd{"101010"}{"S0"} = "text"; $prodFnd{"101010USED"}{"S0"} = "text"; print Dumper(\%prodFnd); #Do you see "SYSTEM" anywhere? No! if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; print "First
"; print Dumper(\%prodFnd); #you see "SYSTEM" now? No! } if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; print "Second
"; print Dumper(\%prodFnd); #you see "SYSTEM" now? No! } Then run use strict; use Data::Dumper; $prodFnd{"101010"}{"S0"} = "text"; $prodFnd{"101010USED"}{"S0"} = "text"; print Dumper(\%prodFnd); if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; print "First
"; print Dumper(\%prodFnd); } if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; print "Second
"; print Dumper(\%prodFnd); } See all those warnings and errors? Fix those! If you had "use strict;" like recommended this would never have run anyways because "S0" would not be a hash so you couldn't ask it for values. Summary: Hashes are not scalars, scalars are not hashes, use strict For more help, type: perldoc perldata and perldoc -f exists Or go google for perldoc perldata. abram Robert Pike wrote: > Sorry. I actually changed the name of the variables because of the data and such used (sensitive and such). I've simplified the problem I'm having below using the actual data retrieved from the array I'm using in this test. > > $prodFnd{"101010"}{"S0"} = "text"; > $prodFnd{"101010USED"}{"S0"} = "text"; > if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { > $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; > print "First
"; > } > if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { > $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; > print "Second
"; > } > > This will only print First. I had also tried defined to see what I got and the same thing occured. I tried changing 101010USED to something else in the second if and it passed, changed only S0 to something else and it passed, and the same with SYSTEM and it passed. What am I missing? Thank you so much for the response and help as well. I also tried the data dump and it gave me what I expected. If I printed out what was in $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} after the first if block it would actually print "TEXT". Does Perl ignore the letters after it sees letters in the first level of the hash or something? > > > > --- On Wed, 7/29/09, abez wrote: > >> From: abez >> Subject: Re: [kw-pm] Problem with hash >> To: "Robert Pike" >> Cc: "KW Perl Mongers" >> Received: Wednesday, July 29, 2009, 2:52 PM >> >> This doesn't parse: >> >>> for (my $cC=0$cC<=$#aA;$cC++) { >> Space everything out, I think you're missing a semi-colon >> >> for ( my $cC = 0 ; $cC <= $#aA ; $cC++ ) { >> >> put use strict; up at the top. It'll tell you that vHash != >> vHsh >> (misspelling). >> >> Then add a: >> >> use Data::Dumper; >> print Dumper(\%vHsh); >> >> at the end of your program and you'll see the hash it >> makes. >> You'll notice you're checking for SS0 and S0 because you >> have this >> "S".$item2 everywhere. >> >> As well you're checking for $vHsh{$itm1}{$itm2}{"SYSTEM"} >> but in your >> examples you never set "SYSTEM", you in fact set >> $vHsh{$itm1}{$itm2} to >> a scalar value, not a hashref >> >> "use strict;" will attempt to spell check your variables. I >> recommend >> always using it. >> >> I've attached my code at the end of this message. >> >> abram >> >> >> Robert Pike wrote: >>> First off, thanks to all that supplied me with >> feedback in regards to the issue I was having with >> redirection in perl. >>> I loop through an array, split the values, and put >> certain values in a hash. Hopefully this will be enough info >> to get some feedback. >>> my %vHash; >>> $vHsh{"101010"}{"S0"} = "text"; >>> $vHsh{"101010USED"}{"S0"} = "text"; >>> >>> my @aA = ("101010~S0", "101010USED~S0"); >>> #if I were to do this >>> for (my $cC=0$cC<=$#aA;$cC++) { >>> ($itm1, $itm2) = >> split(/\~/,$aA[$cC]); >>> if >> (!exists($vHsh{$itm1}{"S".$itm2}{"SYSTEM"})) { #--- also >> tried defined >>> >> $vHsh{$itm1}{"S".$itm2}{"SYSTEM"} = >> "TEXT"; >>> } >>> } >>> >>> The if statement (with the >> defined/exists check) criteria passes first pass but fails >> in the second. Can anyone tell me why? >>> >>> >> __________________________________________________________________ >>> Connect with friends from any web browser - no >> download required. Try the new Yahoo! Canada Messenger for >> the Web BETA at http://ca.messenger.yahoo.com/webmessengerpromo.php >>> _______________________________________________ >>> kw-pm mailing list >>> kw-pm at pm.org >>> http://mail.pm.org/mailman/listinfo/kw-pm >> use strict; >> use Data::Dumper; >> { #make a new scope >> # this version does not work properly >> # this is a minor modification to the original >> version >> my %vHsh; >> $vHsh{"101010"}{"S0"} = "text"; >> $vHsh{"101010USED"}{"S0"} = "text"; >> >> my @aA = ("101010~S0", "101010USED~S0"); >> #if I were to do this >> my ($itm1, $itm2); #satisfy use strict >> for (my $cC=0;$cC<=$#aA;$cC++) { >> ($itm1, $itm2) = >> split(/\~/,$aA[$cC]); >> if >> (!exists($vHsh{$itm1}{"S".$itm2}{"SYSTEM"})) { #--- also >> tried >> defined >> warn "Found [$itm1 $itm2]"; >> >> $vHsh{$itm1}{"S".$itm2}{"SYSTEM"} = "TEXT"; >> } >> } >> print Dumper(\%vHsh); >> } >> >> print "$/ Now again but correctly $/"; >> { >> # this is the new verison >> my %vHsh; >> $vHsh{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; >> $vHsh{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; >> >> my @aA = ("101010~S0", "101010USED~S0"); >> #if I were to do this >> for ( my $cC = 0 ; $cC <= $#aA ; $cC++ ) { >> my ($itm1, $itm2) = >> split(/\~/,$aA[$cC]); # note the scope >> if >> (!exists($vHsh{$itm1}{$itm2}{"SYSTEM"})) { #--- also tried >> defined >> warn "Found [$itm1 $itm2]"; >> >> $vHsh{$itm1}{$itm2}{"SYSTEM"} = "TEXT"; >> } >> } >> print Dumper(\%vHsh); >> } >> >> >> >> >> > > > __________________________________________________________________ > Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now > http://ca.toolbar.yahoo.com. use strict; use Data::Dumper; my %prodFnd; $prodFnd{"101010"}{"S0"} = "text"; $prodFnd{"101010USED"}{"S0"} = "text"; print Dumper(\%prodFnd); if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; print "First
"; print Dumper(\%prodFnd); } if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; print "Second
"; print Dumper(\%prodFnd); } -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 260 bytes Desc: OpenPGP digital signature URL: From eric at uc.org Wed Jul 29 13:09:42 2009 From: eric at uc.org (Eric Maki) Date: Wed, 29 Jul 2009 16:09:42 -0400 (EDT) Subject: [kw-pm] Problem with hash In-Reply-To: <4A70A869.9060907@abez.ca> References: <43855.13091.qm@web58706.mail.re1.yahoo.com> (sfid-20090729_152813_983575_B6171695) <4A70A869.9060907@abez.ca> Message-ID: If you are curious about what Perl thinks you want it to do, toss print Dumper \%text; at the end of your program: $VAR1 = { 'SYSTEM' => 'TEXT' }; This is because: $prodFnd{"101010"}{"S0"} = "text"; and then $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; because you are 'use strict;'ing, soft references are allowed, so $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; means $text{"SYSTEM"} = "TEXT"; So, you just created a hash named %text and assigned to it. use strict 'refs'; was introduced because that behaviour is very frequently not what you want. Eric ---- original message : 2009-07-29 3:52pm : abez ---- > Perl is doing exactly what you told it to do. The problem is that you > made a mistake and you didn't your code carefully enough to see it. > > do you see how you're testing {"SYSTEM"}, that's a key in "S0"'s hash. > > Except you assigned "S0" to a scalar. > > you're actually trying to overwrite a scalar with a hash that looks like > this: > > { > SYSTEM => "TEXT" > } > > when you go $prodFnd{$a}{$b}{SYSTEM} = $c; > you really mean is > > $prodFnd{$a}->{$b}->{SYSTEM} = $c; > > but $prodFnd{$a}->{$b} is not hash/hashref! > > You made $prodFnd{$a}->{$b} be "text"; > not { SYSTEM => "text" }. There's a difference. > > Perl is auto-vivifying your hash. It brings it to life, it generates new > hashes. > > Just run this and you'll see that your initial assignments are to things > you're not even looking for. Step through it. Look at it. You don't even > have the same strings. > > use Data::Dumper; > $prodFnd{"101010"}{"S0"} = "text"; > $prodFnd{"101010USED"}{"S0"} = "text"; > print Dumper(\%prodFnd); #Do you see "SYSTEM" anywhere? No! > if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { > $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; > print "First
"; > print Dumper(\%prodFnd); #you see "SYSTEM" now? No! > } > if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { > $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; > print "Second
"; > print Dumper(\%prodFnd); #you see "SYSTEM" now? No! > } > > Then run > use strict; > use Data::Dumper; > $prodFnd{"101010"}{"S0"} = "text"; > $prodFnd{"101010USED"}{"S0"} = "text"; > print Dumper(\%prodFnd); > if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { > $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; > print "First
"; > print Dumper(\%prodFnd); > } > if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { > $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; > print "Second
"; > print Dumper(\%prodFnd); > } > > See all those warnings and errors? Fix those! > > If you had "use strict;" like recommended this would never have run > anyways because "S0" would not be a hash so you couldn't ask it for values. > > Summary: Hashes are not scalars, scalars are not hashes, use strict > > For more help, type: > perldoc perldata > and > perldoc -f exists > > Or go google for perldoc perldata. > > abram > > > > Robert Pike wrote: >> Sorry. I actually changed the name of the variables because of the data and such used (sensitive and such). I've simplified the problem I'm having below using the actual data retrieved from the array I'm using in this test. >> >> $prodFnd{"101010"}{"S0"} = "text"; >> $prodFnd{"101010USED"}{"S0"} = "text"; >> if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { >> $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; >> print "First
"; >> } >> if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { >> $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; >> print "Second
"; >> } >> >> This will only print First. I had also tried defined to see what I got and the same thing occured. I tried changing 101010USED to something else in the second if and it passed, changed only S0 to something else and it passed, and the same with SYSTEM and it passed. What am I missing? Thank you so much for the response and help as well. I also tried the data dump and it gave me what I expected. If I printed out what was in $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} after the first if block it would actually print "TEXT". Does Perl ignore the letters after it sees letters in the first level of the hash or something? >> >> >> >> --- On Wed, 7/29/09, abez wrote: >> >>> From: abez >>> Subject: Re: [kw-pm] Problem with hash >>> To: "Robert Pike" >>> Cc: "KW Perl Mongers" >>> Received: Wednesday, July 29, 2009, 2:52 PM >>> >>> This doesn't parse: >>> >>>> for (my $cC=0$cC<=$#aA;$cC++) { >>> Space everything out, I think you're missing a semi-colon >>> >>> for ( my $cC = 0 ; $cC <= $#aA ; $cC++ ) { >>> >>> put use strict; up at the top. It'll tell you that vHash != >>> vHsh >>> (misspelling). >>> >>> Then add a: >>> >>> use Data::Dumper; >>> print Dumper(\%vHsh); >>> >>> at the end of your program and you'll see the hash it >>> makes. >>> You'll notice you're checking for SS0 and S0 because you >>> have this >>> "S".$item2 everywhere. >>> >>> As well you're checking for $vHsh{$itm1}{$itm2}{"SYSTEM"} >>> but in your >>> examples you never set "SYSTEM", you in fact set >>> $vHsh{$itm1}{$itm2} to >>> a scalar value, not a hashref >>> >>> "use strict;" will attempt to spell check your variables. I >>> recommend >>> always using it. >>> >>> I've attached my code at the end of this message. >>> >>> abram >>> >>> >>> Robert Pike wrote: >>>> First off, thanks to all that supplied me with >>> feedback in regards to the issue I was having with >>> redirection in perl. >>>> I loop through an array, split the values, and put >>> certain values in a hash. Hopefully this will be enough info >>> to get some feedback. >>>> my %vHash; >>>> $vHsh{"101010"}{"S0"} = "text"; >>>> $vHsh{"101010USED"}{"S0"} = "text"; >>>> >>>> my @aA = ("101010~S0", "101010USED~S0"); >>>> #if I were to do this >>>> for (my $cC=0$cC<=$#aA;$cC++) { >>>> ($itm1, $itm2) = >>> split(/\~/,$aA[$cC]); >>>> if >>> (!exists($vHsh{$itm1}{"S".$itm2}{"SYSTEM"})) { #--- also >>> tried defined >>>> >>> $vHsh{$itm1}{"S".$itm2}{"SYSTEM"} = >>> "TEXT"; >>>> } >>>> } >>>> >>>> The if statement (with the >>> defined/exists check) criteria passes first pass but fails >>> in the second. Can anyone tell me why? >>>> >>>> >>> __________________________________________________________________ >>>> Connect with friends from any web browser - no >>> download required. Try the new Yahoo! Canada Messenger for >>> the Web BETA at http://ca.messenger.yahoo.com/webmessengerpromo.php >>>> _______________________________________________ >>>> kw-pm mailing list >>>> kw-pm at pm.org >>>> http://mail.pm.org/mailman/listinfo/kw-pm >>> use strict; >>> use Data::Dumper; >>> { #make a new scope >>> # this version does not work properly >>> # this is a minor modification to the original >>> version >>> my %vHsh; >>> $vHsh{"101010"}{"S0"} = "text"; >>> $vHsh{"101010USED"}{"S0"} = "text"; >>> >>> my @aA = ("101010~S0", "101010USED~S0"); >>> #if I were to do this >>> my ($itm1, $itm2); #satisfy use strict >>> for (my $cC=0;$cC<=$#aA;$cC++) { >>> ($itm1, $itm2) = >>> split(/\~/,$aA[$cC]); >>> if >>> (!exists($vHsh{$itm1}{"S".$itm2}{"SYSTEM"})) { #--- also >>> tried >>> defined >>> warn "Found [$itm1 $itm2]"; >>> >>> $vHsh{$itm1}{"S".$itm2}{"SYSTEM"} = "TEXT"; >>> } >>> } >>> print Dumper(\%vHsh); >>> } >>> >>> print "$/ Now again but correctly $/"; >>> { >>> # this is the new verison >>> my %vHsh; >>> $vHsh{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; >>> $vHsh{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; >>> >>> my @aA = ("101010~S0", "101010USED~S0"); >>> #if I were to do this >>> for ( my $cC = 0 ; $cC <= $#aA ; $cC++ ) { >>> my ($itm1, $itm2) = >>> split(/\~/,$aA[$cC]); # note the scope >>> if >>> (!exists($vHsh{$itm1}{$itm2}{"SYSTEM"})) { #--- also tried >>> defined >>> warn "Found [$itm1 $itm2]"; >>> >>> $vHsh{$itm1}{$itm2}{"SYSTEM"} = "TEXT"; >>> } >>> } >>> print Dumper(\%vHsh); >>> } >>> >>> >>> >>> >>> >> >> >> __________________________________________________________________ >> Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now >> http://ca.toolbar.yahoo.com. > use strict; > use Data::Dumper; > my %prodFnd; > $prodFnd{"101010"}{"S0"} = "text"; > $prodFnd{"101010USED"}{"S0"} = "text"; > print Dumper(\%prodFnd); > if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { > $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; > print "First
"; > print Dumper(\%prodFnd); > } > if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { > $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; > print "Second
"; > print Dumper(\%prodFnd); > } > > > From eric at uc.org Wed Jul 29 13:15:39 2009 From: eric at uc.org (Eric Maki) Date: Wed, 29 Jul 2009 16:15:39 -0400 (EDT) Subject: [kw-pm] Problem with hash In-Reply-To: References: <43855.13091.qm@web58706.mail.re1.yahoo.com> (sfid-20090729_152813_983575_B6171695) <4A70A869.9060907@abez.ca> Message-ID: > because you are 'use strict;'ing, soft references are allowed, I meant because you are not 'use strict;'ing See perldoc strict "strict refs" for a discussion of symbolic references. ---- original message : 2009-07-29 4:09pm : Eric Maki ---- > > If you are curious about what Perl thinks you want it to do, toss > > print Dumper \%text; > > at the end of your program: > > $VAR1 = { > 'SYSTEM' => 'TEXT' > }; > > This is because: > > $prodFnd{"101010"}{"S0"} = "text"; > > and then > > $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; > > because you are 'use strict;'ing, soft references are allowed, so > > $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; > > means > > $text{"SYSTEM"} = "TEXT"; > > So, you just created a hash named %text and assigned to it. > > use strict 'refs'; was introduced because that behaviour is very frequently > not what you want. > > Eric > > > ---- original message : 2009-07-29 3:52pm : abez ---- > >> Perl is doing exactly what you told it to do. The problem is that you >> made a mistake and you didn't your code carefully enough to see it. >> >> do you see how you're testing {"SYSTEM"}, that's a key in "S0"'s hash. >> >> Except you assigned "S0" to a scalar. >> >> you're actually trying to overwrite a scalar with a hash that looks like >> this: >> >> { >> SYSTEM => "TEXT" >> } >> >> when you go $prodFnd{$a}{$b}{SYSTEM} = $c; >> you really mean is >> >> $prodFnd{$a}->{$b}->{SYSTEM} = $c; >> >> but $prodFnd{$a}->{$b} is not hash/hashref! >> >> You made $prodFnd{$a}->{$b} be "text"; >> not { SYSTEM => "text" }. There's a difference. >> >> Perl is auto-vivifying your hash. It brings it to life, it generates new >> hashes. >> >> Just run this and you'll see that your initial assignments are to things >> you're not even looking for. Step through it. Look at it. You don't even >> have the same strings. >> >> use Data::Dumper; >> $prodFnd{"101010"}{"S0"} = "text"; >> $prodFnd{"101010USED"}{"S0"} = "text"; >> print Dumper(\%prodFnd); #Do you see "SYSTEM" anywhere? No! >> if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { >> $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; >> print "First
"; >> print Dumper(\%prodFnd); #you see "SYSTEM" now? No! >> } >> if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { >> $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; >> print "Second
"; >> print Dumper(\%prodFnd); #you see "SYSTEM" now? No! >> } >> >> Then run >> use strict; >> use Data::Dumper; >> $prodFnd{"101010"}{"S0"} = "text"; >> $prodFnd{"101010USED"}{"S0"} = "text"; >> print Dumper(\%prodFnd); >> if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { >> $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; >> print "First
"; >> print Dumper(\%prodFnd); >> } >> if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { >> $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; >> print "Second
"; >> print Dumper(\%prodFnd); >> } >> >> See all those warnings and errors? Fix those! >> >> If you had "use strict;" like recommended this would never have run >> anyways because "S0" would not be a hash so you couldn't ask it for values. >> >> Summary: Hashes are not scalars, scalars are not hashes, use strict >> >> For more help, type: >> perldoc perldata >> and >> perldoc -f exists >> >> Or go google for perldoc perldata. >> >> abram >> >> >> >> Robert Pike wrote: >>> Sorry. I actually changed the name of the variables because of the data >>> and such used (sensitive and such). I've simplified the problem I'm having >>> below using the actual data retrieved from the array I'm using in this >>> test. >>> >>> $prodFnd{"101010"}{"S0"} = "text"; >>> $prodFnd{"101010USED"}{"S0"} = "text"; >>> if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { >>> $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; >>> print "First
"; >>> } >>> if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { >>> $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; >>> print "Second
"; >>> } >>> >>> This will only print First. I had also tried defined to see what I got and >>> the same thing occured. I tried changing 101010USED to something else in >>> the second if and it passed, changed only S0 to something else and it >>> passed, and the same with SYSTEM and it passed. What am I missing? Thank >>> you so much for the response and help as well. I also tried the data dump >>> and it gave me what I expected. If I printed out what was in >>> $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} after the first if block it would >>> actually print "TEXT". Does Perl ignore the letters after it sees letters >>> in the first level of the hash or something? >>> >>> >>> >>> --- On Wed, 7/29/09, abez wrote: >>> >>>> From: abez >>>> Subject: Re: [kw-pm] Problem with hash >>>> To: "Robert Pike" >>>> Cc: "KW Perl Mongers" >>>> Received: Wednesday, July 29, 2009, 2:52 PM >>>> >>>> This doesn't parse: >>>> >>>>> for (my $cC=0$cC<=$#aA;$cC++) { >>>> Space everything out, I think you're missing a semi-colon >>>> >>>> for ( my $cC = 0 ; $cC <= $#aA ; $cC++ ) { >>>> >>>> put use strict; up at the top. It'll tell you that vHash != >>>> vHsh >>>> (misspelling). >>>> >>>> Then add a: >>>> >>>> use Data::Dumper; >>>> print Dumper(\%vHsh); >>>> >>>> at the end of your program and you'll see the hash it >>>> makes. >>>> You'll notice you're checking for SS0 and S0 because you >>>> have this >>>> "S".$item2 everywhere. >>>> >>>> As well you're checking for $vHsh{$itm1}{$itm2}{"SYSTEM"} >>>> but in your >>>> examples you never set "SYSTEM", you in fact set >>>> $vHsh{$itm1}{$itm2} to >>>> a scalar value, not a hashref >>>> >>>> "use strict;" will attempt to spell check your variables. I >>>> recommend >>>> always using it. >>>> >>>> I've attached my code at the end of this message. >>>> >>>> abram >>>> >>>> >>>> Robert Pike wrote: >>>>> First off, thanks to all that supplied me with >>>> feedback in regards to the issue I was having with >>>> redirection in perl. >>>>> I loop through an array, split the values, and put >>>> certain values in a hash. Hopefully this will be enough info >>>> to get some feedback. >>>>> my %vHash; >>>>> $vHsh{"101010"}{"S0"} = "text"; >>>>> $vHsh{"101010USED"}{"S0"} = "text"; >>>>> >>>>> my @aA = ("101010~S0", "101010USED~S0"); >>>>> #if I were to do this >>>>> for (my $cC=0$cC<=$#aA;$cC++) { >>>>> ($itm1, $itm2) = >>>> split(/\~/,$aA[$cC]); >>>>> if >>>> (!exists($vHsh{$itm1}{"S".$itm2}{"SYSTEM"})) { #--- also >>>> tried defined >>>>> >>>> $vHsh{$itm1}{"S".$itm2}{"SYSTEM"} = >>>> "TEXT"; >>>>> } >>>>> } >>>>> >>>>> The if statement (with the >>>> defined/exists check) criteria passes first pass but fails >>>> in the second. Can anyone tell me why? >>>>> >>>>> >>>> __________________________________________________________________ >>>>> Connect with friends from any web browser - no >>>> download required. Try the new Yahoo! Canada Messenger for >>>> the Web BETA at http://ca.messenger.yahoo.com/webmessengerpromo.php >>>>> _______________________________________________ >>>>> kw-pm mailing list >>>>> kw-pm at pm.org >>>>> http://mail.pm.org/mailman/listinfo/kw-pm >>>> use strict; >>>> use Data::Dumper; >>>> { #make a new scope >>>> # this version does not work properly >>>> # this is a minor modification to the original >>>> version >>>> my %vHsh; >>>> $vHsh{"101010"}{"S0"} = "text"; >>>> $vHsh{"101010USED"}{"S0"} = "text"; >>>> >>>> my @aA = ("101010~S0", "101010USED~S0"); >>>> #if I were to do this >>>> my ($itm1, $itm2); #satisfy use strict >>>> for (my $cC=0;$cC<=$#aA;$cC++) { >>>> ($itm1, $itm2) = >>>> split(/\~/,$aA[$cC]); >>>> if >>>> (!exists($vHsh{$itm1}{"S".$itm2}{"SYSTEM"})) { #--- also >>>> tried >>>> defined >>>> warn "Found [$itm1 $itm2]"; >>>> >>>> $vHsh{$itm1}{"S".$itm2}{"SYSTEM"} = "TEXT"; >>>> } >>>> } >>>> print Dumper(\%vHsh); >>>> } >>>> >>>> print "$/ Now again but correctly $/"; >>>> { >>>> # this is the new verison >>>> my %vHsh; >>>> $vHsh{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; >>>> $vHsh{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; >>>> >>>> my @aA = ("101010~S0", "101010USED~S0"); >>>> #if I were to do this >>>> for ( my $cC = 0 ; $cC <= $#aA ; $cC++ ) { >>>> my ($itm1, $itm2) = >>>> split(/\~/,$aA[$cC]); # note the scope >>>> if >>>> (!exists($vHsh{$itm1}{$itm2}{"SYSTEM"})) { #--- also tried >>>> defined >>>> warn "Found [$itm1 $itm2]"; >>>> >>>> $vHsh{$itm1}{$itm2}{"SYSTEM"} = "TEXT"; >>>> } >>>> } >>>> print Dumper(\%vHsh); >>>> } >>>> >>>> >>>> >>>> >>>> >>> >>> >>> __________________________________________________________________ >>> Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your >>> favourite sites. Download it now >>> http://ca.toolbar.yahoo.com. >> use strict; >> use Data::Dumper; >> my %prodFnd; >> $prodFnd{"101010"}{"S0"} = "text"; >> $prodFnd{"101010USED"}{"S0"} = "text"; >> print Dumper(\%prodFnd); >> if (!exists($prodFnd{"101010"}{"S0"}{"SYSTEM"})) { >> $prodFnd{"101010"}{"S0"}{"SYSTEM"} = "TEXT"; >> print "First
"; >> print Dumper(\%prodFnd); >> } >> if (!exists($prodFnd{"101010USED"}{"S0"}{"SYSTEM"})) { >> $prodFnd{"101010USED"}{"S0"}{"SYSTEM"} = "TEXT"; >> print "Second
"; >> print Dumper(\%prodFnd); >> } >> >> >> > _______________________________________________ > kw-pm mailing list > kw-pm at pm.org > http://mail.pm.org/mailman/listinfo/kw-pm >