首页 > 解决方案 > 如何从 .t​​xt 文件运行?

问题描述

我正在尝试通过附加到字符串的末尾来从 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";

            }
        }
    }
}

标签: perl

解决方案


# 最终的

经过长期的努力,我得到了我想要的结果。这对我来说完美无缺。

#!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;

推荐阅读