Re: about creating an array

2007-03-15 Thread Rob Dixon
Jm lists wrote: 2007/3/16, John W. Krahn <[EMAIL PROTECTED]>: 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 ( ) { s/\s+\z//; push @arr, $_; }

Re: about creating an array

2007-03-15 Thread Chas Owens
On 3/15/07, yitzle <[EMAIL PROTECTED]> wrote: What do you mean? \s+\z will match 0 to all whitespace at end of the buffer. snip Just a quick correction: \s+ matches one or more whitespace characters \s* matches zero or more whitespace characters -- To unsubscribe, e-mail: [EMAIL PROTECTED] Fo

Re: about creating an array

2007-03-15 Thread John W. Krahn
Jm lists wrote: > > 2007/3/16, John W. Krahn <[EMAIL PROTECTED]>: >> >> Or you could remove all trailing whitespace: >> >> while ( ) { >>s/\s+\z//; >>push @arr, $_; >> } > > Thanks John.That's the right way. > Another question,what's the regex of "\s+\z" ? \s+ matches one or more whites

Re: about creating an array

2007-03-15 Thread yitzle
What do you mean? \s+\z will match 0 to all whitespace at end of the buffer. You can see if your variable has this with m/\s+\z/ or you can replace it with FOO: s/\s+\z/FOO/ On 3/15/07, Jm lists <[EMAIL PROTECTED]> wrote: Thanks John.That's the right way. Another question,what's the regex of "\s

Re: about creating an array

2007-03-15 Thread Jm lists
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(){ >c

Re: about creating an array

2007-03-15 Thread Rob Dixon
Jm lists wrote: 2007/3/16, Rob Dixon <[EMAIL PROTECTED]>: Jm lists wrote: hello lists, please see the codes below: [snip code, repeated below] 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

Re: about creating an array

2007-03-15 Thread John W. Krahn
Will Martell wrote: > I believe this is a matter of list context versus scalar context. Really? Where in the code does this apply? > I think that 1693 should be the last itemid in the textfile. > > Double check that. > > Remove the quotes on the print @arr line and you should get what you > wa

Re: about creating an array

2007-03-15 Thread Tom Phoenix
On 3/15/07, Jm lists <[EMAIL PROTECTED]> wrote: $ tail -20 itemid.txt 1674 1675 1676 Could itemid.txt have both CR and LF as line end characters? If you moved the file from Windows to Unix, that could be the problem. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe,

Re: about creating an array

2007-03-15 Thread Will Martell
I believe this is a matter of list context versus scalar context. I think that 1693 should be the last itemid in the textfile. Double check that. Remove the quotes on the print @arr line and you should get what you want. HTH Will Martell Programmer - Dallas Tx. [EMAIL PROTECTED] [EMAIL PROTECTE

Re: about creating an array

2007-03-15 Thread John W. Krahn
Jm lists wrote: > hello lists, Hello, > please see the codes below: > > use strict; > use warnings; > my @arr = (); > open HD,"itemid.txt" or die $!; > while(){ >chomp; >push @arr,$_; > } > close HD; > > print "@arr"; > > > the itemid.txt has 470 lines data,looks like: > > 1210 > 121

Re: about creating an array

2007-03-15 Thread Jm lists
Also I use RH Linux and Perl 5.8.5.Here is the info: $ perl -v This is perl, v5.8.5 built for i386-linux-thread-multi Copyright 1987-2004, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 sourc

Re: about creating an array

2007-03-15 Thread Jm lists
These are copied from the screen: $ cat test.pl use strict; use warnings; my @arr = (); open HD,"itemid.txt" or die $!; while(){ chomp; push @arr,$_; } close HD; print "@arr"; $ tail -20 itemid.txt 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1

Re: about creating an array

2007-03-15 Thread yitzle
Not yet familiar with push, but just do this: use warnings; open HD,"< itemid.txt" or die $!; @arr = ; close HD; print join @arr, ", "; # Not sure I used join right. On 3/15/07, Jm lists <[EMAIL PROTECTED]> wrote: hello lists, please see the codes below: use strict; use warnings; my @arr =

Re: about creating an array

2007-03-15 Thread Rob Dixon
Jm lists wrote: hello lists, please see the codes below: use strict; use warnings; my @arr = (); open HD,"itemid.txt" or die $!; while(){ 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 122

about creating an array

2007-03-15 Thread Jm lists
hello lists, please see the codes below: use strict; use warnings; my @arr = (); open HD,"itemid.txt" or die $!; while(){ 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