in reply to how to split a string at [ ?
Hello blaui,
You can just use a regex:
use strict; use warnings; for my $string ("BCInletTemperature = 90[C]", "BCInletTemperature = 33 +.56[C]") { print "$1\n" if $string =~ / = \s* ([0-9.]+) \[ /x; }
Output:
16:59 >perl 1906_SoPW.pl 90 33.56 17:03 >
The regex says: match an equals sign, followed by zero or more whitespace characters, followed by one or more digit-or-decimal-point characters, followed by a left square bracket; and capture the string of digit-or-decimal-point characters in $1. The /x modifier on the regex means to not match whitespace inside the regex: this just makes the regex easier to read.
Update: Note that it is necessary to escape the square bracket to tell the regex engine that this is a character to be matched literally, and not the beginning of a character class.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to split a string at [ ?
by AnomalousMonk (Archbishop) on Jul 05, 2018 at 13:25 UTC |