小编Jim*_*vis的帖子

如何在perl中写出科学记数法?

我一直在研究一个项目,我基本上要说下一个目标

"在第[27]栏中,如果值大于10^-8删除文件"

如何写10^-8一个程序?

#!/usr/local/bin/perl

use strict;
use warnings;

my @traitarray;
my $traitarray;
my $input ;
my %traithash ;
my $t_out ;
my $TRAIT;
my $SNPS;

open ($input, "gwas_catalog_v1.0-downloaded_2015-07-31.tsv") || die () ;

while(<$input>) {
    @traitarray = split (/\t/);
    $TRAIT = $traitarray[7];
    $SNPS = $traitarray[21];

    if (!exists $traithash {$TRAIT}) {
            $TRAIT =~ tr/ /_/ ;
            $TRAIT =~ tr/:/-/ ;
            $TRAIT =~ tr/\//-/ ;
            $TRAIT =~ tr/*/-/ ;
            open ($t_out, ">outputFiles/".$TRAIT.".txt");
            print $t_out "$SNPS\n";
            $traithash {$TRAIT} = 1 …
Run Code Online (Sandbox Code Playgroud)

perl scientific-notation

1
推荐指数
1
解决办法
522
查看次数

当无法连接时,我的Perl DBI->连接重新调整错误的值

我有以下perl代码:

my $dbo_prd = DBI->connect(
    "dbi:Oracle:host=$db_srv_prd;port=1521;sid=$db_sid_prd",
    $db_user_prd,
    $db_pass_prd
) ||  warn &senderror("TREE_STRUCTURE.Could not connect to $db_srv_prd: $DBI::errstr\n");

print "\n\nconnection:" . $dbo_prd . "\n";
if ($dbo_prd != 1){
    print "in prod prepare\n\n";
    my $query1_prd = $dbo_prd->prepare(
        "INSERT INTO CMSV2.CMS_INBOX VALUES (
            'vmsdk', (SELECT SYSDATE from DUAL), 'NODE_TREE_UPDATE',?,?,?,?,NULL,NULL
        )"
    ) || warn &senderror("TREE_STRUCTURE.Could not prepare to $db_srv_prd: $DBI::errstr\n");
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,我认为如果连接不起作用,它会将连接$ dbo_prd设置为undef,但它将其设置为1?这不是文档在任何地方陈述的内容.

当连接失败时,连接将被打印为"1",如果成功则连接将被打印出来.

oracle perl dbi

0
推荐指数
1
解决办法
50
查看次数

在perl中的子例程之后,哈希键值更改为数组引用

我在同一个哈希上创建子程序外部和内部的键.但是,在子例程之后,调用子例程之前创建的键中的值现在被解释为数组引用.

#!/usr/bin/perl
use module;
use strict;
use warnings;
my %hash;
my $count = 0;

my @array = ("a", "b", "c", "d");

for my $letter (@array) {
    $hash{$letter} = $count;
    $count++;
}

# need "\" to pass in hash otherwise changes
# will get lost outside of subroutine
foreach my $x (sort keys %hash) {
    print "first $hash{$x}\n";
}

module::add_ten(\%hash);

foreach my $p (sort keys %hash) {
    # $hash{$p} is printing array references, but before it was
    # printing the value …
Run Code Online (Sandbox Code Playgroud)

perl hash reference subroutine

0
推荐指数
1
解决办法
135
查看次数

Perl:在运行时修改.pm文件中的数据结构

我有一个.pm文件,我有一个这样的数据结构:

my $var = {  
    "xyz" => {
        "pqr" => {
            "all" => "123",
        },
    },
    "abc" => {
        "zzz" => {
            "f"  => "foo1",
            "n"  => "foo2",
            "g"  => "foo3", 
        },
    },
};

sub getDataStructure() {
    return $var;
}
Run Code Online (Sandbox Code Playgroud)

这种getDataStructure方法被我系统上的各种程序广泛使用.

我想要的是有一个可以写入更多条目的脚本$var.我们假设这些值是用户输入.

我逐行读取文件中的行,一直持续到我};$var,现在我想回去一行,并使用print FH $newContent其中FH是我的文件句柄.

我怎么做?我尝试使用该seek功能,但无法找到正确的方法

请注意:这个问题不是关于如何将Perl哈希写入文件.这是一些技巧,它可以修改现有的.pm文件,并将一些新值写入我提到的数据结构中.

perl

0
推荐指数
1
解决办法
216
查看次数

Perl:for(min .. max)使用随机顺序,但我希望它按顺序0,1,2,

因为我是perl的初学者,oracle sql和其他一切.我必须编写一个脚本来解析excel文件并将值写入oracle sql数据库.

到目前为止一切都很好.但它以随机顺序将行写入数据库.

for ($row_min .. $row_max) {...insert into db code $sheetValues[$_][col0] etc...}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么以随机顺序插入行?显然我怎样才能让它们按顺序排列?excel_row 0 => db_row 0等等...

数组中的值是有序的!行数是动态的.

感谢您的帮助,我希望您能获得所需的所有信息.

编辑:

&parseWrite;

sub parseWrite {
    my @sheetValues;
    my $worksheet = $workbook->worksheet(0);
    my ($row_min, $row_max) = $worksheet->row_range();
    print "| Zeile $row_min bis $row_max |";
    my ($col_min, $col_max) = $worksheet->col_range();
    print " Spalte $col_min bis $col_max |<br>";

    for my $row ($row_min .. $row_max) {
        for my $col ($col_min .. $col_max) {
            my $cell = $worksheet->get_cell ($row,$col);
            next unless $cell; …
Run Code Online (Sandbox Code Playgroud)

sql oracle excel perl for-loop

-4
推荐指数
1
解决办法
110
查看次数

标签 统计

perl ×5

oracle ×2

dbi ×1

excel ×1

for-loop ×1

hash ×1

reference ×1

scientific-notation ×1

sql ×1

subroutine ×1