in reply to Parsing problem

use strict; use warnings; print <<BLOCK1; 1 2 - perlmonks1 sdweq23 3 4 - javaforums2 sd341 5 6 - deamtech3 fr4frf34 7 8 + dreamtech3 dcvdf3443 9 10 + sunforum4 sdcds3443 11 12 - sunforum4 ddfvdv333 BLOCK1 print <<BLOCK2; 1 2 - perlmonks1 sdweq23 one 3 4 - javaforums2 sd341 one 5 6 - deamtech3 fr4frf34 start 7 8 + dreamtech3 dcvdf3443 end 9 10 + sunforum4 sdcds3443 start 11 12 - sunforum4 ddfvdv333 end BLOCK2

or was there more you wanted to tell us about your problem?


True laziness is hard work

Replies are listed 'Best First'.
Re^2: Parsing problem
by imrags (Monk) on Jul 29, 2009 at 04:57 UTC
    Lol :)
    Good reply grandfather :)
    However, I think i means he wants to find out some kind of session end/beginning for the users
    Well that's an "assumption" only :)
    TIMTOWTDI
    Put in a hash or AoA, check for duplicity, flag it. Print out the hash/aoa
    Raghu
Re^2: Parsing problem
by bluedevil (Initiate) on Jul 29, 2009 at 06:10 UTC
    I want to find out the smallest and largest value in field 1 and then print it as start / end and if there is only 1 key value pair then print it as one.
      Not sure what you consider to be the key/value pair

      This code should get you started.

      use strict; use warnings; my @list = split /\n/, <<BLOCK1; 1 2 - perlmonks1 sdweq23 3 4 - javaforums2 sd341 5 6 - dreamtech3 fr4frf34 6.5 6.6 - dreamtech3 fr4frf34 7 8 + dreamtech3 dcvdf3443 9 10 + sunforum4 sdcds3443 11 12 - sunforum4 ddfvdv333 BLOCK1 my ($oldname1,$oldname2) =("") x 2; my ($buf, $occurrances)=(0,0); my ($max,$min); for (@list,""){ my ($num1,$num2,$sign,$name1, $name2) = split; if ($name1 && $name1 eq $oldname1){ $occurrances++ ==1 and $buf .= " start"; }else{ if ($occurrances > 1){ $buf .= " end"; }elsif ($occurrances ==1){ $buf .= " one"; } $occurrances = 1; } (! defined $max) || ($num1 && $num1 > $max ) and $max = $num1; (! defined $min) || ($num1 && $num1 < $min) and $min=$num1 ; print "$buf\n" if $buf; $buf = $_; $oldname1=$name1; } print "Min=$min; Max=$max\n";

           Potentia vobiscum ! (Si hoc legere scis nimium eruditionis habes)