Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Are these warnings indicative of a problem with the structure? (Baby Perl, easy xp... ;-)

by jjap (Monk)
on Oct 27, 2010 at 21:06 UTC ( [id://867842]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks,
I do get the data I need form the following code.
However the warnings probably indicates that there is something wrong with my structure.
use warnings; use strict; my $line; my $msgtype; my $bytes34 ; while (<DATA>) { chomp; next if ($_ =~ /^$/); # fixes the issue... $line = $_; $msgtype = substr $line, 6, 8; # keep only relevant type next if ( $msgtype ne "18FEF200") ; $bytes34 = substr $line, 26, 2; print "Line is: $line\n"; print "qty is: $bytes34\n"; } __END__ 0 18FEF200 X 8 00 00 FF FF 00 00 FF FF 17487.23877 +0 0 18FEF200 X 8 00 00 FF FF 00 00 FF FF 17487.13877 +0 0 18FEF200 X 8 0F 00 00 00 00 00 FF FF 17484.93861 +0 0 18FEF200 X 8 12 00 00 00 00 00 FF FF 17484.83858 +0 0 18FEF200 X 8 00 00 FF FF 00 00 FF FF 17486.83875 +0 0 18FEF600 X 8 FF 31 72 FF FF FF FF FF 17486.75931 +0 0 18FEF200 X 8 1E 01 00 00 00 00 FF FF 17321.32261 +0 0 18FEF200 X 8 2E 01 00 00 00 00 FF FF 17321.22202 +0 0 18FEF200 X 8 45 01 00 00 00 00 FF FF 17321.12260 +0 0 18FEF200 X 8 5A 02 00 00 00 00 FF FF 17016.19730 +0 0 18FEF200 X 8 75 02 00 00 00 00 FF FF 17016.09727 +0
Yields the 10 correct values followed by 5 warnings such as:
substr outside of string at parsefile.pl line 13, <DATA> line 12. Use of uninitialized value $msgtype in string ne at parsefile.pl line +16, <DATA> line 12.
Your indulgence and any hints will be greatly appreciated!
**update**
next if ($_ =~ /^$/); inserted to address possible empty lines, thanks to all
  • Comment on Are these warnings indicative of a problem with the structure? (Baby Perl, easy xp... ;-)
  • Select or Download Code

Replies are listed 'Best First'.
Re: Are these warnings indicative of a problem with the structure? (Baby Perl, easy xp... ;-)
by AR (Friar) on Oct 27, 2010 at 21:14 UTC
    I think you have 5 empty lines at the end of your file. Your code has 11 lines after __END__ but the warning is complaining about line 12.
      Oh-my-God!!
      Number of warnings = 5
      Number of empty lines = 5
      I will add a test for empty lines... Thanks!
Re: Are these warnings indicative of a problem with the structure? (Baby Perl, easy xp... ;-)
by aquarium (Curate) on Oct 27, 2010 at 22:04 UTC
    just a stylistic thing. i think it's clearer if the code is:
    if ( $msgtype eq "18FEF200"){ $bytes34 = substr $line, 26, 2; print "Line is: $line\n"; print "qty is: $bytes34\n"; }
    the hardest line to type correctly is: stty erase ^H

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://867842]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-16 07:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found