in reply to Re: Unscalar'ize a fake array
in thread Unscalar'ize a fake array

Marshall, thanks for responding. I simply printed and eye-balled the array. Looking at it, I expected to be able to split by \t or whitespace, and it didn't split the array the way I hoped to - hence the frustration and reference.

Replies are listed 'Best First'.
Re^3: Unscalar'ize a fake array
by Marshall (Canon) on Sep 25, 2017 at 20:26 UTC
    Well if you just looked at a printout, then this could have been a print out of single scalar text variable containing several lines. To split each line's values into an array, you have to "extract the lines" from the single text variable.

    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