Re: Does Perl have to be installed ?

2003-01-01 Thread Ramprasad
If you are looking for a free soltuion you can try the 'O' module

perldoc O

assume hello.pl is a perl file
do the following

perl -MO=C hello.pl > hello.c

Now hello.c is a c version of your file
Compile it using your favourite C compiler ( you will have to include 
all perl libraries anyway )

On Linux I do this

gcc -D_REENTRANT -fno-strict-aliasing -I/usr/local/include 
-I/usr/lib/perl5/5.6.1/i386-linux-thread-multi/CORE *hello.c* -o *hello* 
-rdynamic -L/usr/local/lib 
/usr/lib/perl5/5.6.1/i386-linux-thread-multi/auto/DynaLoader/DynaLoader.a 
-L/usr/lib/perl5/5.6.1/i386-linux-thread-multi/CORE -lperl -lnsl -ldl 
-lm -lpthread -lc -lcrypt -lutil

(gasp !)

and now the output file hello runs without perl

Just be warned that this may not be the most efficient c program for hello

Craig Williams wrote:
Sounds crazy I know but if I'm on a customers side with my CD of pl scripts
I don't want to have to install Perl on their
servers just to run my code. Can I just put the binary files on the CD and
run them ?

thanks

Craig





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




Re: glob subtlety question

2003-01-01 Thread Rob Dixon
But glob 'absent_file.txt' returns ('absent_file.txt') so I think this does
what's required. As perldoc says, glob EXPR returns the value of EXPR with
filename expansions such as the standard Unix shell /bin/csh would do.

Whether this behaviour is a Good Thing is a separate question though, and
puts me up against innumerable fanatical Unix users :-D

/R

"Jenda Krynicky" <[EMAIL PROTECTED]> wrote in message
3E121902.10341.380E85D6@localhost">news:3E121902.10341.380E85D6@localhost...
> From: "Rob Dixon" <[EMAIL PROTECTED]>
> > Sorry to drag this one up again, but it doesn't seem to have been
> > answered properly. Surely the answer is:
> >
> > my @input_files = map glob, @ARGV;
> >
> > which will also leave @input_files empty if @ARGV is empty.
>
> The problem is that it will also glob the stuff that should not have
> been globbed. And if the script was called
>
> script.pl *.txt results.log
>
> then your globbing will remove the "results.log" if it doesn't exist
> already.
> Not necessarily the best thing to do.
>
> IMHO, the best answer is
> use G; # http://Jenda.Krynicky.cz/#G
>
> Jenda
> = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
> When it comes to wine, women and song, wizards are allowed
> to get drunk and croon as much as they like.
> -- Terry Pratchett in Sourcery
>



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




Re: Perl editors

2003-01-01 Thread Kieren Diment
On Tue, Dec 31, 2002 at 10:33:46AM -0500, Paul Kraus wrote:
> I am running emacs for windows. How do I use these debugging options? I
> currently use cperl  mode.
> 

I haven't looked at it too hard, but, under xemacs using linux I get a
reasonable debugging environment via the Debugger option on the Perl
toolbar item or with M-x cperl-db (equivalent command).  I haven't
done much hardcore debugging with perl so far, but it has lots of
potential.  It's basically an interface between perl's debugger and
emacs.  I'd be pretty sure that you can do everything you wanted to in
this environment after reading the manual that is.


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




Stepping back into the last Century in 2003 - Curses

2003-01-01 Thread Jerry Rocteur
# Platform, SuSE Linux 8.1 and Mac OS X 10.2.3 both running Perl 5.8
#
# Destination platform Solaris 8
#

Hi,

I'd like to write some menus in Perl..

I looked at the FAQ and saw that perlmenu is recommended, so I 
installed it.

It does not tell you it needs curses but when you first run it, it 
yells that Curses.pm is not installed.. (Can't locate Curses.pm in @INC 
...)

So this is where I stepped back to circa 1988.. I tried to install 
Curses.pm... OUCH.

I've tried both of these operations on Mac OSX and Suse Linux and I get 
the same or similar results.

I've read the INSTALL and linked the hints files to c-config.h played 
around and played around and I always get similar results..


CursesFun.c: In function `XS_Curses_getwin':
CursesFun.c:3472: warning: initialization from incompatible pointer type
make: *** [Curses.o] Error 1

This is OBVIOUSLY NOT the way to go in 2003, having to play around 
header files and libraries to get something working, I had less work to 
do upgrading Mac OS X to perl 5.8 than to get this * working.

So, my question is, what do you guys use for menus that works in Perl, 
the destination system once it is developed will be Solaris 8.

I would be grateful for workable solutions, note that I don't want GUI 
stuff, just simple stuff that will work with ssh/Keaterm in the future.

Thanks very much,

Jerry Rocteur.
Back to the Future


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



Re: two questions

2003-01-01 Thread Adriano Allora
thank you all (Dan Muey, Wiggins d'Anconia, Rob Hansom in particular),
the party is finished, there was a perl-experienced-user but I used all 
my selfcoltrol to avoid to ask him something about programming (my 
girlfriend would have never forgiven me ;P ).
After some hours of sleep, I was rewarded for selfcontrol by your 
suggestions. I'll try your code, that's shows as usually a marvellous 
heterogeneity.
valete,

all'adr


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



Posting A file from a form

2003-01-01 Thread LRMK
If a visitor posting a file using a file upload box how do I retrieve that from the 
cgi please give a simple example code 



Extracting an Atachment From a Email

2003-01-01 Thread LRMK
I'm Using NET:POP3 to download mail from pop server
which is in the same computer with my cgi 

1. All the Attachments are comes as a Bulk of text
How do I convert it into real binary file?

Is Is there a Special Module for that purpose or should I use MIME:BASE64 manually 

2. How do I attach a file to email by converting it into a bulk of text?





Name a Free PERL Campiler for Win2k

2003-01-01 Thread LRMK
Is there any Free Perl Compilers for Win2k



Re: Name a Free PERL Campiler for Win2k

2003-01-01 Thread LRMK
Yes   I  Mean to Creat Binary .EXEs
not the PERL interpreter
- Original Message -
From: "K Clark" <[EMAIL PROTECTED]>
To: "LRMK" <[EMAIL PROTECTED]>
Sent: Thursday, January 02, 2003 12:03 AM
Subject: Re: Name a Free PERL Campiler for Win2k


> On Thu, Jan 02, 2003 at 12:02:25AM +0600, LRMK wrote:
> > Is there any Free Perl Compilers for Win2k
>
> yeah, its called PERL. what do you mean by compiler? are you trying to
create
> a windows binary file (.exe?)?
>
> check out the activestate project at activestate.com
> --
> [llamakc.org schlitz.org klark.org]
> k e n a t l l a m a k c d o t o r g
>(o_
>  (o_  (o_  //\
>  (/)_ (/)_ V_/_
>
>


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




Name a Free PERL Campiler for Win2k

2003-01-01 Thread LRMK
Yes   I  Mean to Creat Binary .EXEs
not the PERL interpreter
- Original Message -
From: "K Clark" <[EMAIL PROTECTED]>
To: "LRMK" <[EMAIL PROTECTED]>
Sent: Thursday, January 02, 2003 12:03 AM
Subject: Re: Name a Free PERL Campiler for Win2k


> On Thu, Jan 02, 2003 at 12:02:25AM +0600, LRMK wrote:
> > Is there any Free Perl Compilers for Win2k
>
> yeah, its called PERL. what do you mean by compiler? are you trying to
create
> a windows binary file (.exe?)?
>
> check out the activestate project at activestate.com
> --
> [llamakc.org schlitz.org klark.org]
> k e n a t l l a m a k c d o t o r g
>(o_
>  (o_  (o_  //\
>  (/)_ (/)_ V_/_
>
>


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




Re: Posting A file from a form

2003-01-01 Thread Jenda Krynicky
From: "LRMK" <[EMAIL PROTECTED]>
> If a visitor posting a file using a file upload box how do I retrieve
> that from the cgi please give a simple example code 

I'm sure
perldoc CGI
does contain examples.

Jenda



= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: glob subtlety question

2003-01-01 Thread Jenda Krynicky
From: "Rob Dixon" <[EMAIL PROTECTED]>
> But glob 'absent_file.txt' returns ('absent_file.txt') so I think this
> does what's required. As perldoc says, glob EXPR returns the value of
> EXPR with filename expansions such as the standard Unix shell /bin/csh
> would do.

I see ... it only returns nothing if the parameter contained a * or ?

I remember having some discussions regarding this and we agreed that 
even this should survive the cmdline globbing.
So that you could print

Cannot open file *.txt
or
No files match the *.txt mask

If you happen to have several masks with different meanings it might 
be good to be able to say which one did not return anything.
And it may not of course :-)
I was told this is the behaviour of the Unix shells ...

> > From: "Rob Dixon" <[EMAIL PROTECTED]>
> > > Sorry to drag this one up again, but it doesn't seem to have been
> > > answered properly. Surely the answer is:
> > >
> > > my @input_files = map glob, @ARGV;

There's one more bad thing about this code. Suppose the script was 
called like this

script.pl "hello world.doc"

then the @ARGV = ( 'hello world')
but the line above will set @input_files to
( 'hello', 'world.doc' )

Not very usefull :-)

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: Name a Free PERL Campiler for Win2k

2003-01-01 Thread Jenda Krynicky
From: "LRMK" <[EMAIL PROTECTED]>

> Yes   I  Mean to Creat Binary .EXEs
> not the PERL interpreter

It seems App::Packer promises to do that.
http://search.cpan.org/author/MBARBON/App-Packer-0.09/

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




including data from an external file

2003-01-01 Thread Ebaad Ahmed
Hello everybody,

I would like to include a file in my cgi code so that it contains all the lists of 
data, and later  
can be edited from another form to create an admin tool for the lists in the main 
form.  

I have researched alot and found that I can use "require" or "use" for this purpose
but I still could not find a complete simple example of how to declare the array in an 
 
external file and how to recall the data from the cgi script in order to display it.

Any help will be greatly appreciated.

Regards,
Ebaad.
[EMAIL PROTECTED] more from the Web.  FREE MSN Explorer download : 
http://explorer.msn.com



navigate the directories

2003-01-01 Thread Adriano Allora
I need to know, in the @ARGV, when a string is the name of a directory.
More precisely I'd like to write a script that:

processes the files of the textes in a dir
extracts the list of the sub-directories in a dir
in each sub-dir processes the files of the textes
extracts the list of the sub-directories
in each sub-dir processes the files of the textes
extracts the list of the sub-directories
	and go on...

Some advices?

all'adr


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




Re: macthing question...

2003-01-01 Thread Adriano Allora
maybe this does not ineterest you, but:
if you wanna substitute each code (for instance 010) with its correct 
name (for instance red) you can use thw script that follows.
Actually I'm working on apply this script to an entire directory and 
its subdirectories (see the mail "navigate the directories").
hope to be useful.

all'adr

~~~THE SCRIPT~~~



#!/usr/bin/perl -w
# extracts from a file two arrays of related words
# searches in a file the first word of any couple (in the first array) 
and
# substitute it with its related words in the second array
# then print the correct file
use strict;

my $fileNinput = "INciccio.txt";
my $fileNoutput = "OUTciccio.txt";
my ($firstnames,$secondnames,@firstnames,@secondnames,@badnames);
my $num = 0;

open (INPUT, $fileNinput) or die "File not opnd cos $!";
my @names = ;
foreach my $name (@names) {
#this regexp depends on your text formatting
  if ($name =~ /(\S+) "(\S+)/) {
 push @firstnames, $1;
 push @secondnames, $2;
  }
  else {
 # Invalid formatted name
 push @badnames;
  }
}
close (INPUT);

open (INPUT, $fileNoutput);
while ()
{
foreach $firstnames (@firstnames){
s/$firstnames/$secondnames[$num]/g;
$num ++;
}
print;
}
close (INPUT);


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



RE: navigate the directories

2003-01-01 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Use File::Find from std distribution. Has examples and if problems,
the list can help you.

Wags ;)

-Original Message-
From: Adriano Allora [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 01, 2003 13:21
To: [EMAIL PROTECTED]
Subject: navigate the directories


I need to know, in the @ARGV, when a string is the name of a directory.
More precisely I'd like to write a script that:

processes the files of the textes in a dir
extracts the list of the sub-directories in a dir
in each sub-dir processes the files of the textes
extracts the list of the sub-directories
in each sub-dir processes the files of the
textes
extracts the
list of the sub-directories
and
go on...

Some advices?

all'adr


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


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



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




Re: glob subtlety question

2003-01-01 Thread Rob Dixon
Hi Jenda

See in-line.

"Jenda Krynicky" <[EMAIL PROTECTED]> wrote in message
3E1349E5.27703.3CB576EE@localhost">news:3E1349E5.27703.3CB576EE@localhost...
> From: "Rob Dixon" <[EMAIL PROTECTED]>
> > But glob 'absent_file.txt' returns ('absent_file.txt') so I think this
> > does what's required. As perldoc says, glob EXPR returns the value of
> > EXPR with filename expansions such as the standard Unix shell /bin/csh
> > would do.
>
> I see ... it only returns nothing if the parameter contained a * or ?
>
> I remember having some discussions regarding this and we agreed that
> even this should survive the cmdline globbing.

Sounds like a little overactive ego on the part of the shell in that case.
You're saying that the script in

script.pl *.ext file.ext

would see an @ARGV of

   ('*.ext', 'file.ext')

if there were no files with this extension, but

('file.ext', 'file1.ext', 'file2.ext', 'file.ext')

if all of these (three) files existed?

Then how do you pass '*.ext' as ('*.ext') if there are such files? I suppose
you can pick up the entire command line (I think?) and process that, but I'm
very glad most languages don't do clever 'useful' things with your parameter
list before called code gets to see them.

> So that you could print
>
> Cannot open file *.txt
> or
> No files match the *.txt mask
>
>
> If you happen to have several masks with different meanings it might
> be good to be able to say which one did not return anything.
> And it may not of course :-)
> I was told this is the behaviour of the Unix shells ...
>

Fine, but rather than have the shell performing obscure gymnastics beneath
me I'd rather code it explicitly:

for (@ARGV) { print "No files match the $_ mask\n" unless glob };
my @input_files = map glob, @ARGV;

> > > From: "Rob Dixon" <[EMAIL PROTECTED]>
> > > > my @input_files = map glob, @ARGV;
>
> There's one more bad thing about this code. Suppose the script was
> called like this
>
> script.pl "hello world.doc"
>
> then the @ARGV = ( 'hello world')
> but the line above will set @input_files to
> ( 'hello', 'world.doc' )

Not at all. @ARGV would equal ( "hello world.doc" ) and the statement would
set @input_files = ( "hello world.doc" ).

>
> Not very usefull :-)
>

Au contraire, just what is wanted :-)

Cheers,

Rob




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




Re: glob subtlety question

2003-01-01 Thread Jenda Krynicky
From: "Rob Dixon" <[EMAIL PROTECTED]>
> "Jenda Krynicky" <[EMAIL PROTECTED]> wrote in message
> 3E1349E5.27703.3CB576EE@localhost">news:3E1349E5.27703.3CB576EE@localhost...
> > From: "Rob Dixon" <[EMAIL PROTECTED]>
> > > But glob 'absent_file.txt' returns ('absent_file.txt') so I think
> > > this does what's required. As perldoc says, glob EXPR returns the
> > > value of EXPR with filename expansions such as the standard Unix
> > > shell /bin/csh would do.
> >
> > I see ... it only returns nothing if the parameter contained a * or
> > ?
> >
> > I remember having some discussions regarding this and we agreed that
> > even this should survive the cmdline globbing.
> 
> Sounds like a little overactive ego on the part of the shell in that
> case. You're saying that the script in
> 
> script.pl *.ext file.ext
> 
> would see an @ARGV of
> 
>('*.ext', 'file.ext')
> 
> if there were no files with this extension, but
> 
> ('file.ext', 'file1.ext', 'file2.ext', 'file.ext')
> 
> if all of these (three) files existed?
> 
> Then how do you pass '*.ext' as ('*.ext') if there are such files? 

If we are talking about unix shells

script.pl '*.ext' file.ext

And actually that's what will work with G.pm as well.

And yes you are right, that's exactly what is the shell supposed to 
be doing.

> I
> suppose you can pick up the entire command line (I think?) and process
> that, but I'm very glad most languages don't do clever 'useful' things
> with your parameter list before called code gets to see them.

The whole problem is that the process gets the commandline if you use 
Windows and a list of parameters if you use Unix.

Normaly the C runtime under Windows parses the commandline and fills 
the argv array. Which is exactly what happens if you run a Perl 
script under windows. The system passes the cmdline and the runtime 
breaks it apart. And breaks it. And your program is supposed to do 
the globbing, even though the runtime already stripped some well 
needed info.

The G.pm basicaly overcomes the broken @ARGV and parses the cmdline 
and globs the parameters at the same time. Close to the Unix way.

If you do not want that you either do not use G.pm and glob just the 
stuff you want or 
use G qw(NOGLOB StripPerlFromCommandLine GetCommandLine);

$rawcmdline = GetCommandLine();
$cmdlineparams = StripPerlFromCommandLine($rawcmdline);

and parse the raw commandline. 
(Actually it's not totally raw. The IO redirections and pipes are 
already processed by the shell and NOT passed to the process.)

> > So that you could print
> >
> > Cannot open file *.txt
> > or
> > No files match the *.txt mask
> >
> >
> > If you happen to have several masks with different meanings it might
> > be good to be able to say which one did not return anything. And it
> > may not of course :-) I was told this is the behaviour of the Unix
> > shells ...
> >
> 
> Fine, but rather than have the shell performing obscure gymnastics
> beneath me I'd rather code it explicitly:
> 
> for (@ARGV) { print "No files match the $_ mask\n" unless glob };
> my @input_files = map glob, @ARGV;

Problem is that under Unix the shell IS performing the gymnastics.

You can quote some params to ensure they are not globbed, but the 
default is globbing.
 
> > > > From: "Rob Dixon" <[EMAIL PROTECTED]>
> > > > > my @input_files = map glob, @ARGV;
> >
> > There's one more bad thing about this code. Suppose the script was
> > called like this
> >
> > script.pl "hello world.doc"
> >
> > then the @ARGV = ( 'hello world')
> > but the line above will set @input_files to
> > ( 'hello', 'world.doc' )
> 
> Not at all. @ARGV would equal ( "hello world.doc" ) and the statement
> would set @input_files = ( "hello world.doc" ).

What's your version of Perl?

In file zkGlob.pl I have this:
#!perl
print "\@ARGV = ( '" . join( "', '", @ARGV) . "')\n\n";
@input_files = map {glob $_} @ARGV;
print "\@input_files = ( '" . join( "', '", @input_files) . 
"')\n\n";

call it as:
c:\temp\zkGlob.pl "hello world.doc" *.txt

and get:
@ARGV = ( 'hello world.doc', '*.txt')

@input_files = ( 'hello', 'world.doc', 'te-fetch.txt')

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: including data from an external file

2003-01-01 Thread Wiggins d'Anconia
I am not entirely sure I get what you are trying to do, but see inline.

Ebaad Ahmed wrote:

Hello everybody,

I would like to include a file in my cgi code so that it contains all the lists of data, and later  
can be edited from another form to create an admin tool for the lists in the main form.  


If you are just talking about a list of data, then it can be stored 
either as actual perl code or as a just text delimited by something 
(most likely new lines). In the case of using perl code, you could just 
declare it as an array like in any script, note that it will have to be 
a global which would make strict complain and this is not a good way to 
do anything but a one-off.


I have researched alot and found that I can use "require" or "use" for this purpose
but I still could not find a complete simple example of how to declare the array in an  
external file and how to recall the data from the cgi script in order to display it.


If you still want to take this approach of having the data stored as a 
perl structure the easiest way would be to store it lexically in the 
file as an array for instance, then write a quick subroutine to return 
either the array itself, or a reference to the array. For example:

our @data = ('element1','element2','element3');

sub return_data {
  return @data;
}

or

sub return_data_as_array_ref {
  return \@data;
}

And then in your other script you would simply say:

require 'data_file.pl';
@local_copy_of_data = return_data();

or

$local_ref_to_data = return_data_as_array_ref();


Any help will be greatly appreciated.



However if it is just a list of data, you might consider just storing it 
one element per line, then using 'open' to open the file and then read 
it into an array or line by line.

my $HANDLE;
open($HANDLE,'/path/to/file_with_data.txt') or die "Can't open data 
file: $!";
my @data = <$HANDLE>;
close($HANDLE);

In both cases to edit the file you will have to do an open and the print 
the contents into the file either manually doing your formatting if any 
is required or using something like Data::Dumper or XML, etc.

good luck,

http://danconia.org


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



Re: including data from an external file

2003-01-01 Thread Wiggins d'Anconia
Always group reply so the list can help as well, as I definitely don't 
have all the answers :-).

The code I sent earlier will open the list for reading only. To open a 
file for writing you would have to use the > operator in the open, or >> 
for appending, check out perldoc -f open for more info on this.

In general I would probably open the file, read its contents, and then 
close it, then open it again if I was doing anything but appends, but 
that is in general slower as it requires two opens, but it is probably 
more a matter of preference.  Check out the perldoc -f open doc page 
mentioned earlier for a lot of information about how to do various 
opens, and you may also want to check out perldoc perlopentut.  You may 
also want to consider a backup plan, once you start writing your file if 
something happens to the execution of the program whatever hasn't been 
written will be lost, so you should write to a temporary file and then 
move it into place, or something similar so that you have a way to 
recover the contents in the event of a meltdown.

http://danconia.org


Ebaad Ahmed wrote:


Hi Wiggins,

Thanks a lot for responding to my message, I really liked the idea of 
openeing a separate file and storing the elements in there, but I just 
have one question that will this open the file for reading and writing 
both or do I have to open it again for writting. Please forgive me if it 
is a stupid question. If you want I can email you the code, I only 
wanted to store the contents of a scroll list in a file so that I dont 
have to edit the code in order to add or delete a name from the list.

Regards,
Ebaad.
 >From: Wiggins d'Anconia
 >To: Ebaad Ahmed
 >CC: [EMAIL PROTECTED]
 >Subject: Re: including data from an external file
 >Date: Wed, 01 Jan 2003 20:39:26 -0500
 >
 >I am not entirely sure I get what you are trying to do, but see
 >inline.
 >
 >Ebaad Ahmed wrote:
 >>Hello everybody,
 >>
 >>I would like to include a file in my cgi code so that it contains
 >>all the lists of data, and later can be edited from another form
 >>to create an admin tool for the lists in the main form.
 >>
 >
 >If you are just talking about a list of data, then it can be stored
 >either as actual perl code or as a just text delimited by something
 >(most likely new lines). In the case of using perl code, you could
 >just declare it as an array like in any script, note that it will
 >have to be a global which would make strict complain and this is not
 >a good way to do anything but a one-off.
 >
 >
 >>I have researched alot and found that I can use "require" or "use"
 >>for this purpose
 >>but I still could not find a complete simple example of how to
 >>declare the array in an external file and how to recall the data
 >>from the cgi script in order to display it.
 >>
 >
 >If you still want to take this approach of having the data stored as
 >a perl structure the easiest way would be to store it lexically in
 >the file as an array for instance, then write a quick subroutine to
 >return either the array itself, or a reference to the array. For
 >example:
 >
 >our @data = ('element1','element2','element3');
 >
 >sub return_data {
 > return @data;
 >}
 >
 >or
 >
 >sub return_data_as_array_ref {
 > return \@data;
 >}
 >
 >And then in your other script you would simply say:
 >
 >require 'data_file.pl';
 >@local_copy_of_data = return_data();
 >
 >or
 >
 >$local_ref_to_data = return_data_as_array_ref();
 >
 >
 >>Any help will be greatly appreciated.
 >>
 >
 >However if it is just a list of data, you might consider just
 >storing it one element per line, then using 'open' to open the file
 >and then read it into an array or line by line.
 >
 >my $HANDLE;
 >open($HANDLE,'/path/to/file_with_data.txt') or die "Can't open data
 >file: $!";
 >my @data = <$HANDLE>;
 >close($HANDLE);
 >
 >In both cases to edit the file you will have to do an open and the
 >print the contents into the file either manually doing your
 >formatting if any is required or using something like Data::Dumper
 >or XML, etc.
 >
 >good luck,
 >
 >http://danconia.org
 >
 >
 >--
 >To unsubscribe, e-mail: [EMAIL PROTECTED]
 >For additional commands, e-mail: [EMAIL PROTECTED]


Protect your PC - Click here  for 
McAfee.com VirusScan Online


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




Re: navigate the directories

2003-01-01 Thread R. Joseph Newton
Hi Adriano,

Here is a start.  You might have to adapt it somewhat for youe specific uses.  It 
originated from a proplem Paul posed concernig a search for files of a given name on a 
single level of a directory tree, and greww from there.  It's taken on a bit of random 
testion g code also.  The indent function was born with this program, but never used 
in it.  It has since been moved to a *.pm file.

Have Fun,

Joseph

#!/usr/bin/perl
use warnings;
#use strict;

# Utility to search filenames and text in a given folder and all subdirectoies
# Usage: DirTreeTest.pl -f|-t $baseDir $soughtFile
# If the first parameter is -f, the utility returns all folders containg the given 
file.
# If the first parameter is -t, the utility returns all files containg the given text.


my $option = $ARGV[0];
my $baseDir  = $ARGV[1];
my $soughtFile = $ARGV[2];
my $indentSize = 2;
if ($option eq "-f") {
  ListDirectoriesContainingFile ($ARGV[1], $ARGV[2], 0);
} elsif ($option eq "-t") {
  ListFilesContainingText ($ARGV[1], $ARGV[2], 0);
} else {
  die "You must specify either -f or -t";
}

sub ListDirectoriesContainingFile {
  my $currentDir  = $_[0];
  my $targetFile = $_[1];
  my $indentation = $_[2];
  my $DIR;
  opendir $DIR, $currentDir or die "Cannot opendir $currentDir: $!";
  my $testFile = "";
  while (my $file = readdir $DIR )  {
$testFile = "$currentDir\\$file";
if ( -d $testFile) {
  my $go;
  if ($go = ($file ne "." and $file ne "..")) {
if (-e "$testFile\\$targetFile") {
  print "Found in:\n---=>>$testFile\n";
}
ListDirectoriesContainingFile("$testFile",
 $targetFile, $indentation + 2);
  }
}
  }
}

sub ListFilesContainingText {
  my $currentDir  = $_[0];
  my $targetText = $_[1];
  my $indentation = $_[2];
  chomp $targetText;
  my $DIR;
  print "current directory is $currentDir\n";
  opendir $DIR, $currentDir or die "Cannot opendir $currentDir: ";
  my $testFile = "";
  my $file = "";
  while (defined($file = readdir $DIR) and $file ne "") {
$testFile = "$currentDir\\$file";
if ( $testFile and (-d $testFile)) {
  if ($file eq "\." || $file eq "\.\.") {;
  } else {
ListFilesContainingText($testFile, $targetText, ($indentation + 2));
  }
}
else {
  #print "file $testFile checked\n";
  if ($file =~ /\..*\./) {
print " ~~~> $testFile is ugly in form\n";
  }
  open (SEEK_FILE, $testFile) or print "can not open $testFile\n";
  my $lineNumber = 1;
  my $CurrentLine = ;
  my $IsIt;
  while ($CurrentLine) {
if ($IsIt = ($CurrentLine =~ /\b$targetText\b/)) {
  print "--=>> $testFile: $lineNumber \n";
  print " |$CurrentLine \n";
  #continue;
}
$lineNumber++;
$CurrentLine = ;
  }
  close SEEK_FILE;
}
  }
}

sub indent {
  my ($indentation, $textString) = @_;
  my $indent = "";
  $oneSpace = " ";
  for ($i = 0; $i < $indentation; $i++) {
$indent = $indent.$oneSpace;
  }
  print "$indent$textString"; print "\n";
}


Adriano Allora wrote:

> I need to know, in the @ARGV, when a string is the name of a directory.
> More precisely I'd like to write a script that:
>
> processes the files of the textes in a dir
> extracts the list of the sub-directories in a dir
> in each sub-dir processes the files of the textes
> extracts the list of the sub-directories
> in each sub-dir processes the files of the textes
> extracts the list of 
>the sub-directories
> and go on...
>
> Some advices?
>
> all'adr
>
> --
> 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: more socket stuff - 2nd part

2003-01-01 Thread Ramprasad
Dont fork above the $server->accept() line.

this is where it shuld be
while($client=$server->accept()){
   next unless(fork()); #The server is forked and parent goes back to
# listen
    # One child of the server serves the client
   .#
   undef $client;   # Close the socket
   undef $server;   # Close the forked server
# The server is not stopped because only the
#  forked copy is closed
}




Mat Harris wrote:

Mark Goland wrote:


glad it worked, although the fork() was sepose to be after the while 
loop.

Cheers,
Mark
- Original Message - From: "Mat Harris" 
<[EMAIL PROTECTED]>
To: "Mark Goland" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, December 31, 2002 6:08 AM
Subject: Re: more socket stuff - 2nd part


tried that and although it worked for the first connection, it still 
hung on accepting the second.

either way your suggestion made it happen

--
Mat HarrisonNetwork Systems Administrator
[EMAIL PROTECTED]www.genestate.com


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




Log maintanence prblem...

2003-01-01 Thread Tim Martin
Help Folks..


I have run into a small problem with the script we have been working on for
log management.
Problem 1 - The script must be in the same sub directory as all the logs.
How can I get the script to run from /var/tmp/gatelog and not in
var/tmp/gatelog/glogs

Problem 2 - The Line of the log dose not have the correct server name in
column one.
What I'm I doing wrong.

s00237 2002/12/31 20:47:34 +05 003503E0: STATUS DATA: jobqq= 0 jobqr= 0
reqdq= 0 gwmethods= 0
s00237 2002/12/31 21:47:37 +05 003503E0: STATUS DATA: jobqq= 0 jobqr= 0
reqdq= 0 gwmethods= 0
2002/12/31 22:47:45 +05 003503E0: STATUS DATA: jobqq= 0 jobqr= 0 reqdq= 0
gwmethods= 0

Below is the script we are using.

#!/usr/bin/perl -w

#chdir ("/var/tmp/gatelog/glogs") && die "cannot find directory";

my @Gatelogs_list = `ls`;
my $lineprint = '';
my $lines=`ls | wc -l`;
my $i=0;
my $line = '';

open (OUT, "> /var/tmp/gatelog/gatelog.txt");
while ($lines >$i){
open (IN,"$Gatelogs_list[$i]");

while () {
chomp; # get rid of the newline
next if $_ eq ''; # skip empty lines
s/\s{2,}/ /g; # replace 2 or more whitespace chars
# with a single space
if ( m{^\d{4}/\d{2}/\d{2} \d\d:\d\d:\d\d} ) {
# if the current line starts with a
timestamp ...
# I assume the /MM/DD HH:MI:SS
format
chomp $Gatelogs_list[$i];
$lineprint = "$Gatelogs_list[$i]" . " "
. "$line";
print OUT $lineprint, "\n" if $line;
# print the buffer
$line = $_;
# remember the current line
} else {
$line .= '' . $_;
# add the current line to
the buffer
}
}
close IN;
$i++;
}
print OUT $line, "\n" if $line;
# print the last buffer
close OUT;

exit 0;

Thanks for help in this matterÂ…
Tim



Re: navigate the directories

2003-01-01 Thread John W. Krahn
[ top-posting fixed ]


"R. Joseph Newton" wrote:
> 
> Adriano Allora wrote:
> 
> > I need to know, in the @ARGV, when a string is the name of a directory.
> > More precisely I'd like to write a script that:
> >
> > processes the files of the textes in a dir
> > extracts the list of the sub-directories in a dir
> > in each sub-dir processes the files of the textes
> > extracts the list of the sub-directories
> > in each sub-dir processes the files of the textes
> > extracts the list 
>of the sub-directories
> > and go 
>on...
> 
> Hi Adriano,
> 
> Here is a start.  You might have to adapt it somewhat for youe specific
> uses.  It originated from a proplem Paul posed concernig a search for files
> of a given name on a single level of a directory tree, and greww from there.
>  It's taken on a bit of random testion g code also.  The indent function was
> born with this program, but never used in it.  It has since been moved to a
> *.pm file.
> 
> #!/usr/bin/perl
> use warnings;
> #use strict;

Why disable strict?


> # Utility to search filenames and text in a given folder and all subdirectoies
> # Usage: DirTreeTest.pl -f|-t $baseDir $soughtFile
> # If the first parameter is -f, the utility returns all folders containg the given 
>file.
> # If the first parameter is -t, the utility returns all files containg the given 
>text.
> 
> my $option = $ARGV[0];
> my $baseDir  = $ARGV[1];
> my $soughtFile = $ARGV[2];
> my $indentSize = 2;
> if ($option eq "-f") {
>   ListDirectoriesContainingFile ($ARGV[1], $ARGV[2], 0);

Why not:

   ListDirectoriesContainingFile ($baseDir, $soughtFile, 0);

In fact, since the contents of $soughtFile don't change, why pass it to
the subroutine at all?


> } elsif ($option eq "-t") {
>   ListFilesContainingText ($ARGV[1], $ARGV[2], 0);
> } else {
>   die "You must specify either -f or -t";
> }
> 
> sub ListDirectoriesContainingFile {
>   my $currentDir  = $_[0];
>   my $targetFile = $_[1];
>   my $indentation = $_[2];
>   my $DIR;
>   opendir $DIR, $currentDir or die "Cannot opendir $currentDir: $!";
>   my $testFile = "";
>   while (my $file = readdir $DIR )  {
> $testFile = "$currentDir\\$file";
  ^^
The backslash will only work on some operating systems.  How can you be
sure the OP is using that particular OS?


> if ( -d $testFile) {
>   my $go;
>   if ($go = ($file ne "." and $file ne "..")) {
^
What is this variable for?


> if (-e "$testFile\\$targetFile") {
>   print "Found in:\n---=>>$testFile\n";
> }
> ListDirectoriesContainingFile("$testFile",
>  $targetFile, $indentation + 2);
>   }
> }
>   }
> }
> 
> sub ListFilesContainingText {
>   my $currentDir  = $_[0];
>   my $targetText = $_[1];
>   my $indentation = $_[2];
>   chomp $targetText;
>   my $DIR;
>   print "current directory is $currentDir\n";
>   opendir $DIR, $currentDir or die "Cannot opendir $currentDir: ";
>   my $testFile = "";
>   my $file = "";
>   while (defined($file = readdir $DIR) and $file ne "") {
 ^^^
While I won't say that it is impossible, I would say that it is HIGHLY
improbable that a file system would store a zero length file name.


> $testFile = "$currentDir\\$file";
> if ( $testFile and (-d $testFile)) {
>   if ($file eq "\." || $file eq "\.\.") {;
  ^^   
Periods don't have to be backslashed in strings.  Better to use unless
instead of an empty if block.


>   } else {
> ListFilesContainingText($testFile, $targetText, ($indentation + 2));
>   }
> }
> else {
>   #print "file $testFile checked\n";
>   if ($file =~ /\..*\./) {
> print " ~~~> $testFile is ugly in form\n";

Why is this "ugly"?  Why should we care?


>   }
>   open (SEEK_FILE, $testFile) or print "can not open $testFile\n";
>   my $lineNumber = 1;

Perl provides the current line number in the $. variable (if you use a
proper while loop.)

>   my $CurrentLine = ;
>   my $IsIt;
>   while ($CurrentLine) {
> if ($IsIt = ($CurrentLine =~ /\b$targetText\b/)) {

What happens if $targetText contains regular expression special
characters like '.', '*', '(', etc.?

>   print "--=>> $testFile: $lineNumber \n";
>   print " |$CurrentLine \n";
>   #continue;
> }
> $lineNumber++;
> $CurrentLine = ;
>   }
>   close SEEK_FILE;
> }
>   }
> }
> 
> sub indent {
>   my ($indentation, $textString) = @_;
>   my $indent = "";
>   $oneSpace = " ";
>   for ($i = 0; $i < $indentation; $i++) {
> $indent = $indent.$oneSpace;
>   }
>   print "$indent$textString"; print "\n";
> }

Wh