You could, of course, do it this way, but I'd prefer a repetition quantifier in this case, because the brackets use to catch their content, which is rather boring because it's always three colons. My solution would have been something like:

1) Why add the overhead of loading IO::File when I can just use open? My application is fairly memory intensive as it is so I need to avoid overhead as much as possible.

2) How does Perl know that the colon following the string variable isn't part of the variable name? Put another way, how does it know to interpolate the value of $code and not $code:?

3) I simplified the example conversion file for the purpose of asking my main question. However, in reality, the values following the 3 colons could be a string which includes spaces, special characters etc. For example, it could look like:

mycomment:::Perl's an awesome language! myemail:::me@me.com mycode::::this string begins with a colon. See the fourth colon over there? Isn't it pretty :)

So, I was wondering if I should modify the regex to:

Code

/^$code:{3}(\w+)$/ # added a $ to the end

Also note that I don't want the trailing carriage return, which I don't get when I use split().

Talk with ya later.

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!

1) Why add the overhead of loading IO::File when I can just use open? My application is fairly memory intensive as it is so I need to avoid overhead as much as possible.

I don't think it'll introduce too much overhead. However, you could use open as well.

In Reply To

2) How does Perl know that the colon following the string variable isn't part of the variable name? Put another way, how does it know to interpolate the value of $code and not $code:?

In Perl, the colon isn't a valid character for an identifier. So Perl will always stop before the colon and use only $code. However, there's a problem if two colons follow a variable name, because then the name of the variable is treated as a namespace:

This will print "Hello" and complain about $code being used only once. To achieve the (expected?) result, one has to write the following instead of the above:

Code

print "${code}::test\n";

which will print "Test::test". I'm not sure about what exactly happens inside the perl interpreter if you put three colons after the identifier, as in your case, but to me it looks like it tries to access a variable in another namespace with the empty string as identifier. But that's pure speculation.

In Reply To

3) I simplified the example conversion file for the purpose of asking my main question. However, in reality, the values following the 3 colons could be a string which includes spaces, special characters etc. For example, it could look like:

mycomment:::Perl's an awesome language! myemail:::me@me.com mycode::::this string begins with a colon. See the fourth colon over there? Isn't it pretty :)

So, I was wondering if I should modify the regex to:

/^$code:{3}(\w+)$/ # added a $ to the end

It's even simpler. Just use the following regex:

Code

/^$code:{3}(.*)/

In Reply To

Also note that I don't want the trailing carriage return, which I don't get when I use split().

The regex shouldn't capture the carriage return. If it does, your text file is in a different format than the native text files on the machine running the script normally are. If you want to explicitly disallow carriage returns and line feeds, use the following regex: