Results 1 to 4 of 4

Thread: help with perl

  1. #1
    99shassan's Avatar Poster BT Rep: +1
    Join Date
    Jul 2003
    Posts
    787
    Hi guys, I've loaded a file, and have removed the \n using chomp. however, when I try using length($file), it counts the whitespaces along with the characters. How do I just count the characters, anything but the whitespaces?

    thanks
    Changed SPAN settings in sig a YEAR after it was removed

  2. Internet, Programming and Graphics   -   #2
    4play's Avatar knob jockey
    Join Date
    Jan 2003
    Location
    London
    Age
    41
    Posts
    3,824
    $str = "place the string you want to count in here";
    $count = $str =~ s/([a-z])/$1/gi;
    print $count;

  3. Internet, Programming and Graphics   -   #3
    99shassan's Avatar Poster BT Rep: +1
    Join Date
    Jul 2003
    Posts
    787
    Quote Originally Posted by 4play View Post
    $str = "place the string you want to count in here";
    $count = $str =~ s/([a-z])/$1/gi;
    print $count;
    Hi, that will just count the lowercase characters right? what about capital letters? would it be something along the lines as [a-z]||[A-Z]? also, what is the $1 for?

    done it thanks for your help
    Last edited by 99shassan; 04-24-2008 at 06:32 PM. Reason: Automerged Doublepost
    Changed SPAN settings in sig a YEAR after it was removed

  4. Internet, Programming and Graphics   -   #4
    $count = tr/a-zA-Z//;
    perl -e "$_= 'blah blDh'; $count = tr/a-zA-Z//; print $count;"

    perldoc perlop

    or perl -e "$_= 'blah blDh'; print $count = tr/a-zA-Z//;"
    Last edited by paleywiener; 04-25-2008 at 02:57 PM. Reason: Automerged Doublepost

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •