switch user

2003-06-16 Thread Ahmed Moustafa
How can I switch user "su" in perl?
Thanks in advance,
Ahmed
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: switch user

2003-06-16 Thread Ahmed Moustafa
Steve Grazzini wrote:
Ahmed Moustafa <[EMAIL PROTECTED]> wrote:

[ That address is bouncing, by the way. ]
It should not! What was the message that you got?


How can I switch user "su" in perl?


It's much easier to do that before running the script.  :-)

  $ su -c ./script.pl

And then once you're root, you can change the real and effective
user ids with the magic $< and $> variables.
From inside a non-privileged Perl script, the only thing you can
do is re-exec the script via su/sudo and punch in the password.
  #!/usr/bin/perl -l

  exec "sudo", "/usr/bin/perl", $0, @ARGV if $<;

  print " uid: ", getpwuid $<;
  print "euid: ", getpwuid $>;
If you need to run disconnected from the terminal, you should
just put the script in the correct user's crontab.
Would you tell me more about the crontab, please?

But you could also use Expect.pm to automate password entry,
or configure sudo not to ask for the password.
What I need to do is to add a PGP public key to a user's key ring. Which 
approach would you recommend?

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


Re: Global variables and a forked process

2003-08-10 Thread Ahmed Moustafa
Steve Grazzini wrote:
On Sat, Aug 09, 2003 at 05:14:34PM -0700, Ahmed Moustafa wrote:

Steve Grazzini wrote:

Changes made after the fork() won't be visible in the other
process, if that's what you're wondering.
Yes, that's exactly what I am wondering. So, is there a way to
assign values to the global variables in the parent process?


No.  You'd need to switch to threads or keep the fork and
use some kind of IPC.
% perldoc perlipc
Are there threads in Perl?

What is your application doing?
It scans FTP home directories, once it finds a file, it validates the 
file name, if it is expected or not and then encrypts the file.

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


Re: Global variables and a forked process

2003-08-14 Thread Ahmed Moustafa
Steve Grazzini wrote:
On Sat, Aug 09, 2003 at 01:04:26PM -0700, Ahmed Moustafa wrote:

Does a forked process share the memory locations of the global 
variables from the parent process?


Changes made after the fork() won't be visible in the other
process, if that's what you're wondering.
Yes, that's exactly what I am wondering. So, is there a way to assign 
values to the global variables in the parent process?

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


Global variables and a forked process

2003-08-14 Thread Ahmed Moustafa
Does a forked process share the memory locations of the global variables 
from the parent process?

Thanks in advance!

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


Re: Newbie Help please.

2002-03-31 Thread Ahmed Moustafa

Sa wrote:
> #!/usr/bin/perl -w
> $map{"red"} = "apple";
> $map{"green"} = "grass";
> $map{"blue"} = "ocean";
> print "A string please: "; chomp ($some_string = );
> print "The value for $some_string is $map($some_string)\n";
> 
> When I run it though I get the following complaint from perl:
> 
> A string please: blue
> Use of uninitialized value in concatenation (.) at ./key3.pl line 6, 
> line 1.
> The value for blue is (blue)


In line 6, it's $map{$some_string} not $map($some_string).

Regards,
-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




regular expression to get a file extension

2002-04-08 Thread Ahmed Moustafa

I had the following regular expression to get the extension from a file 
name:


$extension = $filename;
$extension =~ s/(^.+\.)([^\.]+)$/$2/;


But it didn't work (in case the $filename didn't have an extension); so 
I had to add the following line:


$extension = "" if (!$1);


What is wrong with my regular expression?
How can it be done in a single regular expression?

-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: regular expression to get a file extension

2002-04-09 Thread Ahmed Moustafa

Jeff, thanks a lot for your explanation. I really appreciate it.

Jeff 'Japhy' Pinyan wrote:
> Please use File::Basename.  Save us all the headache.

I was thinking that avoiding modules would make the code more portable. 
Am I right?


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




Re: regular expression to get a file extension

2002-04-09 Thread Ahmed Moustafa

John W. Krahn wrote:
> Ahmed Moustafa wrote:
> 
>>Jeff, thanks a lot for your explanation. I really appreciate it.
>>
>>Jeff 'Japhy' Pinyan wrote:
>>
>>>Please use File::Basename.  Save us all the headache.
>>>
>>I was thinking that avoiding modules would make the code more portable.
>>Am I right?
>>
> 
> No, _using_ modules would make the code more portable.

How, please? Using a module requires this module to be installed, 
doesn't it?


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




(-e $filename) gives Use of uninitialized value at...

2002-04-10 Thread Ahmed Moustafa

I'm using (-e $filename) to check the existence of $filename. If the file
exists, it returns true, otherwise it gives 'Use of uninitialized value
at...line #' (# is the line number of the if statement -if ($filename)-. Why
does that happen and how I can fix it, please?

Thanks in advance.

--Ahmed


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




Re: (-e $filename) gives Use of uninitialized value at...

2002-04-10 Thread Ahmed Moustafa

What is the default scope for a variable defined inside a subroutine?

- Original Message -
From: "Nikola Janceski"
To: "'Agustin Rivera'"; "Ahmed Moustafa"; <[EMAIL PROTECTED]>
Sent: Wednesday, April 10, 2002 10:19 AM
Subject: RE: (-e $filename) gives Use of uninitialized value at...


