Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Attempt to parse a line with odd characters is unsuccessful.

by trailhounds (Initiate)
on Jul 21, 2011 at 21:36 UTC ( [id://916004]=perlquestion: print w/replies, xml ) Need Help??

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

I am attempting to read a file in which each string is formatted this way:

DB<27> x @a1

0 "2011-07-06 15:50:28\cI0.050\cM\cJ"


in the debugger. All I want, in reality, is the value that shows as 0.050 in the example. It shows as all white space, aside from the date, time, and value when the file is output via 'cat'. I can slurp the file easily enough, but I can't find a way to get that value.

A bit more information is that the file was created on a Windows 2008 server. I am attempting to process it on a linux machine.
  • Comment on Attempt to parse a line with odd characters is unsuccessful.

Replies are listed 'Best First'.
Re: Attempt to parse a line with odd characters is unsuccessful.
by derby (Abbot) on Jul 21, 2011 at 21:57 UTC
    \cI is the tab character and \cM\cJ is the dos newline. So ... splitting on whitespace and taking the third value should work.
    my $value = (split( /\s+/, $a1[0] ))[2]
    -derby
      splitting on whitespace and taking the third value should work.

        my $value = (split( /\s+/, $a1[0] ))[2]

      Unless there is leading whitespce.    This will work in either case:

      my $value = ( split ' ', $a1[ 0 ] )[ 2 ];
        true ... true .. but there's no leading whitespace in the OP.
        -derby
      Derby,
      Thanks for your answer.
      Will the linux perl interpret the whitespace from Windows correctly?
      My test did not work.
      It keeps coming back when I show the value in the interpreter as "undef".
        Whitespace is whitespace. Windows nor linux should matter (granted the eol delimiter is different but they're both whitespace). I'm guessing there's more to the code and/or data than the snippet you've shown. If you could give more details for 'It keeps coming back when I show the value in the interpreter as "undef"', we could track down the issue.
        -derby
        Check the input file really is what you expect with something like od -xc file.txt

Log In?
Username:
Password:

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

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

    No recent polls found