7stud has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; $/ = undef; my $whole_file = <DATA>; print $whole_file; print "-" x 20, "\n"; my @sections = split /xxx\n/, $whole_file; print $sections[0]; print "-" x 20, "\n"; print $sections[1]; #line 14 __DATA__ aaa bbb ccc xxx yyy zzz --output:-- aaa bbb ccc xxx yyy zzz -------------------- aaa bbb ccc xxx yyy zzz -------------------- Use of uninitialized value in print at t.pl line 14, <DATA> chunk 1.
This works:
use strict; use warnings; my $string = "abc\nxyz"; my @arr = split /\n/, $string; print "$arr[0]\n"; print "$arr[1]\n"; --output:-- abc xyz
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: why isn't split() working here?
by roboticus (Chancellor) on Dec 09, 2010 at 03:39 UTC | |
by JavaFan (Canon) on Dec 09, 2010 at 09:59 UTC | |
by 7stud (Deacon) on Dec 09, 2010 at 03:42 UTC | |
by ikegami (Patriarch) on Dec 09, 2010 at 04:35 UTC | |
by Anonymous Monk on Dec 09, 2010 at 07:11 UTC | |
by ikegami (Patriarch) on Dec 09, 2010 at 16:08 UTC | |
by Anonyrnous Monk (Hermit) on Dec 09, 2010 at 04:18 UTC |
Back to
Seekers of Perl Wisdom