Re: [^/]* Is Not Working

2018-03-24 Thread Shlomi Fish
On Sun, 18 Mar 2018 12:32:44 +0100
hw  wrote:

> John SJ Anderson  writes:
> 
> >> But this one in its place does not work:
> >> if ($link =~ m/\/([^/]*)$/) { # Oddly this does not work  
> >
> > You still need to escape the `/` inside the character class.
> >
> > This works in my testing: `m/\/([^\/]*)$/`.
> >
> > IMO this is a case where an alternative delimiter for `m//` — such as the
> > `#` in your working example — is a better approach.   
> 
> IIRC it´s said in best practises or so that brackets ({, }) should be
> used for an alternative delimiter and that they should probably be the
> only substitute to use.
> 

I don't blindly follow https://en.wikipedia.org/wiki/Perl_Best_Practices and
disagree about this. I find it useful to use #, % and other delimiters which do
not naturally occur in regexes or otherwise.


-- 
-
Shlomi Fish   http://www.shlomifish.org/
Selina Mandrake - The Slayer (Buffy parody) - http://shlom.in/selina

*Chuck*: Indeed. Anyway, I invited a friend who is even crazier than I am.
*Kermit*: Really, who is this crazy guy?
*Chuck*: Actually, it’s a crazy girl.
— http://is.gd/htmOCv

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: [^/]* Is Not Working

2018-03-23 Thread Mike Flannigan


Correction, I am now receiving the posts.
Sorry.


On 3/23/2018 8:12 PM, beginners-digest-h...@perl.org wrote:



Thank you John Anderson and others.
I see your answers in the archives, but for some
reason I am not receiving the list postings
anymore.  I am working to correct that.

It appears the last time I received a post was 3/17/2018.


Mike




Re: [^/]* Is Not Working

2018-03-23 Thread Mike Flannigan


Thank you John Anderson and others.
I see your answers in the archives, but for some
reason I am not receiving the list postings
anymore.  I am working to correct that.

It appears the last time I received a post was 3/17/2018.


Mike


On 3/17/2018 10:02 AM, Mike Flannigan wrote:


This line works fine:
if ($link =~ m#/([^/]*)$#) {

But this one in its place does not work:
if ($link =~ m/\/([^/]*)$/) { # Oddly this does not work

Gives error:
Unmatched [ in regex; marked by <-- HERE in m//([ <-- HERE ^/ at 
csvtopo24.pl line 74.



I think it has to do with the "[^/]*".
Anybody have an explanation for this?


Mike


Simplified code:

#!/usr/bin/perl

use strict;
use warnings;

my $link = '/tree';

#if ($link =~ m/\/([^/]*)$/) { # Oddly this does not work
if ($link =~ m#/([^/]*)$#) {
    my $match = $1;
    print "\nIt worked - $match.\n\n";
}

__END__





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: [^/]* Is Not Working

2018-03-18 Thread hw
John SJ Anderson  writes:

>> But this one in its place does not work:
>> if ($link =~ m/\/([^/]*)$/) { # Oddly this does not work
>
> You still need to escape the `/` inside the character class.
>
> This works in my testing: `m/\/([^\/]*)$/`.
>
> IMO this is a case where an alternative delimiter for `m//` — such as the `#` 
> in your working example — is a better approach. 

IIRC it´s said in best practises or so that brackets ({, }) should be
used for an alternative delimiter and that they should probably be the
only substitute to use.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: [^/]* Is Not Working

2018-03-17 Thread John SJ Anderson


> But this one in its place does not work:
> if ($link =~ m/\/([^/]*)$/) { # Oddly this does not work

You still need to escape the `/` inside the character class.

This works in my testing: `m/\/([^\/]*)$/`.

IMO this is a case where an alternative delimiter for `m//` — such as the `#` 
in your working example — is a better approach. 



chrs,
john.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




[^/]* Is Not Working

2018-03-17 Thread Mike Flannigan


This line works fine:
if ($link =~ m#/([^/]*)$#) {

But this one in its place does not work:
if ($link =~ m/\/([^/]*)$/) { # Oddly this does not work

Gives error:
Unmatched [ in regex; marked by <-- HERE in m//([ <-- HERE ^/ at 
csvtopo24.pl line 74.



I think it has to do with the "[^/]*".
Anybody have an explanation for this?


Mike


Simplified code:

#!/usr/bin/perl

use strict;
use warnings;

my $link = '/tree';

#if ($link =~ m/\/([^/]*)$/) { # Oddly this does not work
if ($link =~ m#/([^/]*)$#) {
    my $match = $1;
    print "\nIt worked - $match.\n\n";
}

__END__

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Substitution operator is not working in perl - Windows OS

2014-12-05 Thread Jitendra Barik
Hi Adam,

Yes File is RTF.

Regards,
Jitendra

On Fri, Dec 5, 2014 at 7:57 PM, Adam Millerchip  wrote:

> Your filename is in a variable called $rtf1, is the file an RTF?
>
> Maybe something funny is going on with the file-format/encoding, and the
> first line doesn't contain %VERSION% when parsed by your script. You could
> try printing out the line in your script to see what it's trying to match:
>
> for(@array){
> print "'$_'\n";
> ...
>
>
>
>
> On 5 December 2014 at 13:21, Jitendra Barik  wrote:
>
>> Hi Shawn,
>>
>> it is VERSION. This is the not a issue. s/\%VERSION\%/$version1/g; the
>> correct one.
>>
>> If I changed VERSION to VERSIONABC it is working correctly OR if I add
>> more character to VERSION then it is working. I could not understand why it
>> is not working for me.
>>
>> The first place in the file is not changed but second occurrence it
>> has replaced the string.
>>
>> Please let me know oi there anything I need to verify?
>>
>> Regards,
>> Jitendra
>>
>> On Thu, Dec 4, 2014 at 6:50 PM, Shawn H Corey 
>> wrote:
>>
>>> On Thu, 4 Dec 2014 16:06:26 +0530
>>> Jitendra Barik  wrote:
>>>
>>> > My code is:
>>> >
>>> > $version1 = "JITENDRA";
>>> > tie @array,Tie::File,"$rtf1" or die($!);
>>> >
>>> > for(@array){
>>> > #print "Hi";
>>> >  s/\%VERSIONS\%/$version1/g;
>>> >
>>> >
>>> > }
>>> > untie(@array);
>>> >
>>> > FILE:
>>> > ***
>>> >
>>> > *Version *%VERSION%, Hello,HI
>>>
>>> In the substitution, you have VERSIONS but in the file, you have VERSION
>>>
>>> If the S is optional, use: s/\%VERSIONS?\%/$version1/g;
>>>
>>>
>>> --
>>> Don't stop where the ink does.
>>> Shawn
>>>
>>> --
>>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>>> For additional commands, e-mail: beginners-h...@perl.org
>>> http://learn.perl.org/
>>>
>>>
>>>
>>
>>
>> --
>> Regards,
>> Jitendra
>>
>
>


-- 
Regards,
Jitendra


Re: Substitution operator is not working in perl - Windows OS

2014-12-05 Thread Adam Millerchip
Your filename is in a variable called $rtf1, is the file an RTF?

Maybe something funny is going on with the file-format/encoding, and the
first line doesn't contain %VERSION% when parsed by your script. You could
try printing out the line in your script to see what it's trying to match:

for(@array){
print "'$_'\n";
...




On 5 December 2014 at 13:21, Jitendra Barik  wrote:

> Hi Shawn,
>
> it is VERSION. This is the not a issue. s/\%VERSION\%/$version1/g; the
> correct one.
>
> If I changed VERSION to VERSIONABC it is working correctly OR if I add
> more character to VERSION then it is working. I could not understand why it
> is not working for me.
>
> The first place in the file is not changed but second occurrence it
> has replaced the string.
>
> Please let me know oi there anything I need to verify?
>
> Regards,
> Jitendra
>
> On Thu, Dec 4, 2014 at 6:50 PM, Shawn H Corey 
> wrote:
>
>> On Thu, 4 Dec 2014 16:06:26 +0530
>> Jitendra Barik  wrote:
>>
>> > My code is:
>> >
>> > $version1 = "JITENDRA";
>> > tie @array,Tie::File,"$rtf1" or die($!);
>> >
>> > for(@array){
>> > #print "Hi";
>> >  s/\%VERSIONS\%/$version1/g;
>> >
>> >
>> > }
>> > untie(@array);
>> >
>> > FILE:
>> > ***
>> >
>> > *Version *%VERSION%, Hello,HI
>>
>> In the substitution, you have VERSIONS but in the file, you have VERSION
>>
>> If the S is optional, use: s/\%VERSIONS?\%/$version1/g;
>>
>>
>> --
>> Don't stop where the ink does.
>> Shawn
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>>
>
>
> --
> Regards,
> Jitendra
>


Re: Substitution operator is not working in perl - Windows OS

2014-12-04 Thread Jitendra Barik
Hi Shawn,

it is VERSION. This is the not a issue. s/\%VERSION\%/$version1/g; the
correct one.

If I changed VERSION to VERSIONABC it is working correctly OR if I add more
character to VERSION then it is working. I could not understand why it is
not working for me.

The first place in the file is not changed but second occurrence it
has replaced the string.

Please let me know oi there anything I need to verify?

Regards,
Jitendra

On Thu, Dec 4, 2014 at 6:50 PM, Shawn H Corey  wrote:

> On Thu, 4 Dec 2014 16:06:26 +0530
> Jitendra Barik  wrote:
>
> > My code is:
> >
> > $version1 = "JITENDRA";
> > tie @array,Tie::File,"$rtf1" or die($!);
> >
> > for(@array){
> > #print "Hi";
> >  s/\%VERSIONS\%/$version1/g;
> >
> >
> > }
> > untie(@array);
> >
> > FILE:
> > ***
> >
> > *Version *%VERSION%, Hello,HI
>
> In the substitution, you have VERSIONS but in the file, you have VERSION
>
> If the S is optional, use: s/\%VERSIONS?\%/$version1/g;
>
>
> --
> Don't stop where the ink does.
> Shawn
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 
Regards,
Jitendra


Re: Substitution operator is not working in perl - Windows OS

2014-12-04 Thread Shawn H Corey
On Thu, 4 Dec 2014 16:06:26 +0530
Jitendra Barik  wrote:

> My code is:
> 
> $version1 = "JITENDRA";
> tie @array,Tie::File,"$rtf1" or die($!);
> 
> for(@array){
> #print "Hi";
>  s/\%VERSIONS\%/$version1/g;
> 
> 
> }
> untie(@array);
> 
> FILE:
> ***
> 
> *Version *%VERSION%, Hello,HI

In the substitution, you have VERSIONS but in the file, you have VERSION

If the S is optional, use: s/\%VERSIONS?\%/$version1/g;


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Substitution operator is not working in perl - Windows OS

2014-12-04 Thread Hans Ginzel
 

Hello, 

I am sorry, I don't know what are you doing wrong, but this
code works for me. 

use strict;
#use warnings;
use Tie::File;

my $file
= 'file.txt';
my $version1 = "JITENDRA";
tie my(@array), 'Tie::File',
$file or die "Cannot open file `$file': $!";
for(@array) {
 #warn "F: ",
$_;
 s/%VERSION%/$version1/g;
 #warn "S: ", $_;
}
untie @array; 

But
why to use such big hammer like Tie::File for the easy operation. 

Try
just from command line 

perl -i.orig -p subst.pl file.txt 

where
subst.pl contains one line 

s/%VERSION%/ABC/ 

See perldoc perlrun, the
examples under the -i option. 

It is possible tu run this whole from
command line 

perl -i.orig -pe ^"s/^%VERSION^%/XYZ/g^" file.txt 

but
under windows you need to escape percent signs complicatedly.


http://superuser.com/questions/409546/escaping-s-in-file-folder-names-at-the-command-line


Regards, 

Hans 

Dne 04.12.2014 11:36, Jitendra Barik napsal: 

> HI
All, 
> 
> My code is: 
> 
> $version1 = "JITENDRA"; 
> 
> tie
@array,Tie::File,"$rtf1" or die($!); 
> 
> for(@array){ 
> #print "Hi";

> 
> s/%VERSIONS%/$version1/g; 
> 
> } 
> untie(@array); 
> 
> FILE: 
>
***

> 
> VERSION %VERSION%, Hello,HI 
> 
> INSTALLATION NOTES 
> 
> The
driver can be installed either during OS setup or as an update -- 
> 
>
REVISION HISTORY 
> 
> %VERSION% 
> 
>
************** 
> 
> In
the above file, the first %VERSION% is not substitute but second one is
repalced bt string JITENDRA. I am executing in windows OS. Could you
please help me why it is not working. 
> 
> Regards, 
> Jitendra

 

Substitution operator is not working in perl - Windows OS

2014-12-04 Thread Jitendra Barik
HI All,

My code is:

$version1 = "JITENDRA";
tie @array,Tie::File,"$rtf1" or die($!);

for(@array){
#print "Hi";
 s/\%VERSIONS\%/$version1/g;


}
untie(@array);

FILE:
***

*Version *%VERSION%, Hello,HI


*Installation Notes*



The driver can be installed either during OS setup or as an update
-- 

*Revision History*



%VERSION%


**



In the above file, the first %VERSION% is not substitute but second one is
repalced bt string JITENDRA. I am executing in windows OS. Could you please
help me why it is not working.



Regards,
Jitendra


Re: Suddenly this script is not working!

2014-07-30 Thread Jim Gibson

On Jul 29, 2014, at 11:00 PM, ESChamp wrote:

> Jim Gibson wrote on 7/29/2014 10:08 PM:
>>> 
> 
>> This is all speculation because you have not provided us with your exact 
>> program and data files.
> 
> I was warned not to post a 3000 line data file and a 150 line program,
> but if you'd like me to send them to you off-line, I will.

The best way to get help in this situation is to reduce your program and data 
down to about 10 lines each, but still containing the statements that are 
giving you problems. Then you can post both program and data here, and people 
will be able to run your exact code and tell you exactly what is going wrong. 
In the process of extracting the problem areas from your original program you 
might well fix the problem yourself.

Since we don't have the exact code and data, we are all speculating and 
guessing what might be the cause.

Hope you've got your program working by now.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Suddenly this script is not working!

2014-07-30 Thread David Precious
On Wed, 30 Jul 2014 11:55:46 -0400
ESChamp  wrote:

> Robert Wohlfarth wrote on 7/30/2014 10:31 AM:
> > On Wed, Jul 30, 2014 at 1:00 AM, ESChamp  > > wrote:
> > 
> > 0D 0A 3C 70 72 65 3E 0D 0A
> > 
> > so no invisible characters.
> > 
> > > Or maybe  occurs on the first line, in which case $index
> > > will have the value 0, which is treated as false, and your
> > > program will die.
> > 
> >  is line 709. No other line is simply 
> > 
> > 
> > How about the 0D 0A at the end of the line? Unless the script used
> > "chomp", the exact line is "\r\n".
> 
> Thanks, Robert. I changed the  to \r\n but it made no
> difference.

Did you also replace the single quotes with double quotes, so that the
\r\n will actually be a carriage return and newline, rather than
literal?

You're probably better off doing it via a regex, or ensuring chomp() is
used, so it'll be portable between platforms with different line
endings.




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Suddenly this script is not working!

2014-07-30 Thread ESChamp
Robert Wohlfarth wrote on 7/30/2014 10:31 AM:
> On Wed, Jul 30, 2014 at 1:00 AM, ESChamp  > wrote:
> 
> 0D 0A 3C 70 72 65 3E 0D 0A
> 
> so no invisible characters.
> 
> > Or maybe  occurs on the first line, in which case $index will have 
> the value 0, which is treated as false, and your program will die.
> 
>  is line 709. No other line is simply 
> 
> 
> How about the 0D 0A at the end of the line? Unless the script used
> "chomp", the exact line is "\r\n".

Thanks, Robert. I changed the  to \r\n but it made no difference.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Suddenly this script is not working!

2014-07-30 Thread Robert Wohlfarth
On Wed, Jul 30, 2014 at 1:00 AM, ESChamp  wrote:

> 0D 0A 3C 70 72 65 3E 0D 0A
>
> so no invisible characters.
>
> > Or maybe  occurs on the first line, in which case $index will have
> the value 0, which is treated as false, and your program will die.
>
>  is line 709. No other line is simply 


How about the 0D 0A at the end of the line? Unless the script used "chomp",
the exact line is "\r\n".

-- 
Robert Wohlfarth


Re: Suddenly this script is not working!

2014-07-29 Thread ESChamp
Jim Gibson wrote on 7/29/2014 10:08 PM:
> 
> On Jul 29, 2014, at 5:12 PM, ESChamp  wrote:
> 
>> ESChamp wrote on 7/28/2014 6:59 PM:
>> 
>> Let me backtrack and provide some background information.
>> 
>> This script processes two files, recapfile, a plain text file, and copy,
>> and HTML-formatted file.
>> 
>> It reads copy into an array, and recapfile into another array. Then it
>> writes a new array which contains all the initial lines of the recapfile
>> array from the first line down to but not including the first line
>> containing / RESULTS OF BOARD 1/
> 
> Most of that information is superfluous. You need to concentrate on the 
> precise problem that you are having.

Didn't I do that in the next section?

>> And here is where it goes wrong ('No  found')
>> 
>> ($index) = grep $hfile[$_] eq '', 0 .. $#hfile;
>> die 'No  found' unless $index;
>> 
>> I printed hfile using
>>  foreach (@hfile) { print "$_\n"; }
>> 
>> and it looks fine! That is, there is a line with only  on it!!!
> 
> Perhaps the line containing ‘’ contains whitespace characters that you 
> cannot see when you print it. 

Good suggestion! I looked at the file with a hex editor and a set of
characters like this

0D 0A 3C 70 72 65 3E 0D 0A

so no invisible characters.

> Or maybe  occurs on the first line, in which case $index will have the 
> value 0, which is treated as false, and your program will die.

 is line 709. No other line is simply 

> This is all speculation because you have not provided us with your exact 
> program and data files.

I was warned not to post a 3000 line data file and a 150 line program,
but if you'd like me to send them to you off-line, I will.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Suddenly this script is not working!

2014-07-29 Thread Jim Gibson

On Jul 29, 2014, at 5:12 PM, ESChamp  wrote:

> ESChamp wrote on 7/28/2014 6:59 PM:
>> Suddenly, without warning or error messages, the script below is
>> producing null for values of $hfile and $bfile!
>> 
>> The script begins:
>> 
>> 
> 
> Let me backtrack and provide some background information.
> 
> This script processes two files, recapfile, a plain text file, and copy,
> and HTML-formatted file.
> 
> It reads copy into an array, and recapfile into another array. Then it
> writes a new array which contains all the initial lines of the recapfile
> array from the first line down to but not including the first line
> containing / RESULTS OF BOARD 1/

Most of that information is superfluous. You need to concentrate on the precise 
problem that you are having.

> 
> And here is where it goes wrong ('No  found')
> 
> ($index) = grep $hfile[$_] eq '', 0 .. $#hfile;
> die 'No  found' unless $index;
> 
> I printed hfile using
>   foreach (@hfile) { print "$_\n"; }
> 
> and it looks fine! That is, there is a line with only  on it!!!

Perhaps the line containing ‘’ contains whitespace characters that you 
cannot see when you print it. If so, you can replace you exact test with a 
regular expression:

  if( grep // @hfile ) {
…
  }

Or maybe  occurs on the first line, in which case $index will have the 
value 0, which is treated as false, and your program will die.

This is all speculation because you have not provided us with your exact 
program and data files.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Suddenly this script is not working!

2014-07-29 Thread ESChamp
ESChamp wrote on 7/28/2014 6:59 PM:
> Suddenly, without warning or error messages, the script below is
> producing null for values of $hfile and $bfile!
> 
> The script begins:
> 
> #!/usr/bin/perl
> 
> use Tie::File;
> use File::Copy 'copy';
> use File::Spec;
> 
> 
> and further down, it has:
> 
> # Tie it to an array
> #
> (my $copy = $htmfile) =~ s/(\.htm)\z/-Copy$1/i;
> copy $htmfile, $copy;
> tie my @hfile, 'Tie::File', $copy;
> tie my @bfile, 'Tie::File', $recapfile;
> 
> ## hfile is the array of the lines of htmfile
> #
> print "$copy \n";
> print "hfile: 1--$hfile-- \n";
> 
> $copy's value is correct.
> 
> I'm on a Windows 7 machine. Should I have the Windows full pathname for
> perl.exe at the top
> 
> Happy to send the entire script to anyone who would like to see it.
> 
> Thanks.
> 

Let me backtrack and provide some background information.

This script processes two files, recapfile, a plain text file, and copy,
and HTML-formatted file.

It reads copy into an array, and recapfile into another array. Then it
writes a new array which contains all the initial lines of the recapfile
array from the first line down to but not including the first line
containing / RESULTS OF BOARD 1/

And here is where it goes wrong ('No  found')

($index) = grep $hfile[$_] eq '', 0 .. $#hfile;
die 'No  found' unless $index;

I printed hfile using
foreach (@hfile) { print "$_\n"; }

and it looks fine! That is, there is a line with only  on it!!!



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Suddenly this script is not working!

2014-07-29 Thread Kent Fredric
The script begins:
>
> #!/usr/bin/perl
>
> use Tie::File;
> use File::Copy 'copy';
> use File::Spec;
>
>


I think this problem becomes much clearer if you enable strict.

-- [ A.pl ] ---
my @list = qw( a b c );

print "X $list Y";

-- [ A.pl  output ] --
X Y

-- [ B.pl ] --
use strict;

my @list = qw( a b c );

print "X $list Y";
-- [ B.pl output ]--

Global symbol "$list" requires explicit package name at /tmp/nostrict.pl
line 6.
Execution of /tmp/nostrict.pl aborted due to compilation errors.

---


What you meant to do, I imagine, is this:


-- [ C.pl ]--

use strict;

my @list = qw(a b c);

print "X " . @list . " Y";

-- [ C.pl output ]--

X 3 Y

-

Or perhaps:

--- [ D.pl ]---

use strict;

my @list = qw(a b c);

print "X $#list Y";  # last item number, not length

--- [ D.pl output ]--
X 2 Y




So unless there's deleted code we're not seeing, this does indeed seem to
reaffirm the mantra "use strict; use warnings, and let perl tell you what
is wrong" =)



-- 
Kent

*KENTNL* - https://metacpan.org/author/KENTNL


Re: Suddenly this script is not working!

2014-07-29 Thread Jim Gibson

On Jul 28, 2014, at 3:59 PM, ESChamp  wrote:

> Suddenly, without warning or error messages, the script below is
> producing null for values of $hfile and $bfile!

What are $hfile and $bfile? You don’t show them in your script. You show two 
arrays: @hfile and @bfile, but those are not the same as the scalar variables 
$hfile and $bfile.

When asking other people for help, it is best to reduce your program down to 
the shortest version that illustrates your problem. People can help you fix 
that, and you can then apply the fix to your actual program.

In this case, it is impossible to help you with the above stated problem, 
because the variable about which you are complaining do not exist in your 
program.

If you actually mean @hfile and @bfile, you say that $copy is correct. Are the 
contents of the file named by $copy also correct?

> The script begins:
> 
> #!/usr/bin/perl
> 
> use Tie::File;
> use File::Copy 'copy';
> use File::Spec;
> 
> 
> and further down, it has:
> 
> # Tie it to an array
> #
> (my $copy = $htmfile) =~ s/(\.htm)\z/-Copy$1/i;
> copy $htmfile, $copy;
> tie my @hfile, 'Tie::File', $copy;
> tie my @bfile, 'Tie::File', $recapfile;
> 
> ## hfile is the array of the lines of htmfile
> #
>print "$copy \n";
>print "hfile: 1--$hfile-- \n";
> 
> $copy's value is correct.
> 
> I'm on a Windows 7 machine. Should I have the Windows full pathname for
> perl.exe at the top

No, because if you are getting any output at all from your Perl program, then 
the program has been found and executed by the operating system.

> Happy to send the entire script to anyone who would like to see it.

Produce a shorter version of the script that demonstrates the problem and post 
it here for all to see.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Suddenly this script is not working!

2014-07-29 Thread David Precious
On Mon, 28 Jul 2014 20:48:51 -0400
Shawn H Corey  wrote:

> > copy $htmfile, $copy;  
> 
> # always check for error
> copy $htmfile, $copy or die "could not copy $htmlfile\n";

And even more helpfully, include in the message $! - which will contain
the error message to show you what actually went wrong:

copy $htmlfile, $copy
or die "Failed to copy $htmlfile to $copy - $!";






-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Suddenly this script is not working!

2014-07-28 Thread Shawn H Corey
On Mon, 28 Jul 2014 18:59:47 -0400
ESChamp  wrote:

> # Tie it to an array
> #
> (my $copy = $htmfile) =~ s/(\.htm)\z/-Copy$1/i;

# the substitution will fail if the HTML file
# doesn't have the correct extension
die "invalid extension on $htmlfile\n" if $copy eq $htmlfile;

> copy $htmfile, $copy;

# always check for error
copy $htmfile, $copy or die "could not copy $htmlfile\n";


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Suddenly this script is not working!

2014-07-28 Thread ESChamp
Suddenly, without warning or error messages, the script below is
producing null for values of $hfile and $bfile!

The script begins:

#!/usr/bin/perl

use Tie::File;
use File::Copy 'copy';
use File::Spec;


and further down, it has:

# Tie it to an array
#
(my $copy = $htmfile) =~ s/(\.htm)\z/-Copy$1/i;
copy $htmfile, $copy;
tie my @hfile, 'Tie::File', $copy;
tie my @bfile, 'Tie::File', $recapfile;

## hfile is the array of the lines of htmfile
#
print "$copy \n";
print "hfile: 1--$hfile-- \n";

$copy's value is correct.

I'm on a Windows 7 machine. Should I have the Windows full pathname for
perl.exe at the top

Happy to send the entire script to anyone who would like to see it.

Thanks.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: -e switch is not working on Window 7 and 8

2014-07-21 Thread Purvee Vora
Thanks Wolf.
It is working now.

cheers,
Purvee
On Mon, Jul 21, 2014 at 11:07 AM, WFB  wrote:

>   Hi Purvee,
>
> perl -e 'xyz' works fine on Unix, however on Windows you must use "
> instead.
>
> perl -e "print qq(Hello \n)"
>
> greetings,
> wolf
>
>
> On 21 July 2014 07:24, Purvee Vora  wrote:
>
>> Hi All,
>>
>> I am currently learing perl and was trying command line switches but It
>> is not working in window7 and 8.
>>
>> Can any one help me out about this.
>>
>> I am really stuck here.
>>
>> I tried following example:
>>
>> perl -e 'print "Hello \n";'
>>
>> Commnad line shows blank response. I cannot see "Hello" world on CMD.
>>
>> Regards,
>> Purvee
>>
>
>


Re: -e switch is not working on Window 7 and 8

2014-07-20 Thread Shaji Kalidasan
Dear Purvee,

Here is one way to do it

#Approach 1

[code]
perl -e "print qq{Hello\n}"
[/code]

[output]
Hello

[/output]

Please note: qq stands for double quotes

#Approach 2

[code]
perl -e "print 'Hello'"
[/code]

[output]
Hello
[/output]



On Mon, Jul 21, 2014 at 10:54 AM, Purvee Vora  wrote:

> Hi All,
>
> I am currently learing perl and was trying command line switches but It is
> not working in window7 and 8.
>
> Can any one help me out about this.
>
> I am really stuck here.
>
> I tried following example:
>
> perl -e 'print "Hello \n";'
>
> Commnad line shows blank response. I cannot see "Hello" world on CMD.
>
> Regards,
> Purvee
>



-- 
best,
Shaji
--
Your talent is God's gift to you. What you do with it is your gift back to
God.
--


Re: -e switch is not working on Window 7 and 8

2014-07-20 Thread WFB
Hi Purvee,

perl -e 'xyz' works fine on Unix, however on Windows you must use " instead.

perl -e "print qq(Hello \n)"

greetings,
wolf


On 21 July 2014 07:24, Purvee Vora  wrote:

> Hi All,
>
> I am currently learing perl and was trying command line switches but It is
> not working in window7 and 8.
>
> Can any one help me out about this.
>
> I am really stuck here.
>
> I tried following example:
>
> perl -e 'print "Hello \n";'
>
> Commnad line shows blank response. I cannot see "Hello" world on CMD.
>
> Regards,
> Purvee
>


-e switch is not working on Window 7 and 8

2014-07-20 Thread Purvee Vora
Hi All,

I am currently learing perl and was trying command line switches but It is
not working in window7 and 8.

Can any one help me out about this.

I am really stuck here.

I tried following example:

perl -e 'print "Hello \n";'

Commnad line shows blank response. I cannot see "Hello" world on CMD.

Regards,
Purvee


Re: auto completion by crtl + space is not working with eclipse -epic module , Good IDE for beginner

2014-07-15 Thread Benjamin Fernandis
Hi,

I read document and tried to test by typing trigger characters ":" and ">"
also by CTRL - SPACE. but not working.

Is there anything else require to install on top of elipse + perl plugin.

As my current system has centos 7 + fresh perl install + eclipse + perl
plugin for it.

Thx


On Tue, Jul 15, 2014 at 10:09 PM, Shaji Kalidasan 
wrote:

> Dear Benjamin,
>
> Excerpt from the documentation
>
> The autocompletion suggestions will pop up automatically after you have
> typed a trigger character. Triggers are ":" and ">". Alternatively, it can
> be triggered by pressing CTRL-SPACE.
>
> Currently the Indirect Object Invocation is not recognized by the content
> assist.
>
> This code block will not work:
>
> $smtp = new Net::SMTP;
> $smtp->[no content assist]
>
> This one will work:
>
> $smtp = Net::SMTP->new(.);
> $smtp->[content assist]
>
>
>
> On Tue, Jul 15, 2014 at 1:11 PM, Benjamin Fernandis 
> wrote:
>
>> Hi,
>>
>> I installed Ecplise standard version but auto completion of syntax is not
>> working while pressing CTL + SPACE key.
>>
>> Is there any configuration required for this ? Any other good IDE for
>> beginner ?
>>
>> Thx
>>
>
>
>
> --
> best,
> Shaji
>
> --
> Your talent is God's gift to you. What you do with it is your gift back to
> God.
>
> --
>


Re: auto completion by crtl + space is not working with eclipse -epic module , Good IDE for beginner

2014-07-15 Thread Shaji Kalidasan
Dear Benjamin,

Excerpt from the documentation

The autocompletion suggestions will pop up automatically after you have
typed a trigger character. Triggers are ":" and ">". Alternatively, it can
be triggered by pressing CTRL-SPACE.

Currently the Indirect Object Invocation is not recognized by the content
assist.

This code block will not work:

$smtp = new Net::SMTP;
$smtp->[no content assist]

This one will work:

$smtp = Net::SMTP->new(.);
$smtp->[content assist]



On Tue, Jul 15, 2014 at 1:11 PM, Benjamin Fernandis 
wrote:

> Hi,
>
> I installed Ecplise standard version but auto completion of syntax is not
> working while pressing CTL + SPACE key.
>
> Is there any configuration required for this ? Any other good IDE for
> beginner ?
>
> Thx
>



-- 
best,
Shaji
--
Your talent is God's gift to you. What you do with it is your gift back to
God.
--


auto completion by crtl + space is not working with eclipse -epic module , Good IDE for beginner

2014-07-15 Thread Benjamin Fernandis
Hi,

I installed Ecplise standard version but auto completion of syntax is not
working while pressing CTL + SPACE key.

Is there any configuration required for this ? Any other good IDE for
beginner ?

Thx


Re: Solved mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-31 Thread Jan Gruber
Hi Martin,

>   I feel embarrassed for wasting everybody's time, but I
> really appreciate the help.

sometimes one needs to think out loud to solve a problem. I had a lot of 
problems like this one where it helped to get feedback from this list.

Regards,
Jan
-- 
Paranoia is simply an optimistic outlook on life.
- 

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Solved mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-31 Thread Jan Gruber
Hi Martin,

>   I feel embarrassed for wasting everybody's time, but I
> really appreciate the help.

sometimes one needs to think out loud to solve a problem. I had a lot of 
problems like this one where it helped to get feedback from this list. 

Regards,
Jan
-- 
Paranoia is simply an optimistic outlook on life.
- 

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-30 Thread Shawn H Corey
On Thu, 30 Jan 2014 07:47:29 -0600
"Martin G. McCormick"  wrote:

> David Precious writes:
> > change "system" to "print" to print out the command that would be
> > run,  
> 
> Great suggestion! I actually did try that using echo instead of
> print so that system was still involved and the values were
> correct. It looked beautiful.

Well, this is a bit redundant since you solved it but try replacing the
"echo" with "ls" and then "ls -l". The first replacement is to test to
see if the directory is readable, the second, to see if its i-node is
readable.


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Solved mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-30 Thread Martin G. McCormick
This is a classic example of the admonition, "Never trust data."

I did try the following:

David Precious writes:
> change "system" to "print" to print out the command that would be run,
> and (a) you'll likely see the problem, or (b) you can try running that
> exact command.

I had tried echo as the system() command and I thought
it was okay but after a night's sleep and trying the print
command as suggested, the problem was obvious. I had gotten
$filename from the following code snippet:

foreach $keyfile (@filenames) {#Checking this key file.
$kpath = $keyfile;
( $filename, $directories, $suffix ) = fileparse($kpath);

I went on to use $filename without making sure it was
clean. It has an embedded newline at the end and

chomp($filename);

fixed everything.

The temporary print statement showed the 1 line becoming
2 and a trace of $filename in perl -d clearly showed the
newline.

I feel embarrassed for wasting everybody's time, but I
really appreciate the help.

Martin


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-30 Thread Martin G. McCormick
"Ron Bergin" writes:
> As has already been mentioned, part of the problem is your quoting.
> 
> What is the value of $directories and more specifically, does it end with
> a forward slash?  Personally, I prefer to leave off the trailing dir
> separator because IMO it makes it more clear later when the $filename is
> added.

You'll see in a previous message that I really goofed.
The $filename variable contained the correct string but also
contained a newline at the end so chomp was in order. I removed
all quotes except for the beginning and ending quotes in the
system command.

I am certainly saving all the suggestions that various
members of this list have sent because this may come up again
some day as the same problem for a different reason.

> Why are you using a system call instead of the more portable move() of
> mv() function from File::Copy, which is a core module?
> 
> use File::Copy qw(cp mv);

Easy answer: I didn't know any better. I've been working with
perl to really learn it for about a year and didn't know it
existed as I didn't need it until now.

Many thanks to all.

Martin McCormick

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-30 Thread Martin G. McCormick
David Precious writes:
> change "system" to "print" to print out the command that would be run,

Great suggestion! I actually did try that using echo instead of
print so that system was still involved and the values were
correct. It looked beautiful.

> and (a) you'll likely see the problem, or (b) you can try running that
> exact command.
> 
> 
> > system(
> > "mv $directories$filename \"$directories\"deleted_keys/"
> > );
> 
> I doubt you meant that extraneous \" in the middle there - I suspect
> you meant \"$directories/deleted_keys\".

That didn't start out like that but I put the \ 's infront of
quotes to see if it would make any difference. It didn't.

> Oh, and make sure that the variables you're interpolating there aren't
> from an untrusted source :)

I have not had a chance to research that yet, but that might be
the problem. I am using strict as in

#!/usr/bin/perl -w
use strict;
use Time::Local;
use File::Basename;

I remember reading about how all the variables should be from
trusted sources but I'll have to remind myself what that means
again. 

Thanks very much.

Martin McCormick

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-30 Thread Ron Bergin
Martin G. McCormick wrote:
>   I have a perl script that I run as root which needs to
> move a file from where it is to another directory.
>
>   I keep getting the "Usage"  help message and a
> permission denied. If I su to root and manually make the move,
> it works.
>
>   The perl script is not trying to run suid to root. I am
> root when I call it. The line in question reads:
>
> system(
> "mv $directories$filename \"$directories\"deleted_keys/"
> );
>
> $directories and $filename are correctly set at the time. The
> output from the script is:
>
> usage: mv [-f | -i | -n] [-v] source target
>mv [-f | -i | -n] [-v] source ... directory
> /var/named/etc/namedb/dynamic/okstate.edu/deleted_keys/: Permission denied
>

As has already been mentioned, part of the problem is your quoting.

What is the value of $directories and more specifically, does it end with
a forward slash?  Personally, I prefer to leave off the trailing dir
separator because IMO it makes it more clear later when the $filename is
added.

Why are you using a system call instead of the more portable move() of
mv() function from File::Copy, which is a core module?

use File::Copy qw(cp mv);

...
...

mv("$directories/$filename", "$directories/deleted_keys")
  or warn qq(Failed to move "$directories/$filename" to
"$directories/deleted_keys" <$!>);


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-30 Thread Charles DeRykus
On Wed, Jan 29, 2014 at 2:10 PM, Martin G. McCormick <
mar...@server1.shellworld.net> wrote:

> I have a perl script that I run as root which needs to
> move a file from where it is to another directory.
>
> I keep getting the "Usage"  help message and a
> permission denied. If I su to root and manually make the move,
> it works.
>
> The perl script is not trying to run suid to root. I am
> root when I call it. The line in question reads:
>
> system(
> "mv $directories$filename \"$directories\"deleted_keys/"
> );
>
> $directories and $filename are correctly set at the time. The
> output from the script is:
>
> usage: mv [-f | -i | -n] [-v] source target
>mv [-f | -i | -n] [-v] source ... directory
> /var/named/etc/namedb/dynamic/okstate.edu/deleted_keys/: Permission denied
>
> As I said, it works if I become root and manually move the file
> in question.o
> This is basically a script for moving expired dnssec keys out of
> the directory and in to a morgue of dead keys which we will keep
> around if there is trouble-shooting to be done later.
>
> The script, when run, is owned by root and run by root
>



Another recommendation:

File::Copy is core now I believe, is portable, faster, easier and more
transparent  than deciphering shell error returns, and enables you
to avoid the nasty quoting issues of a 'system' call:

use File::Copy;
move( $file1, $file2) or die "move: $!";

See: perldoc File::Copy

-- 
Charles DeRykus


Re: mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-30 Thread Hal Wigoda
Is the directory you are moving to writable?

Sent from my iPad

> On Jan 29, 2014, at 4:10 PM, "Martin G. McCormick" 
>  wrote:
> 
>I have a perl script that I run as root which needs to
> move a file from where it is to another directory.
> 
>I keep getting the "Usage"  help message and a
> permission denied. If I su to root and manually make the move,
> it works.
> 
>The perl script is not trying to run suid to root. I am
> root when I call it. The line in question reads:
> 
> system(
> "mv $directories$filename \"$directories\"deleted_keys/"
> );
> 
> $directories and $filename are correctly set at the time. The
> output from the script is:
> 
> usage: mv [-f | -i | -n] [-v] source target
>   mv [-f | -i | -n] [-v] source ... directory
> /var/named/etc/namedb/dynamic/okstate.edu/deleted_keys/: Permission denied
> 
> As I said, it works if I become root and manually move the file
> in question.o
> This is basically a script for moving expired dnssec keys out of
> the directory and in to a morgue of dead keys which we will keep
> around if there is trouble-shooting to be done later.
> 
> The script, when run, is owned by root and run by root.
> 
>Any explanation is appreciated since this isn't making
> sense right now.
> 
> Thank you.
> 
> Martin McCormick
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-30 Thread David Precious
On Wed, 29 Jan 2014 16:10:25 -0600
"Martin G. McCormick"  wrote:
>   I keep getting the "Usage"  help message and a
> permission denied. If I su to root and manually make the move,
> it works.

change "system" to "print" to print out the command that would be run,
and (a) you'll likely see the problem, or (b) you can try running that
exact command.


> system(
> "mv $directories$filename \"$directories\"deleted_keys/"
> );

I doubt you meant that extraneous \" in the middle there - I suspect
you meant \"$directories/deleted_keys\".

Oh, and make sure that the variables you're interpolating there aren't
from an untrusted source :)

Cheers

Dave P 


-- 
David Precious ("bigpresh") 
http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook
www.preshweb.co.uk/cpanwww.preshweb.co.uk/github



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-30 Thread Martin G. McCormick
I have a perl script that I run as root which needs to
move a file from where it is to another directory.

I keep getting the "Usage"  help message and a
permission denied. If I su to root and manually make the move,
it works.

The perl script is not trying to run suid to root. I am
root when I call it. The line in question reads:

system(
"mv $directories$filename \"$directories\"deleted_keys/"
);

$directories and $filename are correctly set at the time. The
output from the script is:

usage: mv [-f | -i | -n] [-v] source target
   mv [-f | -i | -n] [-v] source ... directory
/var/named/etc/namedb/dynamic/okstate.edu/deleted_keys/: Permission denied

As I said, it works if I become root and manually move the file
in question.o
This is basically a script for moving expired dnssec keys out of
the directory and in to a morgue of dead keys which we will keep
around if there is trouble-shooting to be done later.

The script, when run, is owned by root and run by root.

Any explanation is appreciated since this isn't making
sense right now.

Thank you.

Martin McCormick

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: why this is not working ??

2003-08-28 Thread John W. Krahn
Jeff Westman wrote:
> 
> --- "John W. Krahn" <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> > >
> >
> open(STATUS,">>status.txt");for($i=0;$i<=98985;$i++){system("process");if(($i%10)==0){print(STATUS"\n\n
> >  $i iterations over !!*\n\n")}}close(STATUS);
> >
> > However that is not very readable or maintainable.
> 
> I ran this on my system (HP-UX, perl v5.6.1), changed "process" to "date" and
> it ran fine _as-is_.  Could it be hosing on the external command here??!

To find out if it is, test the return value from system().

system( 'process' ) == 0 or die "system 'process' failed: $?";


perldoc -f system


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: why this is not working ??

2003-08-28 Thread Jeff Westman

--- "John W. Krahn" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > 
> > On Wed, Aug 27, 2003 at 11:18:26AM +0530, T.S.Ravi Shankar wrote:
> > >
> > > open(STATUS,">> status.txt");
> > > for ($i=0; $i<=98985;$i++) {
> > >   system ("process");
> > >   if (($i%10)==0)
> > > { print STATUS "\n\n  $i iterations over !!*\n\n"; }
> > >   }
> > > close(STATUS);
> > 
> > I'm not an expert, but shouldn't you add a space between % and 10?
> 
> No, a space is not necessary there.  In fact, if you use the print
> function instead of the print operator, you can remove all the
> non-quoted space characters.
> 
>
open(STATUS,">>status.txt");for($i=0;$i<=98985;$i++){system("process");if(($i%10)==0){print(STATUS"\n\n
>  $i iterations over !!*\n\n")}}close(STATUS);
> 
> However that is not very readable or maintainable.

I ran this on my system (HP-UX, perl v5.6.1), changed "process" to "date" and
it ran fine _as-is_.  Could it be hosing on the external command here??!


-JW


__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: why this is not working ??

2003-08-28 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
> 
> On Wed, Aug 27, 2003 at 11:18:26AM +0530, T.S.Ravi Shankar wrote:
> >
> > open(STATUS,">> status.txt");
> > for ($i=0; $i<=98985;$i++) {
> >   system ("process");
> >   if (($i%10)==0)
> > { print STATUS "\n\n  $i iterations over !!*\n\n"; }
> >   }
> > close(STATUS);
> 
> I'm not an expert, but shouldn't you add a space between % and 10?

No, a space is not necessary there.  In fact, if you use the print
function instead of the print operator, you can remove all the
non-quoted space characters.

open(STATUS,">>status.txt");for($i=0;$i<=98985;$i++){system("process");if(($i%10)==0){print(STATUS"\n\n
 $i iterations over !!*\n\n")}}close(STATUS);

However that is not very readable or maintainable.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: why this is not working ??

2003-08-28 Thread jqdkf
On Wed, Aug 27, 2003 at 11:18:26AM +0530, T.S.Ravi Shankar wrote:
> ---
> 
> open(STATUS,">> status.txt");
> for ($i=0; $i<=98985;$i++) {
>   system ("process");
>   if (($i%10)==0) 
> { print STATUS "\n\n  $i iterations over !!*\n\n"; }
>   }
> close(STATUS);
> 
> -

I'm not an expert, but shouldn't you add a space between % and 10?

-- 
Zeng Nan

Simple is Beautiful.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: why this is not working ??

2003-08-27 Thread zentara
On Wed, 27 Aug 2003 11:18:26 +0530, [EMAIL PROTECTED] (T.S.Ravi
Shankar) wrote:
>
>open(STATUS,">> status.txt");
>for ($i=0; $i<=98985;$i++) {
>  system ("process");
>  if (($i%10)==0) 
>{ print STATUS "\n\n  $i iterations over !!*\n\n"; }
>  }
>close(STATUS);
>
>-
>
>"status.txt"  remains empty when the processes are run & the whole file
>is written only at the end of all iterations, which serves no purpose !!
>
>Could you please help me out in solving this problem ??

Turn off buffering!.
Look at this script to demonstrate.
#
#!/usr/bin/perl
#without a newline, it won't print 
#until the buffer is 2k 

#$|=1;  # try it with and without this line :-) 

while (1){
print 'aa';
select(undef,undef,undef,.03);
}
###


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: why this is not working ??

2003-08-27 Thread simran
Buffering is probably the reason why the file is not written till later.

Try putting the following (from memory);

-

use FileHandle;
open (STATUS, ">> status.txt") || die;
STATUS->autoflush(1);

--


On Wed, 2003-08-27 at 15:48, T.S.Ravi Shankar wrote:
> Hi all :
> 
> I am running a process "n" number of times with a for loop.  I am
> interested in looking for the status at specific intervals(say at every
> 10 iterations).  I wrote the below shown code for this purpose but
> without success :
> 
> ---
> 
> open(STATUS,">> status.txt");
> for ($i=0; $i<=98985;$i++) {
>   system ("process");
>   if (($i%10)==0) 
> { print STATUS "\n\n  $i iterations over !!*\n\n"; }
>   }
> close(STATUS);
> 
> -
> 
> "status.txt"  remains empty when the processes are run & the whole file
> is written only at the end of all iterations, which serves no purpose !!
> 
> Could you please help me out in solving this problem ??
> 
> Thanks,
> Ravi


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



why this is not working ??

2003-08-27 Thread T.S.Ravi Shankar
Hi all :

I am running a process "n" number of times with a for loop.  I am
interested in looking for the status at specific intervals(say at every
10 iterations).  I wrote the below shown code for this purpose but
without success :

---

open(STATUS,">> status.txt");
for ($i=0; $i<=98985;$i++) {
  system ("process");
  if (($i%10)==0) 
{ print STATUS "\n\n  $i iterations over !!*\n\n"; }
  }
close(STATUS);

-

"status.txt"  remains empty when the processes are run & the whole file
is written only at the end of all iterations, which serves no purpose !!

Could you please help me out in solving this problem ??

Thanks,
Ravi

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]