in reply to Splitting in while loop
#!/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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Splitting in while loop
by tel2 (Pilgrim) on Oct 07, 2021 at 05:16 UTC | |
by kcott (Archbishop) on Oct 07, 2021 at 07:43 UTC | |
by tel2 (Pilgrim) on Oct 08, 2021 at 00:54 UTC | |
by kcott (Archbishop) on Oct 08, 2021 at 04:38 UTC | |
by eyepopslikeamosquito (Archbishop) on Oct 08, 2021 at 01:21 UTC | |
by AnomalousMonk (Archbishop) on Oct 07, 2021 at 07:44 UTC | |
by AnomalousMonk (Archbishop) on Oct 07, 2021 at 07:21 UTC | |
by jwkrahn (Abbot) on Oct 07, 2021 at 07:21 UTC | |
by tel2 (Pilgrim) on Oct 08, 2021 at 00:34 UTC | |
by kcott (Archbishop) on Oct 08, 2021 at 03:23 UTC | |
by pryrt (Abbot) on Oct 08, 2021 at 13:48 UTC | |
| |
by tel2 (Pilgrim) on Oct 08, 2021 at 04:02 UTC | |
|