How can I get a value from a specific number?
Assume a number 20040819. I want to get the last two digits of ie 19using Perl.
20040819
19
my $x = 20040819; print $x % 100, "\n"; print substr($x, -2);
Benoit's answer is at the mark and one that I would use, but for this, using a template search, as you suggested in your title, you should:
my $x = 20040819; if ($x =~ /\d*(\d{2})/) { $lastTwo = $1; }
substr("20040819", -2);
Regexp:: Common:: time - ,
use strict; use Regexp::Common qw(time); my $str = '20040819' ; if ($str =~ $RE{time}{YMD}{-keep}) { my $day = $4; # output 19 #$1 the entire match #$2 the year #$3 the month #$4 the day }
, YYYYMMDD , :
my $str = '20040819'; my ($year, $month, $date) = $str =~ /^(\d{4})(\d{2})(\d{2})$/;
defined $year .., , .
defined $year
my $num = 20040819; my $i = 0; if ($num =~ m/([0-9]{2})$/) { $i = $1; } print $i;
Another option:
my $x = 20040819; $x =~ /(\d{2})\b/; my $last_two_digits = $1;
\b matches the word boundary.
\b
Another solution:
my $number = '20040819'; my @digits = split //, $number; print join('', splice @digits, -2, 2);
The solution for you:
my $number = 20040819; my ($pick) = $number =~ m/(\d{2})$/; print "$pick\n";
$x=20040819-int(20040819/100)*100;
Source: https://habr.com/ru/post/1767517/More articles:Good 2D primitive rendering library for C # /. NET? - c #Django must be an instance of "User" - djangoHow to save folder tree and publish websites in TFS 2010? - tfsHigh Performance Registration Library for Embedded Applications - c ++How to print the .rtf file? - c #TextMate - find and replace selected text - keyboard-shortcutsselect a DIV but not a link inside it, jQuery question - jqueryProblem of using JPA with Oracle and clock grouping - javaThe best free cross-platform library for a higher level Matrix, Vector and especially. SparseMatrix Operations? - c ++Sharing a dataset among streams-C ++ - c ++All Articles