On Wed, 17 Jul 2024 17:41:22 +1000
Peter West via beginners <[email protected]> wrote:
[...]
> $ cat print_file
> #!/usr/bin/perl -n
> while (<>) {
> print "$. $_";
> }
> exit;
[...]
> What happened to line 1?
It's eaten by the `while (<>) { ... }` loop that is wrapped around your
program because you used `-n` in the shebang line - see `perldoc
perlrun` for details on the `-n` arg.
What's essentially happening is:
# this outer loop is the effect of the -n arg to perl
while (<>) {
# and this is your actual program code
while (<>) {
print "$. $_";
}
exit;
}
If you remove the `-n` from the shebang line, it'll work as you'd
expect it to. (For portability you could also consider changing the
shebang line to use /usr/bin/env to use the first Perl found in $PATH,
e.g.:
#!/usr/bin/env perl
... but that's up to you :)
Cheers
Dave P (BIGPRESH)
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/