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, $_;
}
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
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
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
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
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
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
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,
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
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
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
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
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 =
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
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
15 matches
Mail list logo