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";
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.