我有一个显示货币汇率列表的文本文件。
我已经阅读了文本文件内容的第一行,我需要将此行插入到输入表单中。
var var1 = true
var var2 = 1
@IBAction func button1(_ sender: UIBarButtonItem?) {
if var2 == 1 {
sender?.image = UIImage(named: "1")
} else {
sender?.image = UIImage(named: "2")
}
}
func calc() {
if var1 {
button1(nil)
}
}
文本文件具有类似的值
#!/usr/local/bin/perl
use strict;
use warnings;
use CGI qw(:standard);
#use Data::Dumper;
#use CGI;
my $q = CGI->new;
my %data;
$data{name} = $q->param('name');
print header;
my $file = '/admin/currencyX.txt';
open my $info, $file or die "Could not open $file: $!";
while ( my $line = <$info> ) {
print $line, "<br>";
last if $. == 1;
}
print
start_html('A Simple Example'),
h1('A Simple Example'),
start_form,
"What's your value? <br>",
textfield(-name => 'name', -class => 'nm', -value => '$line'),
p,
submit(-value => 'Add', -name => 'ed'),
end_form,
hr;
if ( $ENV{'REQUEST_METHOD'} eq "POST" ) {
if ( $data{name} eq '' ) {
print "Please provide the input";
exit;
}
#print "response " . Dumper \%data;
}
if ( param() ) {
print
"Your name is",em(param('name')),
hr;
}
print end_html;
我需要更正以使其正常工作。
答案 0 :(得分:3)
textfield(-name => 'name', -class => 'nm', -value => '$line'),
您的问题似乎是您将$line
放在了单引号中-这阻止了它的内插。尝试只删除它们。
textfield(-name => 'name', -class => 'nm', -value => $line),
答案 1 :(得分:-3)
做到这一点的最佳方法是找到一种替代方法,将文本值放出来
open my $getV, '<', "/admin/currencyX.txt";
my $realV = <$getV>;
close $getV;
print $realV; # will out put AFN Afghan Afghani 73.0556951371 0.0136881868
然后将字符串附加到html输入值
"What's your value? <br>",textfield(-name =>'name', -class =>'nm', -value =>$realV),