Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > BOOK: Beginning Perl
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Perl
This is the forum to discuss the Wrox book Beginning Perl by Curtis Poe; ISBN: 978-1-118-01384-7
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Perl section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 29th, 2014, 11:06 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Id like to understand this

Hi,

I’d like to understand this. Please see below. This is about page 26 of the book "Biginning Perl".

print oct(0b11010), "\n";

produces 22

But,

print oct(“0b11010”), "\n";

produces 26.

Why is that?

Shouldn’t it always produce 26 as that’s what binary 11010 is.

Thanks!
Reply With Quote
  #2 (permalink)  
Old April 27th, 2015, 06:27 AM
Registered User
Points: 11, Level: 1
Points: 11, Level: 1 Points: 11, Level: 1 Points: 11, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2015
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb A long overdue and outdated reply...

I'm 99% sure the original poster has long since figured this out, and is probably no longer working through this book, but heres a reply for my own benefit, as well as anyone else who may have the same questions now or in the future.


Notice the first print line is placing the print line directly within the parentheses, as shown here:

Code:
oct(0b11010)
which is interpreting 11010 in binary.

while the second example is quoting the entire binary string within the quotes:

Code:
oct(“0b11010”)
which interprets 011010 in binary.

Essentially, quoting the string equates to the following code:
Code:
oct(0b011010)
basically, quoting the string is adding an extra 0 to the binary sequence, which is where the output of 26 comes from. I'm not sure why perl does this, as i just started the book a few days ago, but at least it solves the question of why you're receiving different results.

Last edited by okcomputer; April 27th, 2015 at 06:35 AM.
Reply With Quote
Reply


Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Don't understand which errors metinhoclam XSLT 8 July 30th, 2010 05:54 AM
Please help me understand SeanDunn BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 3 November 14th, 2009 02:38 PM
I don't understand for some contents... jay0715 BOOK: Ivor Horton's Beginning Visual C++ 2005 0 November 4th, 2007 07:39 AM
I don't understand... jmsherry ASP.NET 2.0 Basics 17 July 23rd, 2007 01:28 PM
I still do not understand aude_poullain ASP.NET 1.0 and 1.1 Basics 2 February 7th, 2007 09:11 PM



All times are GMT -4. The time now is 10:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.