Thanks John.That's the right way. Another question,what's the regex of "\s+\z" ?
2007/3/16, John W. Krahn <[EMAIL PROTECTED]>:
Jm lists wrote: > hello lists, Hello, > please see the codes below: > > use strict; > use warnings; > my @arr = (); > open HD,"itemid.txt" or die $!; > while(<HD>){ > chomp; > push @arr,$_; > } > close HD; > > print "@arr"; > > > the itemid.txt has 470 lines data,looks like: > > 1210 > 1211 > 1212 > 1213 > 1214 > 1215 > 1216 > 1217 > 1218 > 1219 > 1220 > 1221 > 1222 > > > But when I run that script I got the output: > > $ perl test.pl > 1693 > > > why? my purpose is to create an arrany which include all the text lines. My guess is that the file 'itemid.txt' was created on DOS/Windows and you are running the program on some form of Unix. man dos2unix Or you could remove all trailing whitespace: while ( <HD> ) { s/\s+\z//; push @arr, $_; } Or you could extract just the numbers: my @arr = do { local $/; <HD> } =~ /\d+/g; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/