Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 02 Aug 2002 20:43:18 +0200
From:      Jens Rehsack <rehsack@liwing.de>
To:        Fernando Costa de Almeida <falmeida@easyit.com.br>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Little Question
Message-ID:  <3D4AD2C6.BDC95345@liwing.de>
References:  <00a901c23a4b$a627a750$1a0e6bc0@Presto>

next in thread | previous in thread | raw e-mail | index | archive | help


Fernando Costa de Almeida wrote:
> 
>     I know that this question is more related to perl than FreeBSD, but....
>     Anyone knowns how can I count the number of bytes in STDIN in perl...
> 
>     Like:
> 
>     cat /kernel | ./checksize.pl
> 
>     and the script says:
> 
>     File has 50000 bytes..
> 
>     Thanks in advance...
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message

Example 1:

#!/usr/bin/perl

@lines = <>;
print "File has 50000 bytes..\n";

Example 2:
#!/usr/bin/perl

$count = 0;
@lines = <>;
foreach(@lines) {
  $count += length( $_ );
}

print "count: $count\n";

bash-2.05a$ ./test1.pl </kernel
count: 1921983
bash-2.05a$ ls -l /kernel
-r-xr-xr-x  1 root  wheel  1921983 May  7 23:50 /kernel

Hope this helps,
Jens
-- 
L     i  W     W     W  i                 Jens Rehsack
L        W     W     W
L     i   W   W W   W   i  nnn    gggg    LiWing IT-Services
L     i    W W   W W    i  n  n  g   g
LLLL  i     W     W     i  n  n  g   g    Friesenstraße 2
                                  gggg    06112 Halle
                                     g
                                 g   g
Tel.:  +49 - 3 45 - 5 17 05 91    ggg     e-Mail: <rehsack@liwing.de>
Fax:   +49 - 3 45 - 5 17 05 92            http://www.liwing.de/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D4AD2C6.BDC95345>