Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Add strings together

    What I am trying to do is simple enough, I know some JavaScript so?

    var name = "corrie";
    var holder = "hi my name is "+name+" what's yours?";

    but how to write the above in perl is baffling me, I'm just a beginner in perl and the '$ % @' things are really messing with my head, so that's probably my problem, I know the first is a variable, second is an associative array, and third is a plane old array, but the associations between them (how you can reference the @person with $person[1]) is just confusing me, if anyone knows any good tutorials that cover this in great detail please let me know.

    Thanks
    corrie track

  • #2
    New Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Its quite slow round here these days, no matter I've solved this, if anyone's interested?

    $name = "such and such "."is linked into this" ## yes, a dot. That was what was holding me back, a dot.

    Well, it is usually the smallest things that get me.
    corrie track

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Once you get over the initial shock of the funny symbols you'll find them really useful, for example, if you were doing a Perl version of your JavaScript code, you'd go:

    Code:
    $name = "Corrie";
    $holder = "Hi, my name is $name, what's yours?";
    As you can see, you can just write the name of the variable within a double-quoted string and Perl will interpolate it for you.

    As for the $array[3] bit, it might seem a little weird at first, but if you think about it carefully it actually makes more sense to use the $ symbol here. Since what you're actually accessing with this syntax is a single scalar value, it makes sense to use the single scalar symbol...

    To be honest just learning the basic scalar, array and associative array stuff is worth it, it makes sense once you get the hang of it

    If you want to learn Perl, the best learning book, especially if you're not an experienced programmer already is Learning Perl by Randal Schwartz and Tom Christiansen (I think). But the definitive Perl book, which is slightly meatier and pretty comprehensive is called Programming Perl by Larry Wall, Jon Orwant and Tom Christiansen, also called the Camel Book.

    There are millions of beginner's tutorials for Perl out there though, just do a search on Google and some will turn up.

  • #4
    New Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Mouldy_Goat, I've seen that in a tutorial somewhere before (and should have remembered), its just such a big step from JavaScript, putting a variable in a string with JavaScript that way would have been unthinkable, so naturally I never thought of it

    I'll have a look for those books, thanks again
    corrie track


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •