눈바래다

1 #!/usr/bin/perl

      2

      3 use warnings;

      4 use strict;

      5 use encoding "euc-kr";

      6

      7 sub split_words {

      8  my ($word, $pre);

      9  my (@words, @bigram);

     10

     11  $pre="";

     12  while (<>) {

     13   chomp;

     14   @words=split(/\s+/,$_);

     15   foreach $word (@words) {

     16     if ($pre eq "USB"){

     17      push(@bigram, $word);

     18     }

     19     $pre=$word;

     20   }

     21  }

     22  return @bigram;

     23 }

     24

     25 MAIN: {

     26  my $word;

     27  my @bigram;

     28

     29  @bigram=split_words();

     30

     31  foreach $word (@bigram) {

     32   print $word . "\n";

     33  }

     34 }

 

eq : 문자열이 같은지 비교

== : 숫자가 같은지 비교

push : 지정한배열에 지정한요소 추가