Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Splitting in while loop

by haukex (Bishop)
on Oct 12, 2021 at 16:41 UTC ( #11137449=note: print w/replies, xml ) Need Help??


in reply to Re^2: Splitting in while loop
in thread Splitting in while loop

while (my $line = <>) ... Similarly, ... while (my $item = pop @my_array)
use warnings; use strict; while (my $line = <DATA>) { chomp $line; print "<$line>\n"; } my @array = ("Foo","0","Bar"); while (my $item = pop @array) { print "[$item]\n"; } __DATA__ Hello 0 World

Outputs:

<Hello> <0> <> <World> [Bar]

I'd call that a pretty serious caveat. As per I/O Operators, the first is equivalent to while ( defined( my $line = <> ) ), and readline returns undef at EOF, while the second one will stop at any false value, and arrays can contain undefs too.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137449]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2022-01-25 16:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (67 votes). Check out past polls.

    Notices?