Re: readdir formulated badly? gives wrong count

2007-12-02 Thread reader
"Jeff Pang" <[EMAIL PROTECTED]> writes: > On Dec 3, 2007 12:51 PM, <[EMAIL PROTECTED]> wrote: >> "Jeff Pang" <[EMAIL PROTECTED]> writes: >> > mhh? It won't print a newline, it even won't print anything. >> > b/c @ar is empty, for(...) doesn't go into it, 'print' won't be happened. >> >> Yeah you

Re: Check the entered value is single digit or not

2007-12-02 Thread sivasakthi
> > Try this improvment code: > > #! /usrbin/perl > use strict; > use warnings; > > my $tmp=; > chomp $tmp; # though it's not needed chomp it here, but you'd better > to do this. > if($tmp =~ /^\d{1}$/) > { > print"IT IS SINGLE DIGIT\n"; > } else{ > print"IT IS NOT SINGLE DIGIT\n"; >

Re: Check the entered value is single digit or not

2007-12-02 Thread Jeff Pang
On Dec 3, 2007 1:16 PM, sivasakthi <[EMAIL PROTECTED]> wrote: > Hi all, > > I have tried to find the entered number is single digit or not.. > > the code is following, > > #! /usrbin/perl > use strict; > use warnings; > > my $tmp=; > if($tmp =~ m/(\d)/) > { > print"NO IS SINGLE DIGIT\n"; > } > else

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread Jeff Pang
On Dec 3, 2007 12:51 PM, <[EMAIL PROTECTED]> wrote: > "Jeff Pang" <[EMAIL PROTECTED]> writes: > > mhh? It won't print a newline, it even won't print anything. > > b/c @ar is empty, for(...) doesn't go into it, 'print' won't be happened. > > Yeah your right... (what was I thinking...) but my point

Check the entered value is single digit or not

2007-12-02 Thread sivasakthi
Hi all, I have tried to find the entered number is single digit or not.. the code is following, #! /usrbin/perl use strict; use warnings; my $tmp=; if($tmp =~ m/(\d)/) { print"NO IS SINGLE DIGIT\n"; } else { print"NO IS NOT SINGLE DIGIT\n"; } but it always passed the condition even if we ent

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread reader
"Jeff Pang" <[EMAIL PROTECTED]> writes: > On Dec 3, 2007 10:12 AM, <[EMAIL PROTECTED]> wrote: > >> >> #!/usr/local/bin/perl -w >> use strict; >> use warnings; >> my @ar = (); >> >> for(@ar){ >> print "$_\n"; >> } >> >> But running that script just does nothing but gleefully print

Re: File::Find::name output

2007-12-02 Thread Tom Phoenix
On 12/2/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Near as I can tell, when looking at perldoc File::Find > when used as a variable $File::Find::name it supposed to be the > absolute filename > The output I'm getting is a relative name, and that is what I've fed > the find function. But

To warn or not to warn, that is the question

2007-12-02 Thread Tom Phoenix
On 12/2/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote about a foreach loop with an empty list parameter: > Now that seems just wrong ... Not that it won't loop but that it > doesn't warn or something. There are thousands of places where Larry and the other Perl developers have had to decide, I

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread Jeff Pang
On Dec 3, 2007 10:12 AM, <[EMAIL PROTECTED]> wrote: > > #!/usr/local/bin/perl -w > use strict; > use warnings; > my @ar = (); > > for(@ar){ > print "$_\n"; > } > > But running that script just does nothing but gleefully print a > newline. mhh? It won't print a newline, it even

File::Find::name output

2007-12-02 Thread reader
Near as I can tell, when looking at perldoc File::Find when used as a variable $File::Find::name it supposed to be the absolute filename (In part!): perldoc File::Find (In part!): [...] $File::Find::dir is the current directory name, $_ is the current filename within that directory $File:

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread reader
Harry wrote: >> @DirContent = grep { /^[0-9]/ } readdir(DIR); >> if ($DirContent[0]){ J. Krahn replied: > Again, you are doing boolean tests on the contents of array elements > when you should really be testing the array itself. What if > $DirContent[0] contained the file name "0"? > > if ( @D

Re: External application

2007-12-02 Thread Jeff Pang
On 12/3/07, Eric Krause <[EMAIL PROTECTED]> wrote: > Hello all, > Quick question. I would like to launch an external app and pass data to > it. Can someone please tell me a good place to start looking for > information on this? > Hello, That is based on what applications you have. But basicly you

External application

2007-12-02 Thread Eric Krause
Hello all, Quick question. I would like to launch an external app and pass data to it. Can someone please tell me a good place to start looking for information on this? Thanks, Eric -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.pe

Re: regular expression question

2007-12-02 Thread Rob Dixon
Eric Krause wrote: > Hello all, I have a string like: 1xxx1111xx11x1 I would like to replace the 1's with the total of 1's like this: 5xxx26xx2x1 Can anyone please help? Simply: $string =~ s/(1+)/length $1/ge; HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED]

Re: regular expression question

2007-12-02 Thread Tom Phoenix
On 12/1/07, Eric Krause <[EMAIL PROTECTED]> wrote: >for ($n = 8; $n <=1; $n--) { $n <= 1? Because using the three-part for loop can be error-prone, in Perl we more often use the foreach loop, which is easier to get right on the first try: foreach my $n (reverse 1..8) { ... } Hope th

Re: regular expression question

2007-12-02 Thread Paul Johnson
On Sun, Dec 02, 2007 at 12:14:58AM -0500, Eric Krause wrote: >> $ perl -le' >> $_ = q[1xxx1111xx11x1]; >> print; >> s/(1+)/@{[($l=$1)=~y|1|1|]}/g; >> print; >> ' >> 1xxx1111xx11x1 >> 5xxx26xx2x1 >> >> >> >> :-) >> >> John >> > John, > That worked perfectl

Re: What is equivalent to awk's FNR (line number per crnt file)

2007-12-02 Thread Yitzchok Good
perldoc -> perlvar $. is reset when the filehandle is closed, but not when an open filehandle is reopened without an intervening close(). For more details, see "I/O Operators" in perlop. Because <> never does an explicit close, line numbers increase across ARGV files (but see examples in eof).

Re: Appending a backslash

2007-12-02 Thread Solipsis
On Dec 1, 8:28 am, [EMAIL PROTECTED] (AndrewMcHorney) wrote: > Hello > > I have a string that I would like to append a "\" onto the end of the > string. I tried doing a $string_name."\n" but it is not doing anything. > > Thanks, > Andrew Hi Andrew, It sounds like you want a newline at the end as

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread kens
Been away from the computer for a while, and I see that some of your questions have been addressed, but I will add a few comments. On Dec 1, 10:44 am, [EMAIL PROTECTED] wrote: > Thanks for taking time to respong and go clear thru the script bit by > bit. > > kens <[EMAIL PROTECTED]> writes: > > [.

What is equivalent to awk's FNR (line number per crnt file)

2007-12-02 Thread reader
Seems that I recall perl having a built in like awk's FNR that keeps track of the current line number in each file. Zeros out on each new file. Like $. only goes to zero on each new file. I know how to do that with code but wondered if perl already does it thru some builtin. -- To unsubscrib

Appending a backslash

2007-12-02 Thread AndrewMcHorney
Hello I have a string that I would like to append a "\" onto the end of the string. I tried doing a $string_name."\n" but it is not doing anything. Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: "premature end of header" script error

2007-12-02 Thread Matthew Whipple
Ankur wrote: > Hi, > > I am receiving the following error : "Premature end of script headers" > when running my CGI script using a web browser. > > Instead if I execute the script manually at the shell, it executes > successfully. Actually, the script needs to fetch a lot of data from > the databas

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread Matthew Whipple
Rob Dixon wrote: > Matthew Whipple wrote: >> >> The for loop won't execute if it has nothing through which to >> iterate. On my system the for won't execute with an empty list, but >> will once >> when the array is undefined. Changing the above to 'if >> (defined(@DirContent)) {' would be a bit cl

Re: readdir formulated badly? gives wrong count

2007-12-02 Thread Matthew Whipple
Rob Dixon wrote: > Matthew Whipple wrote: >> >> The for loop won't execute if it has nothing through which to >> iterate. On my system the for won't execute with an empty list, but >> will once >> when the array is undefined. Changing the above to 'if >> (defined(@DirContent)) {' would be a bit cl

Re: regular expression question

2007-12-02 Thread Dr.Ruud
John W . Krahn schreef: > Eric Krause: >> I have a string like: >> 1xxx1111xx11x1 >> >> I would like to replace the 1's with the total of 1's like this: >> 5xxx26xx2x1 > > > $ perl -le' > $_ = q[1xxx1111xx11x1]; > print; > s/(1+)/@{[($l=$1)=~y|1|1|]}/g; >

Re: regular expression question

2007-12-02 Thread Eric Krause
Thanks Tom. It's not homework. I'm trying to parse html chess notation from a site into FEN. I labeled the blank spaces 1, now I need to add them up wherever they occur. Just for fun. What I have tried failed miserably and I'm not sure why. for ($n = 8; $n <=1; $n--) { if ($temp =

Re: regular expression question

2007-12-02 Thread Eric Krause
$ perl -le' $_ = q[1xxx1111xx11x1]; print; s/(1+)/@{[($l=$1)=~y|1|1|]}/g; print; ' 1xxx1111xx11x1 5xxx26xx2x1 :-) John John, That worked perfectly! Thanks!!! Cheers, Eric -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-ma