> Assuming you have all warnings on, via -w or use warnings, I don't think
> $filename is losing scope, unless he uses it else where.
>
> The warning is good, it's telling  you that $filename = "" at that point
in
> your script. So either you lost the contents of $filename somewhere, or
lost
> scope of the $filename with content you wanted, or you reassigned it to
"".
> Either way you shouldn't be doing (-e ""); which is happening at that
point.
>
> > -Original Message-----
> > From: Agustin Rivera [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, April 10, 2002 1:12 PM
> > To: Ahmed Moustafa; [EMAIL PROTECTED]
> > Subject: Re: (-e $filename) gives Use of uninitialized value at...
> >
> >
> > Seems like the method you use to assign filename doesn't always occur.
> > Maybe you have the my $filename='whatever' in an if statement?
> >
> > Agustin Rivera
> > Webmaster, Pollstar.com
> > http://www.pollstar.com
> >
> >
> >
> > - Original Message -
> > From: "Ahmed Moustafa"
> > To: "Perl" <[EMAIL PROTECTED]>
> > Sent: Wednesday, April 10, 2002 10:02 AM
> > Subject: (-e $filename) gives Use of uninitialized value at...
> >
> >
> > > I'm using (-e $filename) to check the existence of
> > $filename. If the file
> > > exists, it returns true, otherwise it gives 'Use of
> > uninitialized value
> > > at...line #' (# is the line number of the if statement -if
> > ($filename)-.
> > Why
> > > does that happen and how I can fix it, please?
> > >
> > > Thanks in advance.
> > >
> > > --Ahmed


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




Re: (-e $filename) gives Use of uninitialized value at...

2002-04-10 Thread Ahmed Moustafa

I put a print statement, just before the (-e $filename) line, to print the
$filename. It printed the $filename successfully and didn't give the
'uninitialized' warning for the print line.

- Original Message -
From: "Nikola Janceski" <[EMAIL PROTECTED]>
To: "'Agustin Rivera'" <[EMAIL PROTECTED]>; "Ahmed Moustafa"
<[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, April 10, 2002 10:19 AM
Subject: RE: (-e $filename) gives Use of uninitialized value at...


> Assuming you have all warnings on, via -w or use warnings, I don't think
> $filename is losing scope, unless he uses it else where.
>
> The warning is good, it's telling  you that $filename = "" at that point
in
> your script. So either you lost the contents of $filename somewhere, or
lost
> scope of the $filename with content you wanted, or you reassigned it to
"".
> Either way you shouldn't be doing (-e ""); which is happening at that
point.
>
> > -Original Message-
> > From: Agustin Rivera [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, April 10, 2002 1:12 PM
> > To: Ahmed Moustafa; [EMAIL PROTECTED]
> > Subject: Re: (-e $filename) gives Use of uninitialized value at...
> >
> >
> > Seems like the method you use to assign filename doesn't always occur.
> > Maybe you have the my $filename='whatever' in an if statement?
> >
> > Agustin Rivera
> > Webmaster, Pollstar.com
> > http://www.pollstar.com
> >
> >
> >
> > - Original Message -
> > From: "Ahmed Moustafa" <[EMAIL PROTECTED]>
> > To: "Perl" <[EMAIL PROTECTED]>
> > Sent: Wednesday, April 10, 2002 10:02 AM
> > Subject: (-e $filename) gives Use of uninitialized value at...
> >
> >
> > > I'm using (-e $filename) to check the existence of
> > $filename. If the file
> > > exists, it returns true, otherwise it gives 'Use of
> > uninitialized value
> > > at...line #' (# is the line number of the if statement -if
> > ($filename)-.
> > Why
> > > does that happen and how I can fix it, please?
> > >
> > > Thanks in advance.
> > >
> > > --Ahmed


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




Re: regular expression to get a file extension

2002-04-11 Thread Ahmed Moustafa

>   # foo.txt.bak => bak
>   ($extension) = $name =~ /.*\.([^.]*)/;
>   # or
>   # ($extension) = $name =~ /\.([^.]*)$/;

It doesn't work if there is no extension in $name.


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




what is the value of WNOHANG?

2002-04-12 Thread Ahmed Moustafa


waitpid $pid,&WNOHANG;


What is the value of the flag WNOHANG in waitpid?
What does it mean when $pid is -1?

Thanks in advance.
-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: what is the value of WNOHANG?

2002-04-12 Thread Ahmed Moustafa

I found it in . It was 0x0001.

Is use POSIX ":sys_wait_h"; portable?


Ahmed Moustafa wrote:
> 
> waitpid $pid,&WNOHANG;
> 
> 
> What is the value of the flag WNOHANG in waitpid?
> What does it mean when $pid is -1?
> 
> Thanks in advance.


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




Re: what is the value of WNOHANG?

2002-04-13 Thread Ahmed Moustafa

Paul Johnson wrote:
>>Is use POSIX ":sys_wait_h"; portable?
>>
> 
> It is on systems that support it.

It looks like it won't on the Windows systems, right?

> 
>>>What does it mean when $pid is -1?
>>>
> 
> It means wait for any child process.

Then, the pid's of the child processes don't need to be held to be 
waited for.

-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: Scope of my() declared variables WAS( Re: -e $filename...)

2002-04-13 Thread Ahmed Moustafa

Elaine -Hfb- Ashton wrote:
> I always found the local, my, our mess pretty confusing and the best
> explanation is MJD's "Coping with Scoping"
> 
> http://perl.plover.com/FAQs/Namespaces.html
> 
> Make good note of the text in red :)

Elaine, thanks a lot for MJD's article. There is a great difference 
before reading it and after :)

In the example:


{ my $seed = 1;
sub my_rand {
$seed = int(($seed * 1103515245 + 12345) / 65536) % 32768;
return $seed;
}
}


, the function my_rand () is declared inside a block. Does that mean a 
function can be declared anywhere in the program (i.e. inside another 
function, loop or if block)?


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




Re: (-e $filename) gives Use of uninitialized value at...

2002-04-13 Thread Ahmed Moustafa

Jeff 'Japhy' Pinyan wrote:
> The default scope for ALL variables is to the package they belong to.  If
> you declare a variable with 'my', or give it a fully qualified package
> name (like $Foo::x), then the default is not the case.

I found the same for subroutines, right?
-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




How can a sub return true or value?

2002-04-13 Thread Ahmed Moustafa

I use " " for true and "" for false. Is there a more standard (or 
readable) values for true and false?

Thanks in advance.

-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: How can a sub return true or false?

2002-04-13 Thread Ahmed Moustafa

Ahmed Moustafa wrote:
> I use " " for true and "" for false. Is there a more standard (or 
> readable) values for true and false?
> 
> Thanks in advance.


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




Re: How can a sub return true or false?

2002-04-14 Thread Ahmed Moustafa

Steven Brooks wrote:
> You could use 0 as false and 1 (or another non-zero value) as true.

Why does an empty string work as 0 (false)?


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




Re: How to thread in Perl?

2002-04-15 Thread Ahmed Moustafa

> #reap the children to avoid zombies
> waitpid $_ for (@children); 

Do I need to pop the pid's from the stack children?

Thanks,

Ahmed


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




Re: How to thread in Perl?

2002-04-15 Thread Ahmed Moustafa

> You are better off trying
>
> $SIG{CHLD} = 'IGNORE';
>
> at the top of your program and seeing if zombies are left out there.

There were no zombies left after the program termination. Then, I don't need
even to push the ids from the children in the stack, right?

> Missile Address: 33:48:3.521N  84:23:34.786W

By the way, what is the Missile Address?


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




Re: How to thread in Perl?

2002-04-15 Thread Ahmed Moustafa

> > You are better off trying
> >
> > $SIG{CHLD} = 'IGNORE';
> >
> > at the top of your program and seeing if zombies are left out there.
>
> There were no zombies left after the program termination. Then, I don't
need
> even to push the ids from the children in the stack, right?

Something happened when I tried $SIG{CHLD} = 'IGNORE';
I don't know if it's a related or not.
When a child is forked, it calls an Java program through system(), it used
to return 0 but with $SIG{CHLD} = 'IGNORE'; it returns -1.
I know that Java application exits normally (exit code = 0).
Does that make sense?

Thanks,

Ahmed



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




Net::SFTP installation on Windows

2002-04-16 Thread Ahmed Moustafa

How can I install Net::SSH and Net::SFTP on ActivePerl (Windows NT), please?

Your help will be appreciated so much.

Thanks,

Ahmed


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




Re: OT: Old uunet gag was Re: How to thread in Perl?

2002-04-16 Thread Ahmed Moustafa

Is there a way to know the Missile Address from an IP address?
--
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: How to thread in Perl?

2002-04-17 Thread Ahmed Moustafa

> You are better off trying
>
> $SIG{CHLD} = 'IGNORE';
>
> at the top of your program and seeing if zombies are left out there.  If
> so then you might want to use pop or shift like this
>
> waitpid shift @children while @children;

Do I really need to hold the pid's of the kids process somewhere?
Can't I do something like that my $forked =  fork; waitpid $forked,
&WNOHANG;?
What do you think?

Thanks,

Ahmed


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




Re: How to thread in Perl?

2002-04-18 Thread Ahmed Moustafa

Chas,

Thanks a lot!

> #the main loop has exited, so we should check to see if there are
> #any unreaped children
> waitpid $_ for keys %running;

My main loop is iterating forever i.e. a daemon; thus, any code after the
main loop will not be executed. So, what do you think?

Once again, thanks.

Ahmed


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




Re: How to thread in Perl?

2002-04-19 Thread Ahmed Moustafa

Chas Owens wrote:
> my $terminate = 0;
> $SIG{TERM} = sub { $terminate = 1 };
> until ($terminate) {
>   #do stuff
> }
> 
> #cleanup
> 
> 
> You should definitely provide some means of cleanly bring down your
> daemon.

Cleaning up is application specific, isn't? Or, is there a standard 
procedure?

How can a child process be forced to be killed (in the cleaning up)?

-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




synchronized block

2002-04-22 Thread Ahmed Moustafa

How a block of code is atomized (e.g. synchronized blocks in Java)?

Thanks in advance.

-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: Windows IDE for Perl ?

2002-04-22 Thread Ahmed Moustafa

Peter Lang wrote:
> Hi All,
> 
> Are there MS Windows based IDE for Perl, with debug and
> trace / step thru facilities, free or otherwise?
> 
> Thanks
> Peter

Take a look at Visual Perl 



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




Re: Standalone exe's

2002-04-22 Thread Ahmed Moustafa

Peter Lang wrote:
> Hi All,
> 
> This is a newbie question. Can you generate a stand alone
> ..exe file from Perl?
> 
> Thanks
> Peter

Perl2Exe <http://www.indigostar.com/perl2exe.htm>

-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: Unix to dos; dos to unix...

2002-04-25 Thread Ahmed Moustafa

Ron Powell wrote:
> There is a utility out there that will convert unix-style end-of-lines (LF)
> to dos-style (CR/LF)...
> 
> Just for giggles, I'm trying to write a perl script to do this...
> 
> Here's what I've tried...
> 
> while () {
>   $line = $_;
>   $line=~tr/\012/\015\012/;
>   print OUTFILE ("$line\n");
>   }
> 
> The problem is that the output, when viewed with notepad, contains
> inappropriate line breaks...
> 
> The same input file, when converted using the unix utility unix2dos,
> converts "properly."  This leads me to believe that I'm missing something
> obvious here
> 
> I'm not asking for the answer per se, but perhaps a pointer? 
> 
> --
> Ron Powell
> Senior IT Analyst &
> Network Administrator
> gomembers, Inc. (Baltimore Office)
> [EMAIL PROTECTED]
> 410-494-1600 x4058
>  <<...OLE_Obj...>> 

If your file is already in the DOS file format (each line ends with CR 
and LF), your script will replace the LF with CR and LF; which means 
your lines will end with CR + CR + LF. And, that's why they had 
inappropriate line breaks.

--
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: OpenInteract and others

2002-04-25 Thread Ahmed Moustafa

There is Open Architecture Community System (OpenACS) 
<http://www.openacs.org>. It is a well engineered Tcl/AOLServer-based 
framework. It uses PostgreSQL or Oracle. I think they made it to work 
with Apache. I don't know about mod_perl but there are a lot of 
discussions about Perl there at 
http://openacs.org/bboard/search-entire-system.tcl?query_string=perl
-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: Net::SFTP installation on Windows

2002-04-25 Thread Ahmed Moustafa

Ahmed Moustafa wrote:
> How can I install Net::SSH and Net::SFTP on ActivePerl (Windows NT), please?

Has anyone had Net:SFTP working on Windows?


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




Send email with attachment

2002-04-28 Thread Ahmed Moustafa

Hi All,

Would you post an example of sending an email with attachment(s) using 
Net::SMTP, please?

Thanks in advance.

Ahmed


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




Re: Send email with attachment

2002-04-29 Thread Ahmed Moustafa

Bob Showalter wrote:
>>-Original Message-
>>From: Ahmed Moustafa
>>Sent: Sunday, April 28, 2002 2:47 PM
>>To: [EMAIL PROTECTED]
>>Subject: Send email with attachment
>>
>>
>>Hi All,
>>
>>Would you post an example of sending an email with 
>>attachment(s) using 
>>Net::SMTP, please?
>>
> 
> Net::SMTP just sends messages. To handle attachments, you should use
> something like MIME::Lite to create a MIME message. You can then send
> it with Net::SMTP, or MIME::Lite can send it for you.

Thanks a lot!


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




Re: Perl and Visual Basic

2002-05-03 Thread Ahmed Moustafa

[EMAIL PROTECTED] wrote:
> Good day;

Hello,

> I have developed some useful Perl scripts.. Users want a VB front-end 
> to run these scripts.
> What do I need to do, such that something like this could work (i.e.: 
> User presses a command button, which then launches a Perl script- data 
> sent to output files, etc..)

There is the VB's *Shell* function which let's you call an external 
executable program (including the Perl interperter).

-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: Global variables in forked processes

2002-05-09 Thread Ahmed Moustafa

Thanks a lot. I understand that.

I was thinking that variable 'x' of a forked process 'p2' would point at 
the same memory location of variable 'x' of a parent process 'p1'. That 
can't be true. If that was true, 'p1' and 'p2' would be identitcal (no 
need to fork!).

