Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Script failed with certain value in the variable

by mamoru0916 (Initiate)
on Mar 18, 2017 at 00:58 UTC ( [id://1185098]=perlquestion: print w/replies, xml ) Need Help??

mamoru0916 has asked for the wisdom of the Perl Monks concerning the following question:

I'm running perl on windows with active perl 5.24 x64. This mystery issue is really bothering me. So, I'm here to seeking for some wisdom.

Lets call my script getopt.pl and it takes the input and doing something. However, whenever the value in the variable is "E48.2", the value is creating issue causing the script to fail miserably.

Input: 1. getopt.pl --platform=1 --version=E48.1 ..... ok 2. getopt.pl --platform=1 --version=E48.2 ..... Failed 3. getopt.pl --platform=1 --version=48.2 ..... ok 4. getopt.pl --platform=1 (script find version value E48.2) ... failed Sample code: use Getopt::Long; my $platform = 0; my $version = undef; my $suffix = undef; my $flag1 = 0; my $flag2 = 0; GetOptions ('platform=i' => \$platform, 'version=s' => \$version, 'suffix=s' => \$suffix, 'flag1' => \$flag1, 'flag2' => \$flag2,); if ($platform == 1) { if (!defined($version)) { Find version number!! $version = E . "$valuefind"; ($version will be E48.2) } print "Find version: " . $version . "!\n"; if (!defined(Suffix) && defined($version)) { Find suffix value, let's say suffix is F!! } print "Find suffix: " . $suffix . "!\n"; } Output for each input is like: 1. Find version: E48.1! Find suffix: F! 2. Find version: E48.2! Use of uninitialized value $suffix in concatenation (.) or string a +t getopt.pl. 3. Find version: 48.2! Find suffix: F! 4. Find version: E48.2! Use of uninitialized value $suffix in concatenation (.) or string a +t getopt.pl.

For some reason, when the value in $version is E48.2, the script can't enter the last if clause to find the $suffix value. Tried a few other number all seems to be okay....E48.3, E48.4 .. 5.. 6.. E74.0 E64.5 ... etc

Chris

Replies are listed 'Best First'.
Re: Script failed with certain value in the variable
by marinersk (Priest) on Mar 18, 2017 at 07:41 UTC

    First troubleshooting step is to add strictand warnings:

    #!/usr/bin/perl use strict; use warnings; use Getopt::Long;

    This identified several problems. The first one is:

    S:\Steve\PerlMonks>perl .\tparse.pl --platform=1 --version=E48.1 Bareword found where operator expected at .\tparse.pl line 25, near "$ +version will" (Missing operator before will?)

    Something's wrong on line 25. After my additions noted above, lines 22-26 are:

    if (!defined($version)) { Find version number!! $version = E . "$valuefind"; ($version will be E48.2) }

    My guesses:

    1. Find version number!! is presumably meant to be a comment. (As posted, it's not one.)
    2.  $version = E . "$valuefined";is probably meant to put a literal 'E' into the result. I'm old-fashioned; I'd put quotes around it.
    3.  $valuefindis not defined anywhere, yet you appear to be trying to reference it.
    4.  ($version will be E48.2)is presumably mean to be a comment. (As posted, it's not one.)

Re: Script failed with certain value in the variable
by shmem (Chancellor) on Mar 18, 2017 at 14:36 UTC

    Adding to what marinersk said above, there's an easy to overlook typo:

    - if (!defined(Suffix) && defined($version)) + if (!defined($suffix) && defined($version))
    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: Script failed with certain value in the variable
by huck (Prior) on Mar 18, 2017 at 03:37 UTC

    For some reason, when the value in $version is E48.2, the script can't enter the last if clause to find the $suffix value.

    Why do you say that?. I would say instead that if $version is E48.2 then the part you call "Find suffix value" does not set $suffix like you claim it should. Since you have not shown us that part of the code how can we tell you why it failed. For us to help you we are going to have to see that part of the code

    another thing that bothers me is that the message "Use of uninitialized value $suffix in concatenation" is the type of message given out when you say "use warnings;" but i dont see that in your code. while "use strict; use warnings;" is a good idea and i suggest it, this leads me to thing there are other parts of code you are not showing us too. For us to help you well will need an example that will compile, and shows us a path that fails like you claim it fails. Like stevieb points out this example does not do that

Re: Script failed with certain value in the variable
by mr_ron (Chaplain) on Mar 18, 2017 at 14:59 UTC

    The line that reads:

    if (!defined(Suffix) && defined($version))

    was almost certainly intended to be

    if (!defined($suffix) && defined($version))

    strict would have caught the mistake. !defined(Suffix) should always return false if the code runs. strict and warnings were also recommended by other replies.

    Ron
Re: Script failed with certain value in the variable
by stevieb (Canon) on Mar 18, 2017 at 01:08 UTC

    Your code doesn't compile. Please edit your question with your real code that we can test with :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1185098]
Approved by beech
Front-paged by beech
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: (4)
As of 2024-03-29 11:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found