Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: perl and Docker

by 1nickt (Canon)
on Oct 25, 2016 at 11:53 UTC ( [id://1174682]=note: print w/replies, xml ) Need Help??


in reply to perl and Docker

The conf file you are trying to load contains garbage characters.

The relevant code in your external script is:

my(@conf); if(defined($opt{config_file})){ my($buf); $buf = `cat $opt{config_file}`; # slurp if (eval($buf)){ print STDOUT "$me: Read config from $opt{config_file}\n" if $opt +{verbose}; } else{ die "$me: Error reading config from $opt{config_file} (fix it!)\ +n\n"; } } else{ @conf = @default_conf; }
This is a horrible way of loading configuration, but it works:

$ cat 1174639.conf @conf = ( {'step' => 8, 'blur_fwhm' => 4, 'iterations' => 20}, {'step' => 6, 'blur_fwhm' => 3, 'iterations' => 20}, {'step' => 4, 'blur_fwhm' => 2, 'iterations' => 10}, {'step' => 2, 'blur_fwhm' => 1, 'iterations' => 10}, );
$ cat 1174639.pl use strict; use warnings; use feature 'say'; use Data::Dumper; my $file = '1174639.conf'; my $buf = `cat $file`; my @conf; eval( $buf ); say Dumper \@conf;
$ perl 1174639.pl $VAR1 = [ { 'blur_fwhm' => 4, 'step' => 8, 'iterations' => 20 }, { 'step' => 6, 'blur_fwhm' => 3, 'iterations' => 20 }, { 'blur_fwhm' => 2, 'step' => 4, 'iterations' => 10 }, { 'blur_fwhm' => 1, 'step' => 2, 'iterations' => 10 } ];

Do you think this is due to compatibility issue between Perl version 1.2.0 and Perl version 5.0

Definitely not. The 1.2.0 version number you cite is just the version number of the Nlpfit software.

Hope this helps!

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: perl and Docker
by shmem (Chancellor) on Oct 31, 2016 at 16:21 UTC

    Careful. You might get nominated for the useless use of cat award, and actually get it.

    This is a horrible way of loading configuration

    Indeed. Instead of

    my $file = '1174639.conf'; my $buf = `cat $file`; my @conf; eval( $buf );

    I'd rather say

    my @conf = do '1174639.conf';

    since duplicating a static file name into a variable is pointless, as is allocating a buffer to eval a file, and invoking /bin/sh to read it.

    update: The award should go to the author of nlpfit, since lines 227-244 read as follows

    # set up the @conf array my(@conf); if(defined($opt{config_file})){ my($buf); $buf = `cat $opt{config_file}`; # slurp if (eval($buf)){ print STDOUT "$me: Read config from $opt{config_file}\n" if $opt +{verbose}; } else{ die "$me: Error reading config from $opt{config_file} (fix it!)\ +n\n"; } } else{ @conf = @default_conf; }

    and that's where 1nickt got that abomination. It shouldn't have been repeated without correction, though.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1174682]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-23 17:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found