Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Extracting ranged data

by Anonymous Monk
on Jul 24, 2002 at 20:01 UTC ( [id://185008]=perlquestion: print w/replies, xml ) Need Help??

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

Hello, I am attempting to parse some data that looks like the following:
Users of some feature user1 user2 user3 ... Users of some other feature user1 user2 user3 ... Users of yet another feature ...
What I am trying to figure out is how to count the number of users utilizing each feature. I have been playing around with the .. and ... operators but have not been successful.
Thanks for any help you can give

Replies are listed 'Best First'.
Re: Extracting ranged data
by BigGuy (Friar) on Jul 24, 2002 at 20:21 UTC
    THis is quick and dirty and just assumes that your data is structured the way you did in your post.
    #!/usr/bin/perl open IN, "in.txt" or die "Can't Open input\n"; $count = 0; while (<IN>) { chomp($_); if ($_ =~ /Users/) { print $_,"\t=\t"; } elsif ($_ =~ /\.\.\./) { print $count,"\n"; $count = 0; } else { if ($_) { $count++; } } }
    gives this as a result from your example data
    Users of some feature = 3 Users of some other feature = 3 Users of yet another feature = 0


    BigGuy
    "One World, one Web, one Program" - Microsoft promotional ad
    "Ein Volk, ein Reich, ein Fuhrer" - Adolf Hitler
      Like BigGuy said, his example is assuming that you have one text file set up exactly like what you have posted which looks like:
      Users of some feature
      
         user1
         user2
         user3
         ...
      
      Users of some other feature
      
         user1
         user2
         user3
         ...
      
      Users of yet another feature
      
      ...
      
      Is that the case?
Re: Extracting ranged data
by fuzzyping (Chaplain) on Jul 24, 2002 at 21:20 UTC
    I suggest you take a look at my code from Re: Searching Files. The data structure is very similar, you just might need to increment differently.

    -fp
Re: Extracting ranged data
by neilwatson (Priest) on Jul 24, 2002 at 20:09 UTC
    Showing us a sample of your actual data and the actual code that is giving you problems would help us to better help you.

    Neil Watson
    watson-wilson.ca

Log In?
Username:
Password:

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

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

    No recent polls found