in reply to Re: how to find particular string and store in to variable
in thread how to find particular string and store in to variable
I think you'd want that RE within an if condition, because otherwise the RE could fail to match and you'd load the previous value of $1 into $var
#!/usr/bin/perl use warnings; use strict; my $str = "http://172.20.37.115:8080/se/1.0/provision/subscribers/1989 +68"; $str =~ /.*\/(\d+)$/; my $var = $1 || ''; print "$var\n"; # prints 198968 my $str2 = http://172.20.37.115:8080/se/1.0/provision/subscribers/foo" +; $str2 =~ /.*\/(\d+)$/; my $var2 = $1 || ''; print "$var2\n"; #prints 198968
May be better to do:
use warnings; use strict; my $str = "http://172.20.37.115:8080/se/1.0/provision/subscribers/1989 +68"; if( $str =~ /.*\/(\d+)$/ ) { my $var = $1 || ''; print "$var\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how to find particular string and store in to variable
by AnomalousMonk (Archbishop) on Jun 25, 2015 at 13:58 UTC | |
by 1nickt (Canon) on Jun 25, 2015 at 14:16 UTC | |
by AnomalousMonk (Archbishop) on Jun 25, 2015 at 14:39 UTC | |
by 1nickt (Canon) on Jun 25, 2015 at 16:08 UTC | |
by 1nickt (Canon) on Jun 25, 2015 at 14:13 UTC | |
by AnomalousMonk (Archbishop) on Jun 25, 2015 at 14:23 UTC |