Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > BOOK: Beginning Perl
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2014, 10:06 AM
Registered User
 
Join Date: Aug 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default I’d 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!
 
Old April 27th, 2015, 05:27 AM
Registered User
 
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 05:35 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Don't understand which errors metinhoclam XSLT 8 July 30th, 2010 04: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 12:28 PM
I still do not understand aude_poullain ASP.NET 1.0 and 1.1 Basics 2 February 7th, 2007 09:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.