in reply to Re^2: how to find particular string and store in to variable
in thread how to find particular string and store in to variable
But I was matching against (\d*) \z which cannot fail, although it could match an empty string of digits — which can be useful in and of itself!
Update: Interestingly, what is captured | assigned to $var in a statement like
my ($var) = $s =~ m{ (\d+) \z }xms;
is not the same as what is captured to | not necessarily the same as the value of $1:
This warrants a bit more research!c:\@Work\Perl\monks>perl -wMstrict -le "'zot' =~ m{ (zot) }xms; ;; for my $s ( 'http://172.20.37.115:8080/se/1.0/pro/subs/198968/', 'http://172.20.37.115.8080/se/1.0/pro/123456', ) { my ($var) = $s =~ m{ (\d+) \z }xms; print '$var is ', defined($var) ? '' : 'UN', 'defined'; print qq{'$s' -> '$var' (\$1 is '$1')}; } " $var is UNdefined Use of uninitialized value $var in concatenation (.) or string at -e l +ine 1. 'http://172.20.37.115:8080/se/1.0/pro/subs/198968/' -> '' ($1 is 'zot' +) $var is defined 'http://172.20.37.115.8080/se/1.0/pro/123456' -> '123456' ($1 is '1234 +56')
Give a man a fish: <%-(-(-(-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: how to find particular string and store in to variable
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 | |
|
Re^4: how to find particular string and store in to variable
by 1nickt (Canon) on Jun 25, 2015 at 14:13 UTC | |
by AnomalousMonk (Archbishop) on Jun 25, 2015 at 14:23 UTC |