perl - 使用 "strict subs"时不允许使用裸字

标签 perl material-design

我是高阻隔橡胶 Material 的研究员。我在使用 Materials Studo 软件时遇到了一些 Perl 问题。我无法理解 Perl 错误的含义。

这是 Perl 脚本及其错误

#!perl

use strict;

use Getopt::Long;
use MaterialsScript qw(:all);

for ( my $RxnRadius = my $MinRxnRadius; $RxnRadius <= my $MaxRxnRadius; $RxnRadius += 0.5 ) {

    my $xsdNameDist = sprintf( "%s_R%.2f", my $rootName, $RxnRadius );    #rename the new structure;

    if ( $RxnRadius > $MinRxnRadius ) {

        my $doc->Name = $xsdNameDist . "_init";
        ForciteGeomOpt( $doc, 20000 );                                    # run 20000 steps of Geometry Optimization

        my $results = ForciteDynamics( $doc, my $steps, "NPT" );
        $results->Trajectory->Delete;
    }

    for ( my $iteration = 1; $iteration <= my $IterationsPerRadius; $iteration++ ) {

        my $doc->Name = $xsdNameDist . "_" . $iteration;
        my $numBonds = createNewXlinks( $doc, $RxnRadius );
        my $reactedOligomerAtoms = 0;

        foreach my $atom ( @{ $doc->UnitCell->Atoms } ) {
            my $oligomerReactiveAtom;
            $reactedOligomerAtoms++ if ( $atom->Name =~ /^$oligomerReactiveAtom-\d/ );
        }

        my $conversion = 100 * my $totalOligomerAtoms;

        ( $reactedOligomerAtoms / $totalOligomerAtoms );

        if ( $numBonds == 0 ) {
            last;
        }

        optimizeAndPerturb( $doc );

        my $rowCounter;
        xlinkStatistics( $doc, $RxnRadius, $rowCounter );
        maxBondEnergy( $doc, $RxnRadius, $rowCounter ) if ( my $UseMaxBondEnergy );

        my $analysis_doc = Documents->New( "analyze.xsd" );
        $analysis_doc->CopyFrom( $doc );

        my $analyzeDuration;
        my $timeStep;

        my $steps   = ( $analyzeDuration * PICO_TO_FEMTO / $timeStep );
        my $freq    = int( $steps / 20 ); ### line 56
        my $results = Forcite Dynamics(
            $analysis_doc, $steps,
            "NPT",
            ( TrajectoryFrequency => $freq )
        );

        getTrajTempAndPressure( $results, $rowCounter, $RxnRadius );
        getEnergies( $results, $rowCounter );
        $analysis_doc->Delete;
        $results->Trajectory->Delete;

        if ( $conversion >= my $conversionTarget ) {

            my $numbondsDelete = my $xlinkCounter - $reactedOligomerAtoms - my $targetOligomerAtoms;

            if ( my $deleteExcessXlinks and $numbondsDelete > 0 ) {
                deleteExcessBonds( $doc, $numbondsDelete );
                xlink Statistics( $doc, "Final", $rowCounter );
            }
            else {
                my $textDoc->Append(
                    sprintf "There  are no excess bonds to delete\n "
                );
            }

            my $textDoc->Save;

            last;
        }

        Documents->SaveAll;
    }

    last if ( my $conversion >= my $conversionTarget );
}

my $doc->Name = my $rootName . "_final";
analyzeBonds( $doc );
XlinkSet( $doc );
Glasstransitiontemperature( $doc );
Documents->SaveAll;

给予

Bareword "PICO_TO_FEMTO" not allowed while "strict subs" in use at -e line 56.
-e had compilation errors.

我不知道如何理解该通知或如何解决问题。

最佳答案

可能某种形式的 PICO_TO_FEMTO 是从您开始时使用MaterialsScript库导入的,因为它没有在您的脚本中定义。

看看库。我的假设是,它的名称实际上是 $PICO_TO_FEMTO,一个带有 $ 标志的简单标量变量。

Perl 中的裸字是没有印记的标识符。如果是函数的话就OK了。但这可能是一个变量。

如果你想定义一个裸字变量,你可以这样做:

use constant PICO_TO_FEMTO => 1000;

这将创建一个名为 PICO_TO_FEMTO 的函数,其底层始终返回 1000。

关于perl - 使用 "strict subs"时不允许使用裸字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51778850/

相关文章:

javascript - 精简版 Material 设计 : how to update checkbox value

reactjs - 什么时候应该在 Material-UI 中使用 Typography?

javascript - jQuery 热图?

Android 使用 MaterialDatePicker 和 TextInputLayout

linux - Perl:检查特定文本的标准输出并执行操作

multithreading - Perl 线程之间共享套接字对象

Flutter 应用栏布局 : action buttons in the same row with tab bar?

javascript - 在 Angular Js 导航栏中将元素右对齐

perl - 如何在 Perl 中执行自省(introspection)?

perl - 如何在 Perl 调试器中移动指令点?