I'm trying to find a way to place a colon ( : ) into a string, two characters from the end of the string.
Examples of $meetdays:
1200 => 12:00
900 => 9:00
1340 =>13:40
Not sure if this should be a regular expression or just another function that I'm not aware of.
If you need to split a string into characters, you can do this: @array = split(//); After this statement executes, @array will be an array of characters. split recognizes the empty pattern as a request to make every character into a separate array element.
Below is the syntax of split function in perl are as follows. Split; (Split function is used to split a string.) Split (Split function is used to split a string into substring) /pattern/ (Pattern is used to split string into substring.)
A string is splitted based on delimiter specified by pattern. By default, it whitespace is assumed as delimiter. split syntax is: Split /pattern/, variableName.
The operator =~ associates the string with the regex match and produces a true value if the regex matched, or false if the regex did not match. In our case, World matches the second word in "Hello World" , so the expression is true.
Can also use substr() as well.....
my $string = "1200";
substr $string, -2, 0, ':';
# $string => '12:00';
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