我正在阅读Llama(
Learning Perl)的书,并正在进行练习.对于这个练习:
Write a program that reads a list of strings on separate lines until end-of-input and prints out the list in reverse order. [. . .]
好吧,我已经想出了一个更简单的方法(我记得你可以在数组上使用反向… Perl是如此……真棒到目前为止),但我想知道为什么这个不起作用.
#!/usr/bin/perl use 5.010; chomp(@strings = <STDIN>); foreach (@strings){ push @revstrings,$_; } while($i++ <= scalar @revstrings){ say pop @revstrings; }
它是这样的:
$./first@H_403_14@ one@H_403_14@ two@H_403_14@ three@H_403_14@ [^D]@H_403_14@ three@H_403_14@ two@H_403_14@ $
如果我将while循环中的< =更改为<而输出是相同的.