Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 10th, 2009, 01:04 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 8,344 Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 4 Days 13 h 47 m 33 sec
Reputation Power: 2532
Perl puzzle of the week/month/year

As promised, here's the new perl puzzle of the week/month/year. This one is short and sweet.
perl Code:
Original - perl Code
  1.  
  2. #!/usr/bin/perl –aw
  3. use strict;
  4.  
  5. my $x = 23;
  6. my $y = 42;
  7. my $z = 69;
  8.  
  9. $a = ($x + $y) * $z;
  10. print “a = $a\n”;

The question here is why does this code run fine, in spite of the use strict; directive?

As before, usual rules apply:
* I will post the solution on friday, if no one else has got it by then.
* First person/people to post the correct answer will have their names on my signature for a while (until I post the next puzzle)
* Judge's discretion is final
* Keep on truckin'
Comments on this post
ishnid agrees: Puzzles are fun. More, more!
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by Fishmonger, superior perl programmer of the month

Last edited by Scorpions4ever : August 10th, 2009 at 01:08 PM.

Reply With Quote
  #2  
Old August 10th, 2009, 01:25 PM
FishMonger FishMonger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 261 FishMonger User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)FishMonger User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)FishMonger User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)FishMonger User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)FishMonger User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)FishMonger User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)FishMonger User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)FishMonger User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)FishMonger User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)FishMonger User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)FishMonger User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Week 48 m 31 sec
Reputation Power: 403
$a as well as $b are built-in global vars that are used in sorting and while using them outside of a sort routine is allowed, it's discouraged.

EDIT: maybe I should post the related documentation from perldoc perlvar

Quote:
# $a
# $b

Special package variables when using sort(), see sort. Because of this specialness $a and $b don't need to be declared (using use vars, or our()) even when using the strict 'vars' pragma. Don't lexicalize them with my $a or my $b if you want to be able to use them in the sort() comparison block or function.

Last edited by FishMonger : August 10th, 2009 at 01:33 PM.

Reply With Quote
  #3  
Old August 10th, 2009, 02:01 PM
KevinADC's Avatar
KevinADC KevinADC is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2004
Location: Sunny Southern California
Posts: 2,687 KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level)KevinADC User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 12 h 54 m 48 sec
Reputation Power: 857
My answer would have been the same as FishMongers. Not sure why you have the -a switch on the shebang line. Might confuse some people trying to answer the question(s) thinking it somehow makes the code fly.

Reply With Quote
  #4  
Old August 11th, 2009, 02:49 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 8,344 Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 4 Days 13 h 47 m 33 sec
Reputation Power: 2532
Fishmonger: That was the correct answer

KevinADC: The -a was a red herring. Originally when I posted the puzzle in my office, I was messing with another predefined var that gets activated with -a, but it didn't work right.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Perl puzzle of the week/month/year


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek