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

Re: Re: Re: Need a better way to count input lines

by BrowserUk (Patriarch)
on May 07, 2004 at 20:57 UTC ( #351603=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Need a better way to count input lines
in thread Need a better way to count input lines

Weird! The ^Ms that are getting left behind on the end of the first names suggests that the contents of the data file is weird, though given the source that's no real surprise.

The reason for having the no warnings 'uninitialized' is to avoid the need for a special case to deal with location lines that don't contain the room number. The regex is saying:

m[ ([^/]+) / # capture the phone number before the slash (?: #optionally capture the room number if it is exists (\S+) # capture all the non-spaces between the / \s+ #and one or more spaces )? # but only if there are two sets of non-spaces # separated by a one or more spaces before EOL (\S+) #capture the building code. $ ]x;

If the room number isn't present, the second capture ($2) will be undefined, hence the need to suppress the warning. However, that you are getting three warnings means that all 3 captures are undefined (ie. the regex failed to match), which suggests that the data in the file is formatted somewhat differently to the sample data you posted.

Without being able to see the actual contents of the file it is a little difficult to diagnose the problem.

Perhaps you could run this one liner on the data file to dump the first few lines in hex and post the output here?

perl -nle" exit if $. == 15; print unpack 'H*', $_" testdata.txt

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: Re: Re: Need a better way to count input lines
by Theo (Priest) on May 07, 2004 at 22:19 UTC
    OK, BrowserUk, here are the results.
    %perl -nle" exit if $. == 15; print unpack 'H*', $_" testdata.txt Illegal variable name.
    Hope you can make sense of it ...

    -Theo-
    (so many nodes and so little time ... )

      Are you using linux or cygwin?

      As you were processing Word data, I (stupidly) assumed that you were using Win32 (native). Try

      perl -nle' exit if $. == 15; print unpack "H*", $_' testdata.txt

      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
        In the original post, I included the o/s along with the perl version (sun4-solaris-64int-ld). Sorry you missed it.
        As I'm sure you suspected, each line ends with a CR (0d.) Were you looking for anything else?
        %perl -nle' exit if $. == 15; print unpack "H*", $_' testdata.txt 416c616e6f6e2c20426172740d 353539302f454c0d 2d2d2d2d0d 4f274c657769732c204a6f686e2e0d 2d2d2d2d2f2d2d2d202d2d0d 6a6f686e0d 4c65204d7563682c426f204a6f0d 333430362f313635204e530d 656440612e6e6c0d 4162652d4a656e2c204d61722d4a6f0d 333432312f31363444204e530d 63626573740d
        I was assuming that the "== 15" was a line count, but it only printed 12 - that's all the data that's in the test file. Do you want more data?

        -Theo-
        (so many nodes and so little time ... )

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2023-06-01 19:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?