I'm a Perl5 programmer for 7 years and I'm trying to learn C++ now. Some of the C++ syntax is hard for me to understand and to think in C++ way.
For example: In Perl, you can mix the data in the arrays
@array = (1,"string",5.355);
You can assign any value to a scalar variable:
$var = 1;
$var = "string";
$var = \$reference_to_scalar;
There are many examples.
A friend of mine recommend me the book "Thinking of C++" by Bruce Eckel, but I haven't any C background and it's hard for me to understand some things.
So my question is - could you recommend me a book for this situation. I don't want to learn C. I understand OOP (I'm getting more familiar with C++ oop aswell), I understand the point of the pointers (and some arithmetic) and references (widely used in Perl).
I don't need manuals for dummies (what is int
, bool
, double
, if
, while
), I just need a direction how to learn C++ from the perspective of a Perl programmer, because I'm sure that there are many like me.
Thank you in advance.
EDIT: Thank you for all the recommended books and the answers, I will try with "Accelerated C++". I will start from the beginning and try to change my mindflow to C++. I have added the "beginner" tag.
Why it is still relevant in 2022. Perl is not going away even if it tends to be less trendy than other modern languages. It is used in production codebases of many companies, for tasks as diverse as web development, databases access, log analysis or web crawling. It is a core component of most unix-like systems.
Perl is an interpreted programming language. C++ is a general-purpose object-oriented programming (OOP) language. Perl can use closures with unreachable private data as objects. C/C++ doesn't support closures where closures can be considered as function that can be stored as a variable.
C is the foundation that most other languages and programming language creators have built other languages on top of C, including Python, Ruby, JavaScript, and C++. By knowing C, you are setting yourself up for success in understanding other programming languages widely used in the industry.
Let's say you are new to programming. There are a variety of languages to choose from. Many people will recommend Python as your first language because of its short syntax which makes it very attractive.
"C++ For Perl Programmers" is a pretty specific request. Given that Perl abstracts away more of the machine than C++ does, I think that a good way to start would be to forget what you know about Perl and get a regular C++ book.
For example, it seems reasonable to you that you should be allowed to have multiple data types in an array, because a Perl array is a higher-level construct than just a series of contiguous words in memory. If I were going to go from an array in C++ to one in Perl, I would say that a Perl array is like a C++ array that holds pointers to data instead of data (if that is even true - I am not a Perl programmer so it may not be. Maybe a Perl array is more like a linked list data structure. In any case, you get the idea.) Going backwards, IMO, is not quite the same.
As far as the book I'd recommend - there are a lot of good ones, so it depends on the style and depth you're looking for. I think Accelerated C++ is great for ramping up - its thorough and covers a lot of ground without inundating you with the tedious details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With