in reply to How to read pcap data from stream not from files.

while ( defined( my $line = <STDIN> ) ) { process($line); }

Also, please wrap your code in <c>...</c> for better legibility.

Replies are listed 'Best First'.
Re^2: How to read pcap data from stream not from files.
by almut (Canon) on May 06, 2010 at 14:45 UTC
    while ( defined( my $line = <STDIN> ) ) {

    Just a quick side note:  you don't need the defined here. Perl has some DWIMmery in place for this case, to always act as if the defined was there, even if you don't write it:

    $ perl -MO=Deparse -e 'while ( my $line = <STDIN> ) { print $line }' while (defined(my $line = <STDIN>)) { do { print $line }; } -e syntax OK

      Cool. I always thought that the DWIM magic was only there for the exact expression while (<FILEHANDLE>), but not for any other construction like the assignment.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^2: How to read pcap data from stream not from files.
by Anonymous Monk on May 06, 2010 at 14:19 UTC

    pcap file is not a text file.

    So, it doesn't save a packet-wise information in $line.

    I hope somebody who has better idea can help me.

    thanks

      You're right, I made a bad assumption. Is there a line delimiter in the pacp format? If so, you can add local $/ = $delimiter;. Note that this also changes the behavior of chomp in a predictable way.

        Unfortunately, pcap is a binary format, so it doesn't include any ascii (text) delimiter. thanks anyway.