Как я пропускаю к определенной входной строке в Perl?

попробуйте этот код

 this.newsList = JSON.stringify(this.database.list('news'));

html

 <ion-list>
    <ion-item *ngFor="let item of newList">
      <h2>{{item}}</h2> //or item.subitem, depends of your object or what you want to show.
    </ion-item>
  </ion-list>
5
задан Brad Gilbert 24 July 2009 в 15:46
поделиться

2 ответа

Значения по умолчанию оператора соответствия к использованию $_ но <> оператор не хранит в $_ по умолчанию, если это не используется в некоторое время цикле, таким образом, ничто не хранится в $_.

От perldoc perlop:

   I/O Operators
   ...

   Ordinarily you must assign the returned value to a variable, but there
   is one situation where an automatic assignment happens.  If and only if
   the input symbol is the only thing inside the conditional of a "while"
   statement (even if disguised as a "for(;;)" loop), the value is auto‐
   matically assigned to the global variable $_, destroying whatever was
   there previously.  (This may seem like an odd thing to you, but you’ll
   use the construct in almost every Perl script you write.)  The $_ vari‐
   able is not implicitly localized.  You’ll have to put a "local $_;"
   before the loop if you want that to happen.

   The following lines are equivalent:

       while (defined($_ = )) { print; }
       while ($_ = ) { print; }
       while () { print; }
       for (;;) { print; }
       print while defined($_ = );
       print while ($_ = );
       print while ;

   This also behaves similarly, but avoids $_ :

       while (my $line = ) { print $line }
10
ответ дан 18 December 2019 в 13:20
поделиться

<> является только волшебным в a while(<>) создать. Иначе это не присваивается к $_, так /include/ регулярное выражение не имеет ничего для соответствия против. Если Вы выполнили это с -w Perl сказал бы Вам:

Use of uninitialized value in pattern match (m//) at ....

Можно зафиксировать это с:

$_ = <> until /include/;

Избегать предупреждения:

while(<>)
{
    last if /include/;
}
4
ответ дан 18 December 2019 в 13:20
поделиться
Другие вопросы по тегам:

Похожие вопросы: