Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
while(<FILE>) { @Array1 = <FILE>; }

That is not going to do quite what you'd hoped. The first time into the loop it will read the first line of the file into the $_ variable, which you never use so that line will be lost. Then, inside the loop you read the file handle in list context as you have an array on the LHS. That will have the effect of reading the remaining lines of the file, one line per element, into the array; the the loop will exit on the next iteration as EOF has been reached. Your array will contain all lines but the first. As you've discovered in your subsequent post you will have to chomp to get rid of line terminators. The correct way to populate your array in a loop would be to use push.

my @arr; while ( <$fh> ) { chomp; push @arr, $_; }

However, there is an easier way as chomp will also operate on arrays

my @arr = <$fh>; chomp @arr;

or even

chomp( my @arr = <$fh> );

I hope this is helpful.

Cheers,

JohnGG


In reply to Re^3: Substring comparison by johngg
in thread Substring comparison by schtinkfist893

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-29 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found