将内置的Perl文档复制到txt文件中

时间:2018-09-30 13:15:45

标签: perl

我想将perl 5.28中内置的perl文档复制到txt文件中。我正在尝试:

try {
    ConnectionHelper conStr = new ConnectionHelper();
    connect = conStr.connectionclass();

    if (connect == null) {
        Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
    } else {
        String query = "select * from cc_fabric";
        stmt = connect.prepareStatement(query);
        rs = stmt.executeQuery();
        ArrayList<String> dataF = new ArrayList<>();
        ArrayList<String> dataFP = new ArrayList<>();
        while (rs.next()) {
            String id = rs.getString("FABRIC_NAME");
            String price = rs.getString("FABRIC_UNIT_PRICE");// value of database
            dataF.add(id);
            dataFP.add(price);
        }
        ArrayAdapter NoCoreAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, dataF);
        Fabric.setAdapter(NoCoreAdapter);
    }
} catch (SQLException e) {
    e.printStackTrace();
}

Fabric.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parent, View view,
                                int position, long id) {
        String name = Fabric.getSelectedItem().toString();
        String price = Fabric.getSelectedItem().toString();
        fabricPrice.setText(price);
        Toast.makeText(Calc_140_plain.this, name, Toast.LENGTH_SHORT)
            .show();
    }
    public void onNothingSelected(AdapterView<?> parent) {
    }
});

我尝试的方法不正确,请纠正我。

1 个答案:

答案 0 :(得分:1)

有关如何在Perl中运行命令并捕获其输出的信息,请参见https://perldoc.pl/perlop#qx/STRING/。但是在这种情况下,另一种选择是直接使用模块。

首先Pod::Simple::Search找到perldoc:

use Pod::Simple::Search;
my $path = Pod::Simple::Search->find('perldoc'); # or the name of the module/documentation you want to read

然后Pod::Simple::Text将其转换为文本:

use Pod::Simple::Text;
my $parser = Pod::Simple::Text->new;
$parser->output_string(\my $text);
$parser->parse_file($path);

最后,File::SlurperPath::Tiny在修改后写出文字。

use File::Slurper 'write_text';
my $outfile = 'perldoc.txt';
write_text($outfile, $text);

-或-

use Path::Tiny;
my $outfile = 'perldoc.txt';
path($outfile)->spew_utf8($text);