in reply to Re^2: Turning a hash into a line of links
in thread Turning a hash into a line of links

tr//--Now there's another element of perl with which I am not very familiar. When I was devising my plan, I decided that I wanted to only loop through/traverse the string once, thus the array of positions of the pipes. Does tr not loop through the string? I'll have to look that up. I was focused on the thought that I will have to loop through the string once to count all the pipes; might as well save the positions while I am there so I don't have to go back through to "find" the middle one. Yeah I had to use the number of elements in the @pipes array to do some funky arithmetic, but only one time through the string.

I've seen the q{} contruct more than once now. Do you guys use a lot of strings that contain embedded quotes? What are the relative merits of q{hi} vs 'hi'?

Thanks,
Terrence

UPDATE: I figured out what tr/// does. I kept bouncing back and forth between tr///, which says "same as y///" and y///, which says "same as tr///." Finally saw the part that says "see perlop." Thanks.


I like computer programming because it's like Legos for the mind.
  • Comment on Re^3: Turning a hash into a line of links

Replies are listed 'Best First'.
Re^4: Turning a hash into a line of links
by johngg (Canon) on Dec 13, 2006 at 20:45 UTC
    I have hardly ever used tr but I bumped into it the other day when looking something else up in the Camel Book. I thought that it could be useful for just the thing you are doing. It would be interesting to benchmark the various ways of counting characters or strings within strings.

    Regarding q{} and qq{}, I am from a *nix background and had never had any problem with normal single- and double-quotes. Then I started trying to do one-liners under MS Windoze and struggled. The quoting operators made it all work nicely and since then, to avoid having to think where I am, I have got into the habit of using them all the time. I don't think that there is any particular merit either way other than normal quotes are widely familiar and take fewer keystrokes, quoting operators do the right thing at the DOS prompt.

    Cheers,

    JohnGG

      That's a great story, and it makes perfect sense. I remember one guy recruiting me to work for a perl company and he mentioned that the code is written in *nix but it has to work in both. If I ever end up interviewing for a job there, I'll already know a good trick for writing portable code. Thanks.

      I like computer programming because it's like Legos for the mind.