in reply to Re: how to split a string at [ ?
in thread how to split a string at [ ?

Hello!

Thanxs all a lot for the many suggestions. Because it seems the more felxible, I started to try with the above Regexp::Common.


I modified it a littel bit.
$tmp[5] = "BCInletTemperature = 90[C]"; print "$tmp[5] xx\n"; $temp = $tmp[5] =~ m{ = \s+ ($RE{num}{real}) \[ }xms; print "xxx $temp xxx\n";
But running it gives:
Name "charnames::CARP_NOT" used only once: possible typo at /usr/lib/p +erl5/5.18.2/Carp.pm line 437. Name "Regexp::Common::delimited::CARP_NOT" used only once: possible ty +po at /usr/lib/perl5/5.18.2/Carp.pm line 437. BCInletTemperature = 90[C] xx xxx 1 xxx
Perl is
perl --version This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-li +nux-thread-multi
at openSUse Leap 42.3.
Do I need a newer version?

Regards, buchi

Replies are listed 'Best First'.
Re^3: how to split a string at [ ?
by hippo (Archbishop) on Jul 06, 2018 at 12:55 UTC
    Do I need a newer version?

    No, but you do need to remember to put the brackets around $temp when you assign to it in order to ensure list context. You should also provide an SSCCE rather than 4 lines out of context as something could be wrong in the code you aren't showing too.

Re^3: how to split a string at [ ?
by haukex (Archbishop) on Jul 06, 2018 at 12:58 UTC
    Name "charnames::CARP_NOT" used only once: possible typo at /usr/lib/p +erl5/5.18.2/Carp.pm line 437. Name "Regexp::Common::delimited::CARP_NOT" used only once: possible ty +po at /usr/lib/perl5/5.18.2/Carp.pm line 437.

    Those are warnings, not errors, and I can't seem to be able to reproduce them here (don't have 5.18.2 handy though). Are you perhaps using perl -w on the command line or on the shebang line? In that case, see What's wrong with -w and $^W and use warnings; instead.

    The other issue with that code is that $string=~/(regex)/ won't return the match(es) unless you use it in list context, but my $temp = ... puts it in scalar context. To put the right-hand side into list context, use my ($temp) = $string =~ /(regex)/;.