While going through tutorial, I ran into below where
author is using map command to split up the array using space and
get below results
------------foo.txt---------
hi how are you
I am fine
-----------when I run with map ---
hi how are you I am fine
I also was wondering if I could do the same w/ just array
---------- when I run with array split
@lines1 is 2
Why is this evaluating split of array to scalar?
**update** ; also, when I run below I get
i am fine
open (FH, "foo.txt") ;
while (<FH>) {
chomp;
@lines1 = split / /, $_;
}
close FH;
print "@lines1\n";
###### map code ############
open (FH, "foo.txt");
my @words = map { split } <FH>;
close FH;
print "@words\n";
############### array split##########
open (FH, "foo.txt");
my @lines = <FH>;
close FH;
my @lines1 = split(' ', @lines);
print "\@lines1 is @lines1";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.