-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: accessing an array in a hash

2002-05-12 Thread Ahmed Moustafa

Roee Moked wrote:
> Hi,
> How do I access a field in an array that is a field of a hash?
> ex:
> %hash
> $hash[1] =@array1
> $hash[2] =@array2
> .
> 
> no I want to change $array2[6] via the hash.
> 
> Thanks
> Roee M.

%hash = (array => ['hello', 'world']);
print $hash{"array"}[0];
print $hash{"array"}[1];

-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




How does ZOMBIE/defunct affect the system?

2002-08-09 Thread Ahmed Moustafa

If a Perl program generates ZOMBIE/defunct processes, how does that 
affect the system?

Do the following code avoid the ZOMBIE/defunct?

# 
do {
$pid = waitpid (-1, &WNOHANG);
} until $pid == -1;
# 


Your help will be appreciated so much.

-- 
Ahmed Moustafa


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




Re: How does ZOMBIE/defunct affect the system?

2002-08-10 Thread Ahmed Moustafa

Drieux wrote:
> 
> 
>use POSIX ":sys_wait_h";
>#...
>do {
>$kid = waitpid(-1,&WNOHANG);
>} until $kid == -1;

Does the execution of the program wait to all the forked processes to 
terminate?

Thanks!!!

-- 
Ahmed Moustafa


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




Re: How does ZOMBIE/defunct affect the system?

2002-08-12 Thread Ahmed Moustafa

Drieux wrote:
> what you want is
> 
> how do I create a demon process
> 
> that will be able to run independent of my programme:
> 
> cf:
> 
> http://www.wetware.com/drieux/pbl/Sys/daemon1.txt

If it's not possible to use Proc::Daemon, what would be the other 
options, please?

Your help will appreciated so much.

--Ahmed Moustafa


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




Re: How does ZOMBIE/defunct affect the system?

2002-08-13 Thread Ahmed Moustafa

Drieux wrote:
> 
> On Monday, August 12, 2002, at 11:31 , Ahmed Moustafa wrote:
> 
>> Drieux wrote:
>>
>>> what you want is
>>> how do I create a demon process
>>> that will be able to run independent of my programme:
>>> cf:
>>> http://www.wetware.com/drieux/pbl/Sys/daemon1.txt
>>
>>
>> If it's not possible to use Proc::Daemon, what would be the other 
>> options,
>>  please?
> 
> 
> do what you will need to do to daemonize -
> reset STDIN/STDOUT/STDERR to other FD - in
> the above case I reset them to a unique log,
> then it is time to do a 'double fork' of the
> process into the background - making sure to
> set the session id enroute.... That normally
> makes sure that one is no longer attached to
> a controlling TTY...

Could you give a sample code, please?

--Ahmed Moustafa


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




Re: How does ZOMBIE/defunct affect the system?

2002-08-13 Thread Ahmed Moustafa

> Proc::Daemon is a pure Perl module, so it is a perfect Perl example of
> how to create a daemon in Unix.  Is there a particular reason you cannot
> use Proc::Daemon (uncooperative sysadmins)? 

Exactly, also, I already have something in place and I need to fix it.


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




system() retuens -1

2002-08-13 Thread Ahmed Moustafa

I call external programs with system(). It used to return the correct value
i.e. zero if there is no error and a non-zero value otherwise. Recently, it
always returns -1 even if the external programs work fine. What could be the
reason?

Thanks in advance,

Ahmed


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




Re: How does ZOMBIE/defunct affect the system?

2002-08-13 Thread Ahmed Moustafa

Ahmed Moustafa wrote:
> Drieux wrote:
> 
>>
>>
>>use POSIX ":sys_wait_h";
>>#...
>>do {
>>$kid = waitpid(-1,&WNOHANG);
>>} until $kid == -1;
> 
> 
> Does the execution of the program wait to all the forked processes to 
> terminate?

Perl Cookbook says "We use the WNOHANG flag to make waitpid immediately 
return 0 if there are no dead children".

So, the above code doesn't pause the program, does it?


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




Re: system() retuens -1

2002-08-14 Thread Ahmed Moustafa

> > I call external programs with system(). It used to return the correct
> > value i.e. zero if there is no error and a non-zero value otherwise.
> > Recently, it always returns -1 even if the external programs work fine.
> > What could be the reason?
>
>
> From perldoc -f system:
>
> The return value is the exit status of the program
> as returned by the "wait" call.  To get the actual
> exit value divide by 256.  See also "exec".  This
> is not what you want to use to capture the output
> from a command, for that you should use merely
> backticks or "qx//", as described in "`STRING`" in
> perlop.  Return value of -1 indicates a failure to
> start the program (inspect $! for the reason).
>
>
> So apparently the call to the external program is not working fine.
Surely
> you don't think perl is incorrect.

$! says 'No child processes'. Does that have something to do with having
$SIG{CHLD} = 'IGNORE';
in the code?

Thanks,

--Ahmed


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




Re: How does ZOMBIE/defunct affect the system?

2002-08-14 Thread Ahmed Moustafa


- Original Message -
From: "Bob Showalter" <[EMAIL PROTECTED]>
To: "'Sudarshan Raghavan'" <[EMAIL PROTECTED]>; "Perl beginners"
<[EMAIL PROTECTED]>
Sent: Wednesday, August 14, 2002 5:45 AM
Subject: RE: How does ZOMBIE/defunct affect the system?


