CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
What is correct regular expression for the below:

 



digioleg54
User

Sep 17, 2016, 9:40 AM

Post #1 of 5 (3140 views)
What is correct regular expression for the below: Can't Post

#!/usr/bin/perl
use warnings;
use strict;

my $string = 123456.999;
if ($string = ~m{(\d+)(\.)(\d+)}) {
print "string is $string\n";
}


It show the error.

Use of uninitialized value $_ in pattern match (m//) at ./regexpr.pl line 6.
string is 18446744073709551615


BillKSmith
Veteran

Sep 17, 2016, 10:35 AM

Post #2 of 5 (3138 views)
Re: [digioleg54] What is correct regular expression for the below: [In reply to] Can't Post

There is nothing wrong with your regular expression. Your problem is that you intend to use the binding operator (=~), but put a space it (= ~), changing it to an assignment operator and a smart match operator which does not make sense in that context.
Good Luck,
Bill


Laurent_R
Veteran / Moderator

Sep 18, 2016, 1:11 AM

Post #3 of 5 (3129 views)
Re: [digioleg54] What is correct regular expression for the below: [In reply to] Can't Post

Bill has given you the answer to your problem, but please also note that you don't need all these parentheses in your regex:

Code
$ perl -e '#!/usr/bin/perl 
> use warnings;
> use strict;
>
> my $string = 123456.999;
> if ($string =~ m{\d+\.\d+}) {
> print "string is $string\n";
> }'
string is 123456.999



digioleg54
User

Sep 18, 2016, 3:35 AM

Post #4 of 5 (3128 views)
Re: [Laurent_R] What is correct regular expression for the below: [In reply to] Can't Post

I want to devide using dot


Laurent_R
Veteran / Moderator

Sep 18, 2016, 11:09 PM

Post #5 of 5 (3117 views)
Re: [digioleg54] What is correct regular expression for the below: [In reply to] Can't Post


In Reply To
I want to devide using dot


Can you please explain what you mean?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives