socket-> recv () vs. <>?

Я пытаюсь работать над небольшим проектом по изучению Perl, который требует чтения 4 целых чисел без знака из сокета. Я не мог прочитать более одного целого числа, и, покопавшись, я нашел решение. Но мне НЕОБХОДИМО понять, что я сделал неправильно (и безрезультатно просмотрел пару книг по Perl, perldocs и т. Д.)

Пример 1: Here's the successful solution code (original), assume the socket connect is successful for both below:

{
  local $/ = \16; # make <> read in 16 bytes with one swoop.
  my @integers = unpack "IIII", <$sock>;
  print "numbers: @val\n";
}

Example 2: I tried this below. If I print the input prior to unpacking, I only get one Integer:

my $input;
$sock->recv($input,16,0);
my @integers = unpack("IIII", $input);

Specific questions:

  1. In example 1, what the heck is "$/"? And how does it "change" , which I thought read STDIN?
  2. In example 2, is there some reason why my recv() doesn't take more than one integer off the socket? My understanding (per perldoc) is that the "SIZE" parameter defaults to "bytes", and integers are 4 bytes?

Any help, pointers, etc. is appreciated. Btw, the "learning project" is overthewire.org - pretty cool stuff.

6
задан Mat 3 May 2013 в 13:25
поделиться