> > -Original Message-
> > From: Sudarshan Raghavan [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, August 14, 2002 7:49 AM
> > To: Perl beginners
> > Subject: Re: How does ZOMBIE/defunct affect the system?
> >
> >
> > On Tue, 13 Aug 2002, Ahmed Moustafa wrote:
> >
> > > Ahmed Moustafa wrote:
> > > > Drieux wrote:
> > > >
> > > >>
> > > >>
> > > >>use POSIX ":sys_wait_h";
> > > >>#...
> > > >>do {
> > > >>$kid = waitpid(-1,&WNOHANG);
> > > >>} until $kid == -1;
> > > >
> > > >
> > > > Does the execution of the program wait to all the forked
> > processes to
> > > > terminate?
> > >
> > > Perl Cookbook says "We use the WNOHANG flag to make waitpid
> > immediately
> > > return 0 if there are no dead children".
> >
> > Yes WNOHANG makes waitpid return immediately the -1 means wait for any
> > child process. This code will do a non-blocking wait for all child
> > processes.
> >
> > >
> > > So, the above code doesn't pause the program, does it?
> >
> > It will be in the do-until loop until all of it's children are dead.
> > perldoc -f waitpid
>
> This example is straight out of perldoc -f waitpid, but if it's
> used "as-is", I don't see the point. Why do a non-blocking wait,
> when the do loop effectively blocks the program anyway. You only
> want non-blocking when you have something else to do.
> I would write the above as:
>
>1 while wait != -1; # wait for all children
>
> Or am I missing something?

All I need to do is to reap the dead processes without blocking the program.
(Also I don't want to ignore the children with using $SIG{CHLD} =
'IGNORE';).


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




Re: How does ZOMBIE/defunct affect the system?

2002-08-14 Thread Ahmed Moustafa


- Original Message -
From: "Bob Showalter" <[EMAIL PROTECTED]>
To: "'Ahmed Moustafa'" <[EMAIL PROTECTED]>; "Perl beginners"
<[EMAIL PROTECTED]>
Sent: Wednesday, August 14, 2002 10:08 AM
Subject: RE: How does ZOMBIE/defunct affect the system?


> > -Original Message-
> > From: Ahmed Moustafa [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, August 14, 2002 11:45 AM
> > To: Bob Showalter; 'Sudarshan Raghavan'; Perl beginners
> > Subject: Re: How does ZOMBIE/defunct affect the system?
> >
> > ...
> > All I need to do is to reap the dead processes without
> > blocking the program.
> > (Also I don't want to ignore the children with using $SIG{CHLD} =
> > 'IGNORE';).
> >
>
> Then you should call wait() inside a SIGCHLD handler. That's
> what SIGCHLD is for. See the examples in perldoc perlipc.

When I put something in the SIGCHLD handler, the calls to system() return
'No child processes'!


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




Re: How to know a file is being processed?

2001-11-29 Thread Ahmed Moustafa

If I try to lock a file while it is still being transferred, would that 
cause an error? If so, then I can I know the file is still being processed.

What do you think, please?

Thanks,

Ahmed


Randal L. Schwartz wrote:

>>>>>>"Ahmed" == Ahmed Moustafa Ibrahim Ahmed <[EMAIL PROTECTED]> writes:
>>>>>>
> 
> Ahmed> My script should be waiting for the incoming files and encrypts them as
> Ahmed> soon as the transmission is completed. Using "lsof" makes a gap between
> Ahmed> the arrival of the files and their encryption.
> 
> Ahmed> Is there any other way to know that a file is being FTPed, specifically?
> 
> The traditional safe way is to have the sender first upload the file
> with a "temporary" extension or prefix, then do a remote-rename to a
> final valid name when the upload is complete.  If you can't control
> the sender, then you are hosed.


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




Can Perl work like Expect?

2001-12-03 Thread Ahmed Moustafa

Hi All,

I used to use Expect http://expect.nist.gov/ for dealing with 
interactive programs i.e. Telnet and FTP.

Expect lets you interact with running process as if it was a file.

Does Perl have something like that i.e. writing a Perl script which 
interacts with another process?

Your help will be appreciated so much.

Ahmed
-- 
Ahmed Moustafa
[EMAIL PROTECTED] | http://arbornet.org/~ahmed


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




Re: Can Perl work like Expect?

2001-12-03 Thread Ahmed Moustafa

Hi Brett,

Thanks a lot. Where can I find exmaples for using Expect.pm, please?

Brett W. McCoy wrote:

> On Mon, 3 Dec 2001, Ahmed Moustafa wrote:
> 
> 
>>I used to use Expect http://expect.nist.gov/ for dealing with
>>interactive programs i.e. Telnet and FTP.
>>
>>Expect lets you interact with running process as if it was a file.
>>
>>Does Perl have something like that i.e. writing a Perl script which
>>interacts with another process?
>>
>>Your help will be appreciated so much.
>>
> 
> Yep -- there's a module on CPAN called Expect.pm.  It works as you would
> expect. :-)
> 
> -- Brett
>   http://www.chapelperilous.net/
> --------
> Violence is a sword that has no handle -- you have to hold the blade.

-- 
Ahmed Moustafa
[EMAIL PROTECTED] | http://arbornet.org/~ahmed


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




Re: Can Perl work like Expect?

2001-12-04 Thread Ahmed Moustafa

Actually, I need to interact with a Secure FTP (SFTP) client. Is there 
some module for that?

By the way, Are these modules installed by default on the Perl 
distributions? Or, how can I tell if a module is installed or not?

Thanks,

Maxim Berlin wrote:

> Hello Ahmed,
> 
> Tuesday, December 04, 2001, Ahmed Moustafa <[EMAIL PROTECTED]> wrote:
> 
> AM> Thanks a lot. Where can I find exmaples for using Expect.pm, please?
> 
> http://search.cpan.org/search?mode=module&query=expect
> but, for telnet and ftp you can use Net::Telnet and Net::FTP modules.
> http://search.cpan.org/doc/JROGERS/Net-Telnet-3.02/lib/Net/Telnet.pm
> http://search.cpan.org/doc/GBARR/libnet-1.09/Net/FTP.pm
> 
> AM> Brett W. McCoy wrote:
> 
> 
>>>>I used to use Expect http://expect.nist.gov/ for dealing with
>>>>interactive programs i.e. Telnet and FTP.
>>>>
>>>>Expect lets you interact with running process as if it was a file.
>>>>
>>>>Does Perl have something like that i.e. writing a Perl script which
>>>>interacts with another process?
>>>>
>>>>Your help will be appreciated so much.
>>>>
>>>>
>>>Yep -- there's a module on CPAN called Expect.pm.  It works as you would
>>>expect. :-)
>>>
> 
> 
> 
> Best wishes,
>  Maximmailto:[EMAIL PROTECTED]

-- 
Ahmed Moustafa
[EMAIL PROTECTED] | http://arbornet.org/~ahmed


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




Net:SFTP license and security

2001-12-04 Thread Ahmed Moustafa

Hi All,
I need documents describing the license of using Net:SFTP
http://search.cpan.org/search?dist=Net-SFTP also the security issues of it
i.e is the connection between the client and the server is *really*
encrypted?
Your help will be appreciated so much.
--Ahmed Moustafa
[EMAIL PROTECTED] | http://arbornet.org/~ahmed


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




Re: Simpler....

2001-12-04 Thread Ahmed Moustafa

Dan, does sub() changes the value of $status? Also, do sub() and sub2() 
break the loop?

Daniel Falkenberg wrote:

> Hey all,
> 
> Please don't stree to much over this one but, is there an easier way of
> writing this?
> 
> while(1){
>   if ($status == 1) {
> #Do this sub...
> sub();
>   elsif ($status == 1) {
> #Do this other sub...
> sub2();
>   } else {
> #Continue while loop...
>   }
> }
> 
> Can I make it smaller.  I want to know this to improve my Perl skills.
> 
> Regards,
> 
> Dan

-- 
Ahmed
[EMAIL PROTECTED] | http://arbornet.org/~ahmed


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




Re: Simpler....

2001-12-04 Thread Ahmed Moustafa

Dan,

What do you think about the following?

while (1) {
if ($status ==1) {
sub();
last;
}
if ($status ==1) {
sub1();
last;
}
}

Regards,

Ahmed

Daniel Falkenberg wrote:

>Ahmed,
>
>For arguments sake we will say yes!  So I presume I will do sub($status)
>?  Also we will say that sub() does break the loop but will return where
>it left off   after the sub sub() and sub2() has finished what it is
>doing?
>
>Cheers,
>
>Dan
>
>-----Original Message-
>From: Ahmed Moustafa [mailto:[EMAIL PROTECTED]]
>Sent: Wednesday, 5 December 2001 3:27 PM
>To: Daniel Falkenberg
>Cc: [EMAIL PROTECTED]
>Subject: Re: Simpler
>
>
>Dan, does sub() changes the value of $status? Also, do sub() and sub2() 
>break the loop?
>
>Daniel Falkenberg wrote:
>
>>Hey all,
>>
>>Please don't stree to much over this one but, is there an easier way
>>
>of
>
>>writing this?
>>
>>while(1){
>>  if ($status == 1) {
>>#Do this sub...
>>sub();
>>  elsif ($status == 1) {
>>#Do this other sub...
>>sub2();
>>  } else {
>>#Continue while loop...
>>  }
>>}
>>
>>Can I make it smaller.  I want to know this to improve my Perl skills.
>>
>>Regards,
>>
>>Dan
>>
>

-- 
Ahmed
[EMAIL PROTECTED] | http://arbornet.org/~ahmed





Re: Loop

2001-12-05 Thread Ahmed Moustafa

Try using "last" instead of "break".

- Original Message -
From: "Purshottam Chandak" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, December 05, 2001 7:19 AM
Subject: Loop


> i was trying to work it out, for any kind of array.
> the following pseudo code doesn't seem to work
>
> for(.) {
> if(...) {
> ..
> }
> else {
> 
> break;
> }
> }
>
> the break statement is not working. Even when it comes into  the else
part,
> it doesn't break the for loop.


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




Re: traversing Windows directories

2001-12-05 Thread Ahmed Moustafa

I think it does not matter it your system is Windows or *nix.

--Ahmed
[EMAIL PROTECTED] | http://arbornet.org/~ahmed

On Wed, 5 Dec 2001, Torres, Jose wrote:

> Hi,
> 
> How do you traverse Windows directories in Perl? Let's say J:\foo\bar\logs
> has a variable number of folders, each of which I want to look into for a
> specific file. How would I do this? Thanks for all help.
> 
> 
> -Jose
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


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




Re: traversing Windows directories

2001-12-05 Thread Ahmed Moustafa

You need to write a recursive function to scan your root dir and list all
the file and directories and do the same for each one of the sub
directories. Once you find the file you are looking for, return.

--Ahmed
[EMAIL PROTECTED] | http://arbornet.org/~ahmed

On Wed, 5 Dec 2001, Torres, Jose wrote:

> Hi,
> 
> How do you traverse Windows directories in Perl? Let's say J:\foo\bar\logs
> has a variable number of folders, each of which I want to look into for a
> specific file. How would I do this? Thanks for all help.
> 
> 
> -Jose
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


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




RE: perl script to remove control M's

2001-12-05 Thread Ahmed Moustafa

This programs exists for Windows also.

--Ahmed
[EMAIL PROTECTED] | http://arbornet.org/~ahmed

On Wed, 5 Dec 2001, Sidharth Malhotra wrote:

> Most unix systems have a program called dos2unix that does the same
> thing.
> % man dos2unix
> % dos2unix sourcefile targetfile
> 
> Hth.  Sid.
> 
> -Original Message-
> From: Chris Spurgeon [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, December 05, 2001 5:41 PM
> To: 'Booher Timothy B 1stLt AFRL/MNAC'; [EMAIL PROTECTED]
> Subject: RE: perl script to remove control M's
> 
> 
> perl -i.bak -npe 's/\r\n/\n/g' 
> 
> where  is the filename you want to clean.
> A backup copy of your original file will be created in the same
> directory with a ".bak" extension.
> 
> 
> Chris Spurgeon
> Senior Design Technologist
> [EMAIL PROTECTED]
> 
> ELECTRONIC INK
> One South Broad Street
> 19th Floor
> Philadelphia, PA 19107
> www.electronicink.com
> 
> t 215.922.3800 x(233)
> f 215.922.3880
> 
> 
> -Original Message-
> From: Booher Timothy B 1stLt AFRL/MNAC
> [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 05, 2001 5:32 PM
> To: [EMAIL PROTECTED]
> Subject: perl script to remove control M's
> 
> 
> 
> I have what seems to be a persistent problem with all files that I
> import from dos into emacs. I have those control M's all over the place.
> 
> Does anyone know of a perl script to 'clean' these files?
> 
> Thanks so much,
> 
> tim
> 
> Timothy B Booher, Lt USAF, AFRL/MNAC
> 101 West Eglin Blvd, Suite 339 
> Eglin AFB FL 32542-6810 
> Phone: 850-882-8302 Ext. 3360 (DSN 872-)
> FAX: 850-882-2201
> 
> This e-mail is intended solely for the above-mentioned recipient and it
> may contain confidential or privileged information.  If you have
> received it in error, please notify us immediately and delete the
> e-mail.  You must not copy, distribute, disclose or take any action in
> reliance on it.  In addition, the contents of an attachment to this
> e-mail may contain software viruses which could damage your own computer
> system.  While Electronic Ink, Inc. has taken every reasonable
> precaution to minimize this risk, we cannot accept liability for any
> damage which you sustain as a result of software viruses.  You should
> perform your own virus checks before opening the attachment.
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


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




RE: Confirmation...

2001-12-06 Thread Ahmed Moustafa

Hi Messier,

Try that:

#[1]
$str="206.48.16.3/12345";
$str=~ s/\/.*//g;

#[2]
$str="src=206.48.16.3/12345";
$str=~ s/^src=|\/.*//g;


I hope that helps.

--Ahmed
[EMAIL PROTECTED] | http://arbornet.org/~ahmed

On Thu, 6 Dec 2001, Messier, Jean-Francois wrote:

>   I'm a beginner in those regular expressions and s/// operations. How
> can I extract only the digits and the periods (.) from a string ? I have
> something like 206.48.16.3/12345. An IP address with a port number. There
> are digits on both sides of the slash, but I would like to keep only the
> digits from on the left as well as the periods. More complex question: If I
> have something like "src=206.48.16.3/12345", how can I do the same as bove,
> but also removing the "src=" at the beginning ?
> 
>   Thanks :-)
> 
> Jean-Francois Messier
> Ottawa, CANADA
> 
> -Original Message-
> From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 05, 2001 11:18 PM
> To: Daniel Falkenberg
> Cc: [EMAIL PROTECTED]
> Subject: Re: Confirmation...
> 
> 
> On Dec 6, Daniel Falkenberg said:
> 
> >$string =~ s/[^a-zA-Z0-9]//g;
> >
> >I take it only allows $string to eq anthing in the charcter class of
> >a-z, A-Z and 0-9.  I also take it that anything other than that will be
> >stripped out?  Any other comments?
> 
> Right.  I'd write it as
> 
>   s/[^a-zA-Z0-9]+//g;
> 
> for "efficiency".  Or perhaps as
> 
>   tr/a-zA-Z0-9//cd;
> 
> for "clarity".  Your ideas of "efficiency" and "clarity" may differ.
> 
> -- 
> Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
> RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
> ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
>  what does y/// stand for?   why, yansliterate of course.
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


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




Re: Is A File Encrypted?

2001-12-06 Thread Ahmed Moustafa

If you expect a certian pattern of text in the file, I think, you
can grep the file from the expected text pattern. If you find any, then
the file is not encrypted; otherwise, the probability of the file being
encrypted would be higher.

--Ahmed
[EMAIL PROTECTED] | http://arbornet.org/~ahmed

On Thu, 6 Dec 2001, Ray Murphy wrote:

> Hello,
> 
> Want to make sure I'm not missing anything here.  My
> task is to see if a file looks like it's encrypted. 
> I'm splitting the path/filename/extension via
> File::Basename and checking to see if the extension is
> ..pgp or .gpg.  I'm also checking to see if the file is
> a text file via 'if (-T $file)'.  Is there any other
> (better) way of testing to see if a file is encrypted?
>  I don't want to call the decryption routines if the
> file is not encrypted.
> 
> Cheers
> 
> Ray.
> 
> __
> Do You Yahoo!?
> Send your FREE holiday greetings online!
> http://greetings.yahoo.com
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


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




Re: Restarting a daemon...

2001-12-06 Thread Ahmed Moustafa

Hi Daniel,

I had the following code. I hope it would help.

# Before your while loop:
#---
open (PID, $pidfile) || die "Cannot $pidfile: $!\n";
while ( $pid =  ) {
system "kill -9 $pid";
}
close (PID);
open (PID, ">$pidfile") || die "Cannot $pidfile: $!\n";
print PID "$$\n" if (!$stop);
close PID;
exit (0) if ($stop);
#---

Regards,


Daniel Falkenberg wrote:

> Hi All,
> 
> I have a daemon here that runs in a while loop.  I was just wondering if
> it is possible to restart a perl daemon instead of doing the
> following...
> 
> %killall name_of_perl_daemon.pl
> 
> How would I go about doing something like...
> 
> service name_of_perl_daemon.pl restart
> 
> Can I do this with perl...?
> 
> Dan
> 
> ==
> VINTEK CONSULTING PTY LTD
> (ACN 088 825 209)
> Email:  [EMAIL PROTECTED]
> WWW:http://www.vintek.net
> Tel:(08) 8523 5035
> Fax:(08) 8523 2104
> Snail:  P.O. Box 312
> Gawler   SA   5118
> rm -rf /bin/laden
> ==

-- 
Ahmed
[EMAIL PROTECTED] | http://arbornet.org/~ahmed


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




Re: very basic newbie q: executing a script/dir permissions

2001-12-13 Thread Ahmed Moustafa

I think you should have something like the cgi-bin directory under the 
web server where your cgi script should be. It depends on your web 
server and how you configure it.

[EMAIL PROTECTED] wrote:

> Hello, 
> 
> Tried to be as descriptive as possible in my subject
> line. I have worked with perl off and on but now I am
> trying to build things from the ground up and I can't
> get my script to run from the browser. what are the
> persmissions that allow script to run for the file and
> the dir? Perl is in the same place (usr/bin/perl) as
> in the script. Perl is installed and runs the script
> from the command line, I checked that.
> 
> Thank you oh, gracious list.
> 
> jh
> 
> __
> Do You Yahoo!?
> Check out Yahoo! Shopping and Yahoo! Auctions for all of
> your unique holiday gifts! Buy at http://shopping.yahoo.com
> or bid at http://auctions.yahoo.com

-- 
Ahmed
[EMAIL PROTECTED] | http://arbornet.org/~ahmed


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




Re: Hash question...

2001-12-17 Thread Ahmed Moustafa

Hi Dan,

Try this:

# --
%flags=();
foreach $user ( keys (%popusers) ) {
if (-e "/home/$user/test.pl") {
$flags{$user} = "YES";
} else {
$flags{$user} = "NO";
}
}
# --

I hope that helps,

Ahmed

Daniel Falkenberg wrote:

> Hi All,
> 
> Just working on a new hash that I need some help with...
> 
> Firstly
> 
> I can create a hash like the following no problem
> 
> %popusers = (
> 'user1' => 'Fullname1',
> 'user2' => 'Fullname2',
> 'user3' => 'Fullname3',
> );
> 
> Foreach user i.e. (user1, user2 and user3) a home directory exists such
> as /home/user1/
> 
> Now I need my script to check each home dir. for a file of test.pl if
> the file exists then I need it to create the following hash with a
> YES for yes the file exists and NO if the file doesn't
> 
> %popusers_file = (
> 'user1' => 'YES',
> 'user2' => 'YES',
> 'user3' => 'NO',
> );
> 
> Would I start by doing something like the following...
> 
> foreach $user (keys %popusers) {
>   #Check each home dir /home/$user for file test.pl
>   #Begin new hash (%popusers_file)
> }
> 
> Is this the correct way of going about this one???
> 
> Regards,
> 
> Dan

-- 
Ahmed Moustafa
[EMAIL PROTECTED] | http://arbornet.org/~ahmed


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




Re: add text to the end of a word. HELP!!

2002-01-01 Thread Ahmed Moustafa

Can you open a file for reading and writing as the same time?

Leon wrote:

> There are many ways to do it. Some would use regexes or map. Anyway heres
> one solution assuming your file contain only 1 word in one line..
> 
> open FILE, 'yourfile.txt' or die "$!\n";
> while (){
>  chomp;
>  $_ = "$_\@minime.com";
>  print "$_\n";
> };
> close FILE;


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




Re: add text to the end of a word. HELP!!

2002-01-02 Thread Ahmed Moustafa

Leon,

I've tested reading and writing from the same file and it didn't work. I 
  think that can't be done in any language.

Leon wrote:

> - Original Message -----
> From: "Ahmed Moustafa" <[EMAIL PROTECTED]>
> Newsgroups: perl.beginners
> To: "Leon" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> 
>>Can you open a file for reading and writing as the same time?
>>
> 
> I have asked the question of can I read and write to the same file
> simultaneously, such as this :-
> open FILE, 'myfile.txt' or die "$!\n";
> open FILE2, '>myfile.txt' or die "$!\n";
> while (){
> # do some changes to $_;
> print FILE2 $_;
> };
> 
> but I did not get any response. Therefore I dont think we can do that.
> 
>  end of msg -


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




Hash of hash of array

2002-01-09 Thread Ahmed Moustafa

Hi All,

My data structure is a hash of a hash of an array. I build it from an 
input file by the following code. Could you help me write it back to an 
output file, please?

# Code Begins
%data = ( );
open (IN, "in.txt") || die;
while () {
  chop;
  ($user_name, $file_name, $modified_by, $last_modified) = split ( " ", 
$_ );
  $data{$user_name}{$file_name} = [$modified_by, $last_modified];
}
close (IN);
# Code Ends

Thanks a lot for your attention. Your help will be appreciated so much.

Ahmed


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




Re: Hash of hash of array

2002-01-09 Thread Ahmed Moustafa

Jon,thanks a lot for your help :)

Jon Molin wrote:

> Ahmed Moustafa wrote:
> 
>>Hi All,
>>
>>My data structure is a hash of a hash of an array. I build it from an
>>input file by the following code. Could you help me write it back to an
>>output file, please?
>>
>># Code Begins
>>%data = ( );
>>open (IN, "in.txt") || die;
>>while () {
>>  chop;
>>  ($user_name, $file_name, $modified_by, $last_modified) = split ( " ",
>>$_ );
>>  $data{$user_name}{$file_name} = [$modified_by, $last_modified];
>>}
>>close (IN);
>># Code Ends
>>
>>
> 
> the hash hasn't got arrays but arrayrefs in it, here are some ways to
> reach the values:
> 
> my $scalar = $data{user}{file1}->[0]; # get value 0 in the file1 array
> my @array = @{$data{user}{file1}}; # dereferens the array and put it in
> @array
> my $array_ptr = $data{user}{file1}; # get the arrayref and reach the
> values by $array_ptr->[nbr]
> 
> /Jon
> 
> 
> 
>>Thanks a lot for your attention. Your help will be appreciated so much.
>>
>>Ahmed
>>
>>--
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]


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




return code

2002-01-10 Thread Ahmed Moustafa

Hi All,

I'm calling a Java application using "system". How can I know the return 
code of the called Java application?

Your help will be appreciated so much.

Ahmed
--
[EMAIL PROTECTED] | http://www.photo.net/users/ahmed


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




Re: How do I delete a file from Perl?

2002-01-12 Thread Ahmed Moustafa

Randy,

You can delete a file, or a list of files, using "unlink". Example:
##
unlink $file;
##

perldoc -f unlink

Hope that helps.

Ahmed
[EMAIL PROTECTED] | http://www.photo.net/user/ahmed

Randolph S. Kahle wrote:

> I am writing my first perl program (copied from a magazine).
> 
> The only line that is not working is
> 
> system( rm -rf $file );
> 
> The error message is:
> 
> Can't call method "rm" with a package or object reference.
> 
> Any tips?
> 
> Thanks -- Randy


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




Re: How do I delete a file from Perl?

2002-01-12 Thread Ahmed Moustafa

It's "perldoc -f system" not "perldoc system".
--Ahmed

Gary Hawkins wrote:

>>  system("rm -rf $file");
>>
>>But if you copied this from another source, that source was totally
>>unaware that deletion of files like THAT is TOTALLY unsafe.  A safer
>>approach is:
>>
>>  system("rm", "-rf", $file);
>>
> 
> I'm not aware of the reason for it.
> 
> What's a good way to find which perl doc contains the thing I need to read
> about?
> 
> This will prolly make me look stupider than I wasn't to be of something then
> of, but:
> 
> C:\>perldoc system
> No documentation found for "system".
> 
> /g


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




Re: Pointers versus References

2002-01-12 Thread Ahmed Moustafa

I believe the two terms, reference and pointer, are equivalent. By the 
way, In Java, they call it reference also, I think.
--Ahmed
[EMAIL PROTECTED] | http://www.photo.net/users/ahmed


Patrick Hall wrote:

> Hi pholks,
> 
> It's taken me a while to wrap my head around
> references, since I thought they were always
> Perl-specific. (At least, the term 'reference' doesn't
> show up in K&R!)
> 
> Anyway, it finally occurred to me that the term
> 'reference' might just be Perlish for what other
> languages (C, I'm thinking) call a 'pointer'... Am I
> totally out of wack? 
> 
> Is the distinction in the docs somewhere that I could
> read about a bit?
> 
> -Patrick
> .
> fieldmethods.net: All the news that's fit to parse:
> Human Language Technology


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




Re: Adding/deleting a file

2002-01-16 Thread Ahmed Moustafa

Hi Rory,

Assuming that if there is a problem in opening the file then it's 0, I 
hope the following code helps.

#Code Begings
if (open (INFILE, ";
 close (INFILE);
} else {
 $flag = 0;
}

if ($flag == 0) {
 $flag = 1;
} else {
 $flag = 0;
}

open (OUTFILE, ">file.txt") || die;
print OUTFILE $flag;
close (OUTFILE);
#Code Ends

Regards,

Ahmed

Rory Oconnor wrote:

> I need to touch a file with a "1" in it if a condition is true, and
> either toggle the "1" to a "0" or delete the file (whichever is better,
> probably toggle) if another condition is true.  Excuse my
> newbie-ness...but can anyone give me some hints as to the correct syntax
> for that?
> 
> thanks,
> 
> rory


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




Re: how do I load a new page?

2002-01-20 Thread Ahmed Moustafa

I think your script needs to return something to the broswer. I.E.

#Code begins
print "content-type text/html\n\n";
print "Done";
#Code ends

I hope that helps.


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




Re: Running scripts within browsers

2002-01-20 Thread Ahmed Moustafa

Naveen,

You don't run a perl, if you mean a cgi script, in a browser. You run it 
under a web server, which supports cgi.

Naveen Parmar wrote:

> Hello,
> 
> My activeperl installation was fine. When I try to run my example Perl 
> scripts within IE, the browser does not even recognize them??
> 
> Any ideas???
> 
> - NP


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




Re: change type of fields

2002-01-22 Thread Ahmed Moustafa

Hi Nafiseh,

Based on this document
http://techdocs.postgresql.org/techdocs/updatingcolumns.php, this 
feature has not been implemented yet in postgres. I think you can dump 
this column to a file, or a dummy table, and drop it. Then, you can add 
it again with the correct type and load your data.

Regards,


Nafiseh Saberi wrote:

> hi.
> hope you be fine.
> 
> how can I change type of field in 
> table that build in past ?
> (in postgres)
> 
> thx for your favour.
> ___
>  Have a nice day
> 
> Sincerely yours Nafiseh Saberi  
> 
>   When I was  little , I would pray to
>   God not because I believed  In God
>   but because I wanted God to believe 
>  in me.why wait for heaven to
>experience glamour and beauty ?
>  I want it all and I want it now.
> 
> < I appreciate your sugesstions >
> ___
> 
> 


-- 
Ahmed Moustafa
[EMAIL PROTECTED]


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




Re: Copy a portion of a file to a new file?

2002-01-29 Thread Ahmed Moustafa

Hi Bill,

You can use "last"; i.e.:

#Code beings
open (IN, "out.txt") || die;
while () {
last if /END/;
print OUT;
}
close (IN);
close (OUT);
#Code ends

I hope that helps.

Bill Akins wrote:

> Hi all,
> 
> I would like to read in a file and print out to a new file UNTIL I reach a
> key word in the file.
> 
> I tried something like
> 
> while (<>) {
> if !/KEYWORD/;
> print $ >> dest.txt;
> }
> 
> but that seems to copy all lines of the file except the one(s) contining
> KEYWORD.  How can I have this exit and close dest.txt when I reach the line
> containing KEYWORD?  Maybe
> 
> while (<>) {
> if /KEYWORD/;
> exit
> else print $ >> dest.txt;
> }
> 
> What would be the best approach?  Thanx for any help!


-- 
Ahmed Moustafa
[EMAIL PROTECTED] | http://pobox.com/~amoustafa


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




Re: Launch a url in my web browser?

2002-01-31 Thread Ahmed Moustafa

I believe that is not possible. A server side script can't launch a 
client's browser.

Alan C. wrote:

> Hi,
> 
> Win 2k with MSIE web browser
> 
> Whether or not my web browser is already been launched/opened
> 
> Can a Perl script do that task?  Or a perl module?
> 
> Able to do without bringing up a command prompt as part of the process?
> 
> I was wonder if a script or module already exist.
> 
> Or, what would such written script look like?
> 
> Thanks.  Alan.

-- 
Ahmed Moustafa
[EMAIL PROTECTED] | http://pobox.com/~amoustafa


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




Re: Sites

2002-02-13 Thread Ahmed Moustafa

Naveen, take a look at http://arbornet.org/. I think it's what you are 
looking for.
Good luck


Naveen Parmar wrote:

> Any recommendations on free Web sites where you may upload Perl scripts 
> and execute CGI scripts?
> 
> TIA,
> - NP

-- 
Ahmed Moustafa
[EMAIL PROTECTED] | http://pobox.com/~amoustafa


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




Re: foreach loop

2002-03-16 Thread Ahmed Moustafa

Mariusz,your script works fine!

Mariusz wrote:

> I know this foreach loop works (I included print statement within it and it printed 
>out results perfectly). However, for some reason the script doesn't continue after 
>the loop. Am I missing something really obvious?(the print "text here" just doesn't 
>happen?)
> Thanks. 
> Mariusz
> 
> 
> #!/usr/bin/perl -W
> use CGI ':standard';
> 
> print "Content-type:text/html\n\n";
> 
> @names = param();
> foreach $name (@names) {
>  $$name = param($name);
> }
> print "text here";
> exit;

-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




How to thread in Perl?

2002-03-25 Thread Ahmed Moustafa

How can I thread a function in Perl?

Any help will be appreciated so much.

Regards,
-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: How to thread in Perl?

2002-03-25 Thread Ahmed Moustafa

Matthew Harrison wrote:
> What exactly do you mean by 'thread'?

I've a loop which scans directories looking for files and processes the 
existing files. I'd like process each file independently (i.e. in 
parallel) rather than sequentially.

> 
> On Mon, 25 Mar 2002, Ahmed Moustafa wrote:
> 
> 
>>How can I thread a function in Perl?
>>
>>Any help will be appreciated so much.
>>
>>Regards,
-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


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




Re: How to thread in Perl?

2002-03-25 Thread Ahmed Moustafa

Jim Conner wrote:
> I suck at this kind of topic but the only way I can think of doing such 
> a thing is this:
> 
> Use IPC.
> 
> fork off something like 10 children each child working on a separate 
> file and use sysvmsg sysvshem (I do not believe these are functions and 
> I can't look the right functions up for you right now but perldoc 
> perlipc might be of some use) to pass messages back and forth between 
> the children and the parent to follow what each process is doing.

'fork' spawns a child process of the parent, doesn't it?

> 
> Anyone else?  Im shooting in the dark really.
> 
> - Jim
> 
> 
> At 19:04 03.25.2002 -0800, Ahmed Moustafa wrote:
> 
>> Matthew Harrison wrote:
>>
>>> What exactly do you mean by 'thread'?
>>
>>
>> I've a loop which scans directories looking for files and processes 
>> the existing files. I'd like process each file independently (i.e. in 
>> parallel) rather than sequentially.
>>
>>> On Mon, 25 Mar 2002, Ahmed Moustafa wrote:
>>>
>>>> How can I thread a function in Perl?


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




Re: How to thread in Perl?

2002-03-25 Thread Ahmed Moustafa

> Jim Conner wrote:
> 
>> I suck at this kind of topic but the only way I can think of doing 
>> such a thing is this:
>>
>> Use IPC.
>>
>> fork off something like 10 children each child working on a separate 
>> file and use sysvmsg sysvshem (I do not believe these are functions 
>> and I can't look the right functions up for you right now but perldoc 
>> perlipc might be of some use) to pass messages back and forth between 
>> the children and the parent to follow what each process is doing.
> 
> 
> 'fork' spawns a child process of the parent, doesn't it?

I mean the child is a clone of the parent, isn't?

> 
>>
>> Anyone else?  Im shooting in the dark really.
>>
>> - Jim


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




Re: How to thread in Perl?

2002-03-25 Thread Ahmed Moustafa

Jim Conner wrote:
> At 20:28 03.25.2002 -0800, Ahmed Moustafa wrote:
> 
>>> Jim Conner wrote:
>>>
>>>> I suck at this kind of topic but the only way I can think of doing 
>>>> such a thing is this:
>>>>
>>>> Use IPC.
>>>>
>>>> fork off something like 10 children each child working on a separate 
>>>> file and use sysvmsg sysvshem (I do not believe these are functions 
>>>> and I can't look the right functions up for you right now but 
>>>> perldoc perlipc might be of some use) to pass messages back and 
>>>> forth between the children and the parent to follow what each 
>>>> process is doing.
>>>
>>>
>>> 'fork' spawns a child process of the parent, doesn't it?
>>
>>
>> I mean the child is a clone of the parent, isn't?
> 
> 
> Yes; from the point where the fork occurs.

So, how can a new different process by forked? Or, how a function be 
called and the next step execute without waiting for the previous 
function to terminate?


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




Re: How to thread in Perl?

2002-03-25 Thread Ahmed Moustafa

Tagore Smith wrote:

> Ahmed Moustafa wrote:
> 
> 
>>So, how can a new different process by forked? Or, how a function be
>>called and the next step execute without waiting for the previous
>>function to terminate?
>>
> 
>For your original question (threads) see perldoc perlthrtut.
> 
>When you fork a child process the call to fork returns the child pid to
> the parent and 0 to the child. So you can write code that tests the return
> value and does one thing in the parent process (continue forking children to
> deal with the rest of your files) and another in the child process (process
> the current file). You can also use exec to execute another process which is
> not a "clone" of the parent.
> 
>See perldoc -f fork and perldoc -f exec.
> 
>Out of curiosity, why do you want to do this?


The main loop looks for files which are sent via FTP. Once a file is on 
the server, it should be encrypted. The encryption process is slow so 
some files stay as plain text waiting for their turns to be found and 
encrypted.


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




Re: How to thread in Perl?

2002-03-26 Thread Ahmed Moustafa

Chas, thanks a lot for your example.

if the while loop is inside a main infinite loop (as if it was a 
daemon), do I still need to have the waitpid function? and if yes, where 
should be located?

Once again, thanks a lot!


Chas Owens wrote:
> On Tue, 2002-03-26 at 01:14, Ahmed Moustafa wrote:
> Fork returns 0 to the child process and the pid of the child process to
> the parent.  This allows you to say things like
> 
> my @children;
> #loop while get_filename retruns a vaild filename
> #this could easily be a foreach loop of @filenames
> while (my $filename = get_filename()) { 
>   my $forked = fork; #fork into two processes(parent and child)
> 
>   #if $forked is undef then fork failed
>   unless (defined $forked) {
>   warn "something went wrong with fork";
>   next;
>   } 
> 
>   #push the PID of the child onto a stack
>   push @children, $forked; #meaningless for child
>   
>   next if $forked; #parent loops
> 
>   #only the child can get here 
>   encrypt_the_file($filename);
> 
>   #child ends execution here
>   exit 0;
> }
> 
> #reap the children to avoid zombies
> waitpid $_ for (@children);


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




Re: How to thread in Perl?

2002-03-27 Thread Ahmed Moustafa

Chas Owens wrote:
> I wrote some experimental code and it looks like you don't have to reap
> the children (maybe this is just a C thing).

So, is it OK to fork processes without using waitpid?

In general, how are the servers (from the fork perspective - 
multithreading handling -) implemented in Perl?

> 
> On Tue, 2002-03-26 at 15:56, Ahmed Moustafa wrote:
> 
>>Chas, thanks a lot for your example.
>>
>>if the while loop is inside a main infinite loop (as if it was a 
>>daemon), do I still need to have the waitpid function? and if yes, where 
>>should be located?


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




Transfer a file via FTP

2002-03-28 Thread Ahmed Moustafa

When a file is transferred via FTP, when is the EOF character added to 
the file (only at the end of transmission or also during the transferring)?

Your help will be appreciated so much.
-- 
Ahmed Moustafa


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




Re: Transfer a file via FTP

2002-03-29 Thread Ahmed Moustafa

Jenda Krynicky wrote:
> Anyway when reading file you don't need any end of line character, 
> the system KNOWs how long is the file at the moment and 
>  will return undef if you've read all there is.

I didn't get what you meant by " will return undef if you've 
read all there is"; would you explain more, please?


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




why does flock give Bad file number?

2002-03-29 Thread Ahmed Moustafa

Why does exclusive flock give Bad file number (Solaris)?


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




How to delete hash element

2001-11-20 Thread Ahmed Moustafa Ibrahim Ahmed

Hi,

If I know the key and offset of the element, how can I delete that hash
element, please?

Your help will be appreciated.

Ahmed


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




Re: How to delete hash element

2001-11-20 Thread Ahmed Moustafa Ibrahim Ahmed

The value of each key is an array. And, I want to delete an element of this array. I 
don't want to delete the whole key. Is it possible?
  - Original Message - 
  From: Daniel Gardner 
  To: Ahmed Moustafa Ibrahim Ahmed 
  Cc: [EMAIL PROTECTED] 
  Sent: Tuesday, November 20, 2001 12:50 PM
  Subject: Re: How to delete hash element


  Tuesday, November 20, 2001, 8:41:03 PM, Ahmed Moustafa Ibrahim Ahmed wrote:

  AMIA> If I know the key and offset of the element, how can I delete that hash
  AMIA> element, please?

  you can delete a hash element like:

delete $hash{ the_key };

  but i'm not sure what you mean by "the offset of the element"


  -- 
  Best regards,
   Danielmailto:[EMAIL PROTECTED]





Re: How to delete hash element

2001-11-20 Thread Ahmed Moustafa Ibrahim Ahmed

Michael,

Thanks a lot.

Ahmed
  - Original Message - 
  From: Michael Fowler 
  To: Ahmed Moustafa Ibrahim Ahmed 
  Cc: [EMAIL PROTECTED] 
  Sent: Tuesday, November 20, 2001 2:14 PM
  Subject: Re: How to delete hash element


  On Tue, Nov 20, 2001 at 12:41:03PM -0800, Ahmed Moustafa Ibrahim Ahmed wrote:
  > If I know the key and offset of the element, how can I delete that hash
  > element, please?

  As far as I understand the followup clarification, what you really want to
  do is delete an element in an array, which just happens to be in a hash.

  So, you have a data structure something like:

  %hash = (
  key1=>  ['key1, element1', 'key1, element 2'],
  key2=>  ['key2, element1', 'key2, element2', 'key2, element3'],
  );

  And you want to delete the first element in the $hash{'key2'} array.  That'd
  be accomplished like so:

  unshift @{ $hash{'key2'} };

  Or, say you want to delete the second element in the $hash{'key1'} array:

  splice(@{ $hash{'key1'} }, 1, 1)


  See perldoc perldata for more information on dealing with arrays, perldoc
  perldsc for information on dealing with complex data structures, and perldoc
  -f unshift and perldoc -f splice for information on the unshift and splice,
  respectively.


  I'm really surprised at some of the people suggesting you use delete for
  this.  Most of them should know better.  Using delete on an array element
  will remove that element, but only if it's on the end.  If it's in the
  middle, or at the beginning of the array, it'll simply cause the exists
  operator to return false for that element.  I doubt that's what you wanted.


  Michael
  --
  Administrator  www.shoebox.net
  Programmer, System Administrator   www.gallanttech.com
  --



Re: How to know a file is being processed?

2001-11-24 Thread Ahmed Moustafa Ibrahim Ahmed

My script should be waiting for the incoming files and encrypts them as
soon as the transmission is completed. Using "lsof" makes a gap between
the arrival of the files and their encryption.

Is there any other way to know that a file is being FTPed, specifically?

Thanks,
Ahmed


On Sat, 24 Nov 2001, John W. Krahn wrote:

> Ahmed Moustafa Ibrahim Ahmed wrote:
> > 
> > In Perl, how can I know that a file is being opened by any other process
> > i.e. being edited or transferred (FTP)?
> > 
> > I made following function but it's very slow because of the using of "lsof":
> 
> You are also using "grep" and "wc".
> 
> > ---
> > sub is_open {
> > local ($file) = @_;
> > $flag = qx ( $settings{'lsof'} | grep $file | wc -l);
> > $flag =~ s/^\s+//;
> > $flag =~ s/\s+$//;
> > if ($flag == 0) {
> > return "";
> > } else {
> > return 1;
> > }
> > }
> 
> It is kind of hard to test without the actual command line settings for
> "lsof".
> 
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


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




Useless use of a variable in void context

2001-11-24 Thread Ahmed Moustafa Ibrahim Ahmed

Hi,
The following line of code "if (-d $filename) {" gives me the error
message "Useless use of a variable in void context".
What does this error message, please?
Thanks,
Ahmed


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




Re: error in perl.com

2001-11-25 Thread Ahmed Moustafa Ibrahim Ahmed

Nafiseh,

I think "question" is correct.

Thanks,

Ahmed

Nafiseh Saberi wrote:

> hi all.
> 
> I find one error in perl.com in
> http://www.perldoc.com/perl5.6/pod/func/readdir.html
> in line four.
> instead of qutation...write question.
> 
> bye.
> 
> 
> Nafiseh Saberi   
> 


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




Re: build directory with source code

2001-11-25 Thread Ahmed Moustafa Ibrahim Ahmed

To build a directory, use mkdir



To check if a directory exists or not:

if (-e $dirname) {
  print "$dirname exists";
} else {
  print "$dirname does not exist";
}

I hope that helps.

Ahmed


Nafiseh Saberi wrote:

> hi all...
> would  you  know any info for 
> build directory in specific path in middle
> 
> of source code of perl??
> 
> I need the syntax ,that open dir and if it isn't exist...
> 
> build that.
> 
> thx.
> 
> 
> 
> 
> 
> Nafiseh Saberi   
> 


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




  1   2   >