#!/usr/bin/perl use strict; use warnings; while (split(/[, ]+/, <DATA>)) { chomp; print "'$_'\n"; } __DATA__ me@here.com those@there.com others@there.com you@there.com,them@there.com
Outputs:
Use of uninitialized value $_ in scalar chomp at ./pm11137286.pl line +8, <DATA> line 1. Use of uninitialized value $_ in concatenation (.) or string at ./pm11 +137286.pl line 9, <DATA> line 1. '' Use of uninitialized value $_ in scalar chomp at ./pm11137286.pl line +8, <DATA> line 2. Use of uninitialized value $_ in concatenation (.) or string at ./pm11 +137286.pl line 9, <DATA> line 2. '' Use of uninitialized value $_ in scalar chomp at ./pm11137286.pl line +8, <DATA> line 3. Use of uninitialized value $_ in concatenation (.) or string at ./pm11 +137286.pl line 9, <DATA> line 3. '' Use of uninitialized value in split at ./pm11137286.pl line 9, <DATA> +line 3.
You probably want:
#!/usr/bin/perl use strict; use warnings; for (map { split /[, ]+/ } <DATA>) { chomp; print "'$_'\n"; } __DATA__ me@here.com those@there.com others@there.com you@there.com,them@there.com
In reply to Re: Splitting in while loop
by tybalt89
in thread Splitting in while loop
by tel2
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |