in reply to how to split a string at [ ?

Maybe a better approach instead of split is to match the things you want?

$temp =~ /BCInletTemperature = ([\d.]+)\[C\]/ or die "Invalid temperature format in '$temp'"; my( $inletTemperature ) = $1;

In general, both, split and the matching deal with regular expressions. See perlre on how to use them and on how to escape meta-characters.

Replies are listed 'Best First'.
Re^2: how to split a string at [ ?
by blaui (Initiate) on Jul 06, 2018 at 12:29 UTC
    Hello!

    The text before the equal sign can differ from BCInletTemperature. It can be another word. But the word will be always low/capital charaters without a blank.


    Can I get this with the above too?

    Regards, blaui

      Yes, see perlre on how "alternations" work:

      $temp =~ /(BCInletTemperature|someOtherTemperature|aThirdTemperatu +reName) = ([\d.]+)\[C\]/ or die "Invalid temperature format in '$temp'"; my( $temperatureType, $temperatureValue ) = ($1,$2);

      But maybe you want a more generic parser that will capture any word on the left hand side of the "=" sign and any number on the right hand side. Then you can use the \w character class or the [A-Za-z] character class (again, see perlre) for matching any word on the left hand side:

      $temp =~ /(\w+) = ([\d.]+)\[C\]/ or die "Invalid temperature format in '$temp'"; my( $temperatureType, $temperatureValue ) = ($1,$2);