0
我有代碼獲得的匯率:Perl的解析第二實例與正則表達式
#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;
use POSIX qw(strftime);
use Math::Round;
use CGI qw(header start_html end_html);
use DBI;
sub isfloat {
my $val = shift;
return $val =~ m/^\d+.\d+$/;
}
.....
my $content = get('URL PAGE');
$content =~ /\s+(\d,\d{4})/gi;
my $dolar = $1;
$dolar =~ s/\,/./g;
if (!isfloat($dolar)) {
error("Error USD!");
}
我怎樣才能抓住第二實例/ \ S +(\ d,\ d {4})/ GI ??
我試圖從Perl的食譜這樣的解決方案:
$content =~ /(?:\s+(\d,\d{4})) {2} \s+(\d,\d{4})/i;
但是我有錯誤:
Use of uninitialized value $val in pattern match (m//)
Use of uninitialized value $dolar in substitution (s///)
它的工作。謝謝 – Hesperson