perl - 如何从 .txt 文件运行?
问题描述
我正在尝试通过附加到字符串的末尾来从 base58 组合中获取数据。
#!c:\perl64\bin\perl.exe
{$db = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
$pw="Rw5cfDTA8zGsdjEhKnhXJTH7LrciGrDi9qZ1";
@delen = split('',$pw);
@letters = split('',$db);
$length = length($pw);
for ($position = 36; $position < $length+1; $position++)
{foreach(@letters)
{
@new = @delen;
splice(@new, $position, 0, $_);
print join('',@new)."\n";
}}}
我必须在 $ pw 定义中一一输入所有组合。我希望它处理 TXT 文件中列表的所有行,而不是手动输入。我对如何做到这一点进行了一些研究,但失败了。
编辑:
我找到了我上面提到的方法,它会是这样的。但是,我有一个不同的问题。当我运行 Perl 文件时,输出的顺序很糟糕。我认为从输入文件中获取问题
#!c:\perl64\bin\perl.exe
open( my $data, "<", "test.txt" ) or die "There was a problem opening: $!";
while ($data) {
{
my $db = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
my $pw = <$data>;
my @delen = split( '', $pw );
my @letters = split( '', $db );
my $length = length($pw);
for ( my $position = 35 ; $position < $length + 1 ; $position++ ) {
foreach (@letters) {
my @new = @delen;
splice( @new, $position, 45, $_ );
print join( '', @new ) . "\n";
}
}
}
}
解决方案
# 最终的
经过长期的努力,我得到了我想要的结果。这对我来说完美无缺。
#!c:\perl64\bin\perl.exe
open( my $data, "<", "4.txt" ) or die "There was a problem opening: $!";
while ($data) {
{
my $db = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
my $pw = <$data>;
my @delen = split( ' ', $pw );
my @letters = split( '', $db );
my $length = length($pw);
for ( my $position = 39 ; $position < $length + 1 ; $position++ ) {
foreach (@letters) {
my @new = @delen;
splice( @new, $position, 0, $_ );
print join('', @new ) . "\n";
}
}
}
}
#决赛 2
它现在已经脱离了循环。
唯一的错误是:splice() offset past end of array at
#!c:\perl64\bin\perl.exe
use strict;
use warnings;
open( my $data, "<", "file_in.txt" ) or die "There was a problem opening: $!";
while (my $pw = <$data>) {
my $db = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
my @delen = split( ' ', $pw );
my @letters = split( '', $db );
my $length = length($pw);
for ( my $position = 38 ; #line break
$position < $length + 1 ; $position++ ) {
foreach (@letters) {
my @new = @delen;
splice( @new, $position, 0, $_ );
print join('', @new ) . "\n";
}
}
}
close $data;
推荐阅读
- ios - UIScrollView 不与 UITableView 一起滚动
- javascript - 函数在所有异步工作完成之前结束
- python - Listdir 没有找到循环内的所有文件
- mongodb - 从MongoDB中的未知键合并数组
- r - ggplot在R中使用多个data.frame的facet_wrap?
- python - 如何使用 argparse 创建条件参数?
- pact - 如何处理提供商对消费者服务进行重大更改的工作流程?
- php - RedirectIfAuthenticated 用于 Laravel 中的自定义守卫
- vim - 没有移动光标的 VIM 拉外/内标签
- r - R count() 使用动态生成的变量/列列表