Alternatively, you can use the r modifier (s/_PATTERN_/_REPLACEMENT_/msixpodualngcer in perlop)to shift the behavior to return a value without editing the original string:#!/usr/bin/perl use strict; use warnings; my $adate = "2017-01-29 11:30:07.370"; # more direct way, but returning a "1". my $a_new_datetime = $adate; $a_new_datetime =~ s/(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2})(.*)/$2-$ +3-$1 $4:$5/; print "\n 1 - $a_new_datetime\n\n"; my $new_datetime = $adate; $new_datetime =~ s/(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2})(.*)/$2-$3- +$1 $4:$5/; print " 2 - $new_datetime\n\n";
#!/usr/bin/perl use strict; use warnings; my $adate = "2017-01-29 11:30:07.370"; # more direct way, but returning a "1". ; printf "\n 1 - %s\n\n", $adate =~ s/(\d{4})-(\d{2})-(\d{2})\s(\d{2}):( +\d{2})(.*)/$2-$3-$1 $4:$5/r; printf " 2 - %s\n\n", $adate =~ s/(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d +{2})(.*)/$2-$3-$1 $4:$5/r;
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
In reply to Re: Assigning a parsed date to a variable
by kennethk
in thread Assigning a parsed date to a variable
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |