Bareword not allowed while “strict subs” in use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Bareword not allowed while “strict subs” in use



I'm a researcher of high-barrier rubber materials. I meet some problems with the Perl by using the Materials Studo software. I can not understand what the Perl errors mean.



Here is the Perl script and its error


#!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 deleten "
);


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;



Gives



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

-e had compilation errors.



I don't how to understand the notice or how to solve the problem.





Welcome to Stack Overflow. Please read the About and How to Ask pages soon, but even more importantly, please read about how to create an MCVE (Minimal, Complete, and Verifiable example). An error on line 56 suggests that you've not done enough to minimize the code. A bare word is an identifier with a sigil such as $ (or @ or % or …) in front of it. You identify the line(s): my $steps = ($analyzeDuration * PICO_TO_FEMTO / $timeStep); ***-----line 56*** (it would be better to make the marker into a Perl comment), and PICO_TO_FEMTO does not have $ before it. Is MaterialsScript a public available module?
– Jonathan Leffler
Aug 10 at 5:19


$


@


%


my $steps = ($analyzeDuration * PICO_TO_FEMTO / $timeStep); ***-----line 56***


PICO_TO_FEMTO


$


MaterialsScript





Occasionally, you can use barewords as constants: use constant PICO_TO_FEMTO => 1.0E6; for example (or is it 1.0E-6? — it's only a factor of a trillion so you should be able to deduce which is correct). And then you might write my $fm = PICO_TO_FEMTO * $pm; to convert the picometres in $pm into the corresponding number of femtometres in $fm.
– Jonathan Leffler
Aug 10 at 5:25


use constant PICO_TO_FEMTO => 1.0E6;


1.0E-6


my $fm = PICO_TO_FEMTO * $pm;


$pm


$fm





So you'd need a use constant PICO_TO_FEMTO => 1E-03;. This can be given in the file you show or, rather, in the custom module that is use-ed, which is in the file MaterialsScript.pm. If it is meant to be in that module, the qw(:all) indicates that it would be exported as needed. So it is not clear from what you show why it's not there. Or perhaps ... the constant is defined in some yet other module, which should be included but isn't?
– zdim
Aug 10 at 5:33



use constant PICO_TO_FEMTO => 1E-03;


use


MaterialsScript.pm


qw(:all)





The constant is a pragma which defines constant subroutines so they may be used as "barewords," that is without a leading sigil ($, @, %) which Perl variables must have. Since in your case that apparently hasn't been done the interpreter complains about a bare-word.
– zdim
Aug 10 at 5:36


$


@


%





I don't often work with units below pico (10⁻¹²) and thought femto was 10⁻¹⁸, but that's 'atto' and femto it is actually 10⁻¹⁵, so I was off by a factor of 1000 in converting between the two. Ah well! (The Perl syntax was valid.)
– Jonathan Leffler
Aug 10 at 6:02





1 Answer
1



Probably some form of PICO_TO_FEMTO is imported from the MaterialsScript library you use at the beginning, as it's not defined in your script.


PICO_TO_FEMTO


MaterialsScript


use



Have a look at the lib. My assumption is, its name is actually $PICO_TO_FEMTO, a simple scalar variable with a $ sigil.


$PICO_TO_FEMTO


$



A bareword in Perl is an identifier without a sigil. If it's a function, it's OK. But this is probably a variable.



If you want to define a bareword variable, you do it like this:


use constant PICO_TO_FEMTO => 1000;



This creates a function called PICO_TO_FEMTO always returning 1000 under the hood.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard