in reply to Re^2: Unscalar'ize a fake array
in thread Unscalar'ize a fake array
Another fine point once you have extracted the lines...
There are five white space characters, space,\t,\f,\n,\r.
There are 2 ways to split on any of these white space characters.
Perl has a special case, ' 'for the split.
This is the same as the
regex /\s+/ which splits on any of the five characters
except in how it handles the first potentially "blank" field.
Demo Code:
#!/usr/bin/perl use strict; use warnings; my @lines = ("a b c\n", " a b c\n"); foreach my $line (@lines) { my @array = split ' ',$line; print join ("|",@array), "\n"; } foreach my $line (@lines) { my @array = split /\s+/,$line; print join ("|",@array), "\n"; } __END__ #using split on ' ' a|b|c a|b|c # using split on /\s+/ (the default) a|b|c |a|b|c
|
|---|