CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
strings

 



jazzo
Novice

Aug 5, 2012, 2:57 AM

Post #1 of 5 (1338 views)
strings Can't Post

Hi there, I have just started looking into perl, and I have a very beginner question about strings (I had a quick look at the FAQ but couldn't find anything).
Basically take the following basic script:


Code
#!/usr/bin/perl 
use warnings;
print "hi there", "\n" ;


What's the difference between the above and this:


Code
#!/usr/bin/perl 
use warnings;
print "hi there\n" ;


thanks


Laurent_R
Veteran / Moderator

Aug 5, 2012, 9:40 AM

Post #2 of 5 (1328 views)
Re: [jazzo] strings [In reply to] Can't Post

Both approaches are correct and will give the same result.

The print function expects a filehandle (which can be omitted you you want to print to the standard output) and a list of items to be printed.

In the first case, your list has two strings to be printed, and print will happily print the two items one after the other, whereas in the second case the two strings are first merged into one, and then the merged string is printed.

The Camel book has this to say about the two techniques: "print with a comma separator may be faster than concatenating strings."

In most cases, it will not really make a difference, but if you process a very large amount of data, it may have some impact.


jazzo
Novice

Aug 5, 2012, 3:11 PM

Post #3 of 5 (1319 views)
Re: [Laurent_R] strings [In reply to] Can't Post

fantastic, thanks for that, and sorry if it was a dumb question, but as I said I have just started.
On a slightly different note, what's the camel book? I am using this to learn about perl http://www.perl.org/books/beginning-perl/, do you think it is any good?


Laurent_R
Veteran / Moderator

Aug 6, 2012, 5:13 AM

Post #4 of 5 (1296 views)
Re: [jazzo] strings [In reply to] Can't Post

The "Camel book" is "Programming Perl" book, which is sort of the Perl "bible". It is a 1,000-page book by Larry Wall (the creator of Perl), Tom Christiansen and Jon Orwant. It is published by O' Reilly, and its cover has a black-and-white drawing of a camel (well, actually a dromedary, i.e. one-hump camel), hence the nickname for this book.

This is really a reference, byt may probably not be the best book for a pure beginner.



Since the book you are using is available at www.perl.org, I would assume it is very probably a quite good book, and a quick look at it confirmed this impression.


jazzo
Novice

Aug 6, 2012, 9:55 AM

Post #5 of 5 (1291 views)
Re: [Laurent_R] strings [In reply to] Can't Post

fantastic thanks a lot

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives