count

Hi ! :)
For example I've got something like this:

$users = `users`
;
# command users show actually logged users in system, for example
# now show us this:
# jgr root root jgr greg n0c

@data = split (/ /, $users);

# so in @data i've got: "jgr", "root", "root", "jgr", "greg", "n0c"

eh, end now, how can I count how many each elemenets is in @data, I mean, for example how many "jgr", is in @data ?
But contents of @data is not always the same.
Sorry for my poor english :))
Ok, I think thats all :)

jgr

Comments

  • Hi,

    : For example I've got something like this:
    :
    : $users = `users`
    : ;
    : # command users show actually logged users in system, for example
    : # now show us this:
    : # jgr root root jgr greg n0c
    :
    : @data = split (/ /, $users);
    :
    : # so in @data i've got: "jgr", "root", "root", "jgr", "greg", "n0c"
    :
    : eh, end now, how can I count how many each elemenets is in @data, I
    : mean, for example how many "jgr", is in @data ?
    : But contents of @data is not always the same.
    print scalar(@data); # Will print number of elements
    print $#data; # Will print the highest array index.

    Basically, an array evaluated in scalar context will show the number of elements in the array.

    : Sorry for my poor english :))
    No worries, I understood. :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • : print scalar(@data); # Will print number of elements
    : print $#data; # Will print the highest array index.
    :
    : Basically, an array evaluated in scalar context will show the number of elements in the array.
    :


    :)
    Ok, supose in @data = ("jgr", "root", "jgr"); is 2 "jgr",
    scalar (@data) give number of elements so 3 :)
    so how can count how many elements "jgr" is in @data, no all elements of @data, but only "jgr" :)

    : : Sorry for my poor english :))
    : No worries, I understood. :-)

    ufff.. :)))

    jgr
  • : : print scalar(@data); # Will print number of elements
    : : print $#data; # Will print the highest array index.
    : :
    : : Basically, an array evaluated in scalar context will show the number of elements in the array.
    : :
    :
    :
    : :)
    : Ok, supose in @data = ("jgr", "root", "jgr"); is 2 "jgr",
    : scalar (@data) give number of elements so 3 :)
    : so how can count how many elements "jgr" is in @data, no all
    : elements of @data, but only "jgr" :)
    :
    Use the grep statement.

    @data = grep { $_ eq 'jgr' } @data;

    Then @data only contains the two jgr elements. Of course, you can wrap that up a bit:-

    print scalar grep { $_ eq 'jgr' } @data;

    Will print 2 given the array you gave above as an example.

    : : : Sorry for my poor english :))
    : : No worries, I understood. :-)
    : ufff.. :)))
    :
    Not so sure what ufff means. ;-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • : Not so sure what ufff means.

    Heheh, no bother about this :) & Thanks ;]

    jgr
  • : : Not so sure what ufff means.
    :
    : Heheh, no bother about this :) & Thanks ;]
    :
    Welcome. :)

    Jonathan


    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories