Re: difference between FTP and SFTP

2008-05-29 Thread Ken Foskey
On Thu, 2008-05-29 at 11:00 +0530, Rajnikant wrote:
 Hi everyone,
  
 I have question about SFTP's connection modes. FTP can use Active or Passive
 mode for same.
  
 Is SFTP also supports such modes?

It does not need the distinction.  SFTP connects via ssh on port 22
only.

Ken


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: No such file or directory

2008-05-29 Thread Ken Foskey
On Thu, 2008-05-29 at 11:45 +0100, Mimi Cafe wrote:

 my script is in the same directory as my files, but it cannot find the file
 ABC.txt in open() below.
 
 foreach my $supplied (@ARGV){
  # Output file name set of element currently processed.
 
  # Open file to read from.
  open (INPUTFILE, , $supplied) or die Could not open $supplied: $!\n;
 # Error: No such file or directory.
 }
 
 Any help
 
 Mimi



for starters you might want to look at the  operator:

while(  ) {
}

Will read each file on the command line in sequence, saves you thinking
about it.

If it is Unix it is case sensitive,  is this your problem?

Are you actually in the directory?   `bin/myscript.pl bin/ABC.txt`



Re: 3270 connection via perl

2008-05-29 Thread Ken Foskey
On Thu, 2008-05-29 at 15:23 -0500, jm wrote:
 does anyone have a sample script for a 3270 connection  via perl?
 i've read all i can find for the x3270, x3270-script, c3270, etc. but
 i can't quite wrap my head around how the scripting should work.  i've
 done telnet connections with Net::telnet so i am familiar with the
 basics but i can't find anything as 'straightforward' for 3270
 connectivity.
 
 thanks for any and all help,
 joe

I assume you have http://search.cpan.org/

A couple of suggestions:

There is openmvs which is a unix shell.  This might give you the
ability to script then push the data down to the server.

There is the ability to run web applications on MVS so this might be an
easier option.

You could connect via LU6.2 and have a conversation rather than trying
to scrape screens.  I don't know how, just giving you something to think
about and ask about.

Can you remotely connect to the database and avoid the applications?


Ken


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: how does file gets send to remote machine using perl

2008-05-29 Thread Ken Foskey
On Thu, 2008-05-29 at 19:46 -0400, Richard Lee wrote:

 Hi,
 
 Someone wrote a perl script which manipulate a file and sent to number 
 of remote system.
 I ported that exact script to my local machine but I don't see anything 
 going out.
 Peeking into the script, I see no special module being used and no 
 ftp/sftp/scp or anything like that being used.
 
 Does perl have the ability to transfer file?
 I guess I need to understand networking in general when it comes to 
 programming(i have no idea).
 
 Any idea or pointer would be greatly appreciated.
 
 thanks.(cannot cp and paste work script here since it's company's policy)


No Perl cannot send a file.

Based upon NO information.  Look for 'scp' or 'ftp' commands imbedded in
the application.




DBI question

2008-05-21 Thread Ken Foskey

I have a program that will run literally for days and days.  It monitors
logs by file tail.  Problem is that I think the DBI is causing problems.
It is constantly connecting and reconnecting to DB2 for every
transaction.

What I would like to do is block the subroutine and check the DBI
connection for being 'valid' still and then if it is not valid,
reconnect, sleep then try again for N times then give up entirely
issuing message to support.

I saw mention of a state variable but this not on the connection.   Any
help to make this work would be appreciated.

Thanks
Ken


Re: DBI question

2008-05-21 Thread Ken Foskey
On Wed, 2008-05-21 at 23:53 +1000, Ken Foskey wrote:
 I have a program that will run literally for days and days.  It monitors
 logs by file tail.  Problem is that I think the DBI is causing problems.
 It is constantly connecting and reconnecting to DB2 for every
 transaction.

The original did not make much sense reading it back.

I want to redesign the application to have an open connection
permanently.  Problem is that I don't trust it,  what happens if DB2 is
shutdown for instance.   I have to recover the connection.  Problem is I
cannot figure out how to check the connection is still OK without
calling something an have it fail.

What I would like to do is replace my connect subroutine with a grab a
cached DBI handle,  check it is still connected and if it is not
'actually' connected,  ie crashed,  then reconnect it an return the new
DBI handle.

Anyone know of a way to tell that a handle is still valid?

Ken


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Opening a File in its Native Application

2008-04-25 Thread Ken Foskey

On Fri, 2008-04-25 at 10:09 -0700, Lynn Etheredge wrote:
 Hi,
 I would like to create a button on a web page that opens a file in
 it's application (ie. open a scientific file in it's native
 application).  My file does not have an extension and so I think it
 probably will not open automatically with the system(start docname)
 command.

The start by extension is a feature of the DOS shell.  You can start any
program that way.

start myprog  filename

Ken


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: problem with the script in counting

2008-04-05 Thread ken Foskey
On Sun, 2008-04-06 at 05:39 +0530, pradeep reddy wrote:


 Can this impletemented in shell script alsso?

Why do you ask this in a perl list?

look at `uniq -c`.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: dinamic cgi with perl

2008-04-03 Thread ken Foskey
On Wed, 2008-04-02 at 17:19 +0200, Pau Marc Munoz Torres wrote:

 Hi
 
 is  There  some easy-understanding how to use ajax with perl tutorial
 somewhere?
 
 i just need to know how to do a cgi script to launch a prompt (javascript)
 and use the answer in my script


I learnt AJAX from Mastering Ajax tutorial in developerworks

http://www.ibm.com/developerworks/library/wa-ajaxintro1.html

There is also a module cgi::ajax in CPAN that you might want to look at.


-- 
Ken Foskey
FOSS developer


Re: Perl Stops Processing

2008-04-03 Thread ken Foskey
On Wed, 2008-04-02 at 10:19 -0700, inthepickle wrote:

 Really quick question.  In Perl, if I open a file in notepad
 system( notepad.exe $file ) ;
 Perl stops processes and will not continue until I close notpad.
 How can I open the file, and have Perl continue running?


Look up start in the command shell.   

http://www.ss64.com/nt/start.html

-- 
Ken Foskey
FOSS developer


Re: how do check th argument is passing to running file

2008-03-24 Thread ken Foskey
On Mon, 2008-03-24 at 17:46 +0530, sivasakthi wrote:
 Hi all,
 
 How we can check the argument is passing to the running file or not?
 
 #sample.pl 2008 03
 
 i want to check the two arguments of 2008  03 is passed to sample.pl or
 not..


if( defined $ARGV[1] ) {
die Two arguments required\n  sample.pl   mm;
}

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: diff of two files

2008-03-20 Thread Ken Foskey
Sounds like homework not a genuine work query.

On Thu, 2008-03-20 at 15:14 +0530, [EMAIL PROTECTED] wrote:
 Hi All,
 
 Can somebody please help me on this???
 
 Regards,
 Irfan
 
 
 -Original Message-
 From: Sayed, Irfan 
 Sent: Monday, March 17, 2008 7:52 PM
 To: beginners@perl.org
 Subject: diff of two files
 
 Hi All,
 
  
 
 I want to compare the two files in Perl. The requirement is that file 1
 has 20 lines and file2 has 25 lines . I want to see only five lines as
 output which are there in file2 not in file1 as I know that rest of the
 20 lines are same in both the files.
 
 I am using the following commands 
 
  
 
 Diff /tmp/dev_path_PRS.DB.01.12.000 /tmp/dep_path_D.PRS.DB.01.12.000.8
 
  
 
 As per my understating I should get 5 lines as output
 
  
 
 Could you please help in getting exact result.
 
  
 
 Please help
 
  
 
 Regards,
 
 Irfan
 

Here is a micro spec,  if you show your perl code you might get help.

If you want unique lines simply sort the two input files and read them
together.  if the records match then read another pair,  if they don't
then output the lesser value of the two,  read appropriate file and
retry.

Good luck
Ken


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How to make all files in one directory to an array

2008-03-20 Thread Ken Foskey

On Thu, 2008-03-20 at 18:20 +0530, sivasakthi wrote:

 Hi all,
 
 How to form array by using the files available in particular directory ?
 
 for example, /tmp contains the following files..
 
 #ls /tmp
 example.txt 
 file1.txt
 file2.txt
 file3.txt
 sample.txt
 www.txt
 zzz.txt
 
 i want to take all the above files in to one array? how to do that?


Off the top of my head:

chdir( '/tmp' );
@files = glob('*');

perldoc -f glob


Re: xml::twig help

2008-03-18 Thread ken Foskey
Updated to fix memory problem, you have to purge.   Takes over 30
minutes for 120K records.

I am sure that  the whole process can be done better with a good
understanding of the module.  Will benchmark XML::Rules though.

On Tue, 2008-03-18 at 00:55 +1100, Ken Foskey wrote:
 I am extracting addresses from an XML file to process through other
 programs using pipe delimiter the following code works but this is going
 to get 130,000 records through it it must be very efficient and I cannot
 follow the documentation on the best way to do this.
 
 After this simple one is programmed I have to change a much more complex
 version of this program.
 
 #!/usr/bin/perl -w
 # vi:set sw=4 ts=4 et cin:
 # $Id:$
 
 =head1 SYNOPSIS
 
 Extract addresses from an XML file into pipe delimited file.
 
usage: address_extract.pl  xml_file
 
 =cut
 
 use warnings;
 use strict;
 
 use XML::Twig qw(:strict);
 
 sub no_pipe
 {
 my $value = shift;
 
 $value =~ s/\|//g;
 return $value;
 }
 
 if( ! -f $ARGV[0] ) {
 print $ARGV[0] is not a filename, requires filename as first
 parameter!\n;
 }
 
 my $sort;
 my $sort_file = $ARGV[0].'.unsorted';
 unlink $sort_file; # in case of rerun
 open( $sort, '', $sort_file  ) 
 or die Unable to open $sort_file for output $!;
 
 my $ref = XML::Twig-new( twig_handlers={mem=\member} ) 
 or die Unable to open $ARGV[0] $!;
 
 my $member = 0;
 
 $ref-parsefile( $ARGV[0] );
 
 sub get_value
 {
 my ($mem_ref, $key) = @_;
 my @array = $mem_ref-descendants( $key );
 return $array[0]-text();
 }
 
 sub member {
my ($twig, $mem_ref) = @_;
 $member++;
 
 my $mem_no = get_value( $mem_ref, 'member' );
 my $add1   = get_value( $mem_ref, 'add1' );
 my $add2   = get_value( $mem_ref, 'add2' );
 my $add3   = get_value( $mem_ref, 'add3' );
 my $suburb = get_value( $mem_ref, 'suburb' );
 my $state  = get_value( $mem_ref, 'state' );
 my $pcode  = get_value( $mem_ref, 'pcode' );
 
 print $sort join( '|', $member,
  $mem_no,
  no_pipe( $add1 ),
  no_pipe( $add2 ),
  no_pipe( $add3 ),
  no_pipe( $suburb),
  $state,
  $pcode,
 ) .\n;
$twig-purge;

 return 1;
 }
 
-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: xml::twig help

2008-03-18 Thread ken Foskey
For the record on a more complex script than the address one...

xml:simple   7 hours plus on very quick machine, still running and
absolutely hammering the system, 1.3 Gig of memory used.

xml::twig  1 hour on laptop (underpowered and not much memory), Linux
still usable while running.

Definitely worth the time learning XML::Twig.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




xml::twig help

2008-03-17 Thread Ken Foskey

I am extracting addresses from an XML file to process through other
programs using pipe delimiter the following code works but this is going
to get 130,000 records through it it must be very efficient and I cannot
follow the documentation on the best way to do this.

After this simple one is programmed I have to change a much more complex
version of this program.

#!/usr/bin/perl -w
# vi:set sw=4 ts=4 et cin:
# $Id:$

=head1 SYNOPSIS

Extract addresses from an XML file into pipe delimited file.

   usage: address_extract.pl  xml_file

=cut

use warnings;
use strict;

use XML::Twig qw(:strict);

sub no_pipe
{
my $value = shift;

$value =~ s/\|//g;
return $value;
}

if( ! -f $ARGV[0] ) {
print $ARGV[0] is not a filename, requires filename as first
parameter!\n;
}

my $sort;
my $sort_file = $ARGV[0].'.unsorted';
unlink $sort_file; # in case of rerun
open( $sort, '', $sort_file  ) 
or die Unable to open $sort_file for output $!;

my $ref = XML::Twig-new( twig_handlers={mem=\member} ) 
or die Unable to open $ARGV[0] $!;

my $member = 0;

$ref-parsefile( $ARGV[0] );

sub get_value
{
my ($mem_ref, $key) = @_;
my @array = $mem_ref-descendants( $key );
return $array[0]-text();
}

sub member {
my ($t, $mem_ref) = @_;
$member++;

my $mem_no = get_value( $mem_ref, 'member' );
my $add1   = get_value( $mem_ref, 'add1' );
my $add2   = get_value( $mem_ref, 'add2' );
my $add3   = get_value( $mem_ref, 'add3' );
my $suburb = get_value( $mem_ref, 'suburb' );
my $state  = get_value( $mem_ref, 'state' );
my $pcode  = get_value( $mem_ref, 'pcode' );

print $sort join( '|', $member,
 $mem_no,
 no_pipe( $add1 ),
 no_pipe( $add2 ),
 no_pipe( $add3 ),
 no_pipe( $suburb),
 $state,
 $pcode,
) .\n;
return 1;
}



Re: dinamic cgi with perl

2008-03-14 Thread Ken Foskey

On Fri, 2008-03-14 at 15:14 +0100, Pau Marc Munoz Torres wrote:


 To solve it i was thinking on introduce a javascript code into my cgi, but i
 don't know how to pass the variable info between perl and javascript.


AJAX - I ended up hand coding my AJAX from scratch but there is a module
that I have not tried yet  CGI::AJAX,   http://search.cpan.org


Re: How do I get the contents of a url?

2008-03-12 Thread ken Foskey
On Wed, 2008-03-12 at 17:00 -0400, Jonathan Mast wrote:
 How do I get the contents of a url?  I mean passing a url to whatever object
 and receiving the content of that webpage as a scalar.
 
 I have a web service I want to test with perl, but I can't seem to find the
 right command or module to this despite looking quite a bit.
 
 thanks

use WWW::Mechanize;

Look it up on http://search.cpan.org

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: FTP server

2008-03-08 Thread ken Foskey
On Thu, 2008-03-06 at 22:48 +0200, Octavian Rasnita wrote:

 Thank you. I have it already installed and active, but I thought it is just 
 a way of transfering the files by FTP using SSL, using the 
 usernames/passwords of the OS, which I don't want.
 
 I want to be able to set a different set of usernames/passwords than those 
 of the system. Is it possible?
 Thank you.

If the remote user creates a key you can add that key into a userid on
the receiving box.

scp myfile.txt  [EMAIL PROTECTED]:/my/directory/path

http://polishlinux.org/apps/ssh-tricks

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Are comments allowed before package declarations in modules?

2008-02-26 Thread ken Foskey

On Tue, 2008-02-26 at 12:35 -0500, Jonathan Mast wrote:
 I seem to have a vague memory about Perl not allowing comments before
 program statements, but I'm not sure.  I really want to add a lot of
 comments at the top of a rather large module, but I'm unsure if thats safe.

The perl best practices book recommends that the documentation (POD)
appears at the end of the module.  I don't personally like this
recommendation because it makes it easier for the programmer to forget
to maintain the documentation.

-- 
Ken Foskey
FOSS developer



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How to get error?

2008-01-14 Thread Ken Foskey

On Mon, 2008-01-14 at 02:48 -0800, [EMAIL PROTECTED] wrote:
 Hello.
 I have cgi script and sometimes it fails. I get Internal Server Error
 in my browser.
 When i run perl -c script.cgi  i get syntax ok.
 It is runtime error. But how to know what is the error? How can i make
 the error is shown in bworser window? Or where are error logs stored?

I find that this is caused by the failure to put out CGI headers
properly and Apache then says that it is not formed correctly.

Search your apache log and find the actual messages.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Controlling external I/O with Perl

2008-01-13 Thread Ken Foskey

On Sun, 2008-01-13 at 10:28 -0700, Joseph L. Casale wrote:
 I have a need at work to monitor external I/O from a PC. Basically I
 need to turn outputs on and off and monitor some various inputs for
 different ranges. Since I know *some* Perl and the PC won't be doing
 anything else I am not worried about making sure the code is
 enterprise scalable. Is there any direction anyone can point me to
 start my reading into such a requirement? Additionally if anyone knows
 of any external hardware with a Perl API that exists, that would be
 great!

There are multiple solutions to this.

Are you using Windows or Unix or other operating system.

What type of IO are you using?  Serial,  parrallel, etc.

The answers will probably come from http://search.cpan.org

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How to select from a popup_menu without clicking submit?

2008-01-07 Thread Ken Foskey

On Mon, 2008-01-07 at 08:46 +, Marcus Claesson wrote:
 Hi!
 
 I wonder if there is any way in Perl CGI that you can select an item in
 a popup menu and execute a command WITHOUT having to click a submit
 button? For instance, this is what I want to do:
 
 I have a popup_menu with names of several values.
 print $cgi-popup_menu(-name='list',
   -id='list',
   -values=['L1','L2','L3']);
 
 As soon as the user selects a value I want it to be automatically
 printed out.
 
 if ($cgi-param('list')) {
print Selected value: .$cgi-param('list');
 }
 
 This is a very basic thing if you allow a submit button, but I don't
 want to do that. Any ideas?


This might be CGI::Ajax.   I have hand coded my ajax so far, it requires
javascript knowledge and a real clue stick (mastering ajax on
developerworks was my starting point).

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How to select from a popup_menu without clicking submit?

2008-01-07 Thread Ken Foskey

On Mon, 2008-01-07 at 12:06 +0100, Varjú Tamás wrote:
 This is exactly the point.  Javascript is run in the browser (remotely)
 while the perl script is run on the server (locally).  AJAX is the
 technique to make this two communicate without submitting the whole
 form.
 
 Tamas Varju
 
 2008. 01. 7, hétfő keltezéssel 11.01-kor Marcus Claesson ezt írta:
  Thanks for that, but from what I've heard it should be solvable using
  Javascript event handlers. I just don't know the details of how to use
  it successfully. I tried the following but got no result:
  (if this IS the way forward I'd need the onChange (or similar) handler
  to point to a 'Perl event' and not a 'Javascript event'...)
  
  print $cgi-popup_menu(-name='list',
 -id='list',
 -values=['L1','L2','L3']),
 -onChange=alert('TESTING');
  
  /Marcus

To add to that.

AJAX uses javascript same as the above to insert it's calls.

I use AJAX for things like when the customer changes in the drop box I
use AJAX to query the database on the server and replace another drop
box on the browser (product codes specific for that client).

It looked to me that you wanted to track what the user was doing and
report centrally on the server.  If that is the case then you must bring
that information back somehow AJAX is just one way of doing this.

What are you actually trying to achieve?
What do you know up front?
How much does information change?

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Ftp to GDG dataset

2007-10-11 Thread Ken Foskey

On Thu, 2007-10-11 at 23:05 +0200, Jenda Krynicky wrote:
 From: Johnson, Reginald \(GTI\) [EMAIL PROTECTED]
  I am trying to ftp files to GDG dataset on a mainframe. Whenever I try
  this my put fails with 
  failed Requested action not taken: GDG name  conversion failed
  
  
  #!/usr/bin/perl
  use File::Copy cp;
  use Net::FTP;
  snipped
  $ftp-put($logfile ,SM.SCS.ADSM.LINUX.ACCTLOG(+1) )
  or die put of $logfile failed , $ftp-message;
 
 All I can think of is that the file name is not legal on the 
 mainframe. Though the message looks a bit strange for that. Could you 
 try to uploadthe file with some simpler shorter name?
 
 If that doesn't help, ask the mainframe admins and/or come back and 
 tell us what kind of mainframe it is. (No, it will not be of any use 
 to me, but maybe there's someone around here who does have some 
 experience with those mainframes.)

Is your gdg base properly defined?

Have you set the site command to specify the correct line lengths?

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How to insert data onto an existing XML file

2007-10-03 Thread Ken Foskey

On Wed, 2007-10-03 at 00:42 +0800, Steven Sim wrote:
 Gurus;
 
 Sorry if this is not the proper forum.
 
 I've successfully written a Perl script to create a specific XML file.
 
 The problem comes when I attempt to run the script again and append XML 
 entries onto the XML file.
 
 Using XML::Writer, I am unable to perform a proper append. (The append 
 IO is successful but it breaks the XML syntax.)

Design problem more than a programming problem.  Had similar issue with
RSS feeds,  simple approach was to append the XML segment onto the
bottom of the file and then create a new 'working' file by simply
concatenating the main file with the trailer:

File 1

head
record value=1/
record value=2/

File 2

/head

You can append record value=3/ to file 1 and then concat File 1 and
File 2 to create the actual final XML file.  In our case creating the
final static file in the web browser.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Limiting a program to a single running instance

2007-10-03 Thread Ken Foskey

On Wed, 2007-10-03 at 13:34 -0700, Mark Wagner wrote:
 I've got a Perl program that is run once an hour as a cron job.
 Normally it finishes its task in about ten minutes, but occasionally
 it takes more than an hour to complete.  When this happens, a second
 copy is started, the two copies step on each others' toes, and both
 crash.
 
 I'm looking for the second copy to know that another copy is running
 and exit after logging a message to that effect.  Any method needs to
 work properly if the first copy crashes rather than exiting cleanly.

http://search.cpan.org/~elizabeth/Sys-RunAlone-0.07/lib/Sys/RunAlone.pm

Another design for this sort of thing is a mutex.  There are a few
modules for this.  This means you can lock out smaller parts of code and
keep two copies running concurrently doing different work.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Strange error

2007-09-25 Thread Ken Foskey
 500 Server Error
 [Mon Sep 24 21:00:38 2007] [error] [client ::1] (2)No such file or
 directory: exec of '/Applications/MAMP/cgi-bin/backatcha-cgi' failed
 [Mon Sep 24 21:00:38 2007] [error] [client ::1] Premature end of
 script headers: backatcha-cgi

Why is there a hyphen not a dot?

backatcha.cgi

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Process ID

2007-09-24 Thread Ken Foskey
On Mon, 2007-09-24 at 05:13 +0530, Somu wrote:
 Thanks for the help. I did it using
 
  system tasklist  temp;
 
  open FH , temp ;
  statements..
 unlink (temp); #EOF

Consider this code snippet then, does this in one step.  I am writing
the output to a log only you can put all the logic into the loop.

open( $process, '|-', $command ) or croak Unable to create process
$command, $!;
while( $line = $process ) {
print $log $line;
}
close( $process );


-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: CSV file

2007-09-21 Thread Ken Foskey
On Fri, 2007-09-21 at 15:50 +0500, [EMAIL PROTECTED] wrote:
 There is a report that is generated from a script as a plain text file. I 
 need to take this output file as input for my script and join them and create 
 a CSV file and mail to me daily. How can I create CSV file with out using 
 modules. 
 
 Taking a sample report 
 
 Hostname  IP address  Physical Address.
 inxp1233   XXX.XXX.XXX.XXX Mac-address
 inxp1432   XXX.XXX.XXX.XXX Mac-address
 inxp1232   XXX.XXX.XXX.XXX Mac-address

A really simple solution is to substitute the spaces for comma:

$headings = ;  # read existing headings and discard
print Hostname,IP address,Physical address\n;
while( $details =  ) {
$details =~ s/\s+/,/;
print $details;
}

 If I am joining this with a ',' and saving renaming the text file to CSV will 
 help or is there any other way to do it?Also I need to bold the header in my 
 CSV.

CSV is comma separated variable.  It is a text format and therefore
cannot be 'bold'.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: PERL/LDAPS

2007-09-19 Thread Ken Foskey
On Tue, 2007-09-18 at 17:58 -0700, John Maverick wrote:
 Hello,
 
 I am trying to use LDAPS in one of my perl script and not able to get all
 required modules to install.
 I am doing this on Windows machine.

Are you using active state?  Are you using ppm and what packages did you
install?  What error messages have you got?

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: parsing csv-file for inserting in database

2007-09-17 Thread Ken Foskey
On Mon, 2007-09-17 at 13:34 -0700, Jonathan Lang wrote:

 Most of the replies have suggested using 'split( /\|/, $line )'.
 However, this ignores a potentially important aspect of common cvs
 file formats - well, important to me, anyway - which is the
 interaction between quotes, field delimiters, and newlines:

In this case I would use:

http://search.cpan.org/~hmbrand/Text-CSV_XS-0.31/CSV_XS.pm

I can then set the sep_char in new.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: parsing csv-file for inserting in database

2007-09-16 Thread Ken Foskey
On Sun, 2007-09-16 at 12:28 +0200, Ruprecht Helms wrote:
 Hi,
 
 how can I parse a csv-file where the entries are seperated with  | .
 The scripts later should put them into a mysql-database using dbi.

if it just splitting:

@data = split( /\|/, $line );

If you forget the backslash it will divide the output for every
character.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: unable to use perl script with post on university wireless network

2007-09-15 Thread Ken Foskey
On Sat, 2007-09-15 at 11:17 -0700, perllearner wrote:
 I am a little stumped as to what is happening, just a few hours ago, I
 was able to use the same script at home, however on a university
 wireless, the script just stalls, and even perl package manager gives
 a error 500.  I am a little confused on where to go from here, or how
 to circumvent this, I am using winxp professional with service pack
 2.  Does anyone know how I may be able to use a perl script with such
 a restriction?

Whenever I see differences like this I look for STDIN reads.  eg 

If you are on Unix hit Control-D to end input and see if that completes
the process.

Run the script in debugging to find out what it is doing:
perl -d script

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: want to make a list of all users connected to a network

2007-09-09 Thread Ken Foskey
On Sat, 2007-09-08 at 16:52 -0700, [EMAIL PROTECTED] wrote:
 How would I make a script that gets a list of all the computer names
 and ip addresses, internal 192.168..., of the computers attached to my
 wired network? Or is there a program that will do this already? Thanks

Probably a reverse DNS lookup.  I would start with a search.cpan.org on
DNS.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: spliting

2007-09-04 Thread Ken Foskey
On Tue, 2007-09-04 at 14:29 +0200, Pedro Soto wrote:
 Hi,
 I have a file with lines of 60 characters each. I would like to
 split every line into its 60 characters, but there is not any delimiter
 between them. Something like: ABCDEFGHIJK etc.
 Is there anyway to do it?

perldoc -f sysread

read 60 bytes of the file at a time.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Transform my algorithm in perl. Ideas?

2007-09-03 Thread Ken Foskey
On Mon, 2007-09-03 at 21:56 +0200, Shams Fantar wrote:
 Hi !
 
 I have a problem at which I have no solution.
 
 Here is the algorithm :
 
 If there is a file in this directory which is old likewise of 10 days, 
 to delete it or else, do nothing.
 
 Do you have ideas to say If there is a file which is old likewise of 10 
 days in perl?

Please post what you have done and we can help, otherwise there are many
sites on the Internet to hire a contractor for a small job.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: type comparison in perl

2007-08-31 Thread Ken Foskey
On Fri, 2007-08-31 at 15:08 -0400, Hunter Barrington wrote:
 is there a type() function in perl? i need to be able to test the 
 contents of an array and
 if (type($value)=='string' or type($value)=='int') {print i win;}

if( $value =~ m/^\d+$/ ) {
   print I am a number\n;
}

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Parsing qmail-qread data

2007-08-31 Thread Ken Foskey
On Fri, 2007-08-31 at 18:05 -0700, Chris E. Rempola wrote:
 I'm trying to parse qmail-qread data, but don't know how to find the 
 number of occurrences after a particular string.  Here is the data:
 
 +++ Beginning of data +
 28 Aug 2007 17:00:47 GMT  #8807850  41428  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
 
28 Aug 2007 17:00:47 GMT  #8807850  41428  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
  End of Data ++
 
 How would I make it look for the (#) sign and count every occurence of 
 the word(remote) below it?  So the script would know that 
 '[EMAIL PROTECTED]' sent 10 emails and that '[EMAIL PROTECTED]' sent 
 5 emails.  Any help appreciated.  Thank you.

caveat emptor, untested but gives you the idea

my $line;
my $count;
while( $line =  ) {
  if( $line =~ m/#\d/ ) { # hash and a digit
$count = 0;
while( $line =  ) {
   if( $line !~ m/remote/ ) last;  # exit first while loop
   $count++;
}
print Count $count\n;
  }
}

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Printing asterisks in screen

2007-08-25 Thread Ken Foskey
On Sat, 2007-08-25 at 16:36 -0300, Rodrigo Tavares wrote:

 if (($num1 = 1  $num1 = 30) 
 {
  for (my $i=1 ; $i  30 ; $i++)
   {
 while ($num1 == $i)
  {
   print *;
  }
   }
 }


Think in terms of values:  Use 6 instead of $num1 and think about what
it says.

if ((6 = 1  6 = 30)   # yes this works
 {
  for (my $i=1 ; $i  30 ; $i++)
   {
 while (6 == $i)  # infinite loop because $i does not change.
  {
   print *;
  }
   }
 }


-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




modification

2007-08-20 Thread Ken Foskey

I have a piece of code that I am assured works and I cannot see why it
would.  Code is supposed to force undefined, zero and all space to
numeric zero to stop printf being undefined.

foreach my $value (@array) {
if( ! $value or $value =) {
$value = 0;
}
}

Will this actually work, or as I suspect do nothing because $value is a
copy.

The root cause of the problem is that the array is read from a file with
a simple substr

  $array[0] = substr( $_, 256, 6 );

Despite documented standards some values are simply filled with blanks.

Then rebuilt with a printf %06d, $array[0]; and this causes a non
numeric warning.

Is there a 'better' way to do this.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: modification

2007-08-20 Thread Ken Foskey
Thanks all,

I did read that about for loops somewhere new there was something. I
wonder how many times I have corrupted stuff with the expectation of
having a copy?*

I always make that mistake 'if( $a = 10 ) {'  that is why I always 'use
warnings' and, most importantly, correct the code. Pet peeve is 'use
warnings' and then not cleaning them up.

-- 
Ken Foskey
FOSS developer

* Just because it is tested and has been in production does not mean it
is not wrong. :-)



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Array to Hash

2007-08-13 Thread Ken Foskey
On Sun, 2007-08-12 at 22:55 -0400, yitzle wrote:
 I got an array of values where the order is relevent, eg the ages of
 Alice, Bob and Charles, and I want to make a hash out of it. I got
 this code that does it:
   my %ages = (alice = $r[0], bob = $r[1], charles = $r[2]);
 Is there a more elegent way to do it?

This is not elegant in this example but it possibly is the answer you
are looking for.

  my %ages{ 'alice', 'bob', 'charles'}  = @r;

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Array to Hash

2007-08-13 Thread Ken Foskey
On Mon, 2007-08-13 at 07:47 -0700, Paul Lalli wrote:
 On Aug 13, 9:40 am, [EMAIL PROTECTED] (Ken Foskey) wrote:
  On Sun, 2007-08-12 at 22:55 -0400, yitzle wrote:
   I got an array of values where the order is relevent, eg the ages of
   Alice, Bob and Charles, and I want to make a hash out of it. I got
   this code that does it:
 my %ages = (alice = $r[0], bob = $r[1], charles = $r[2]);
   Is there a more elegent way to do it?
 
  This is not elegant in this example but it possibly is the answer you
  are looking for.
 
my %ages{ 'alice', 'bob', 'charles'}  = @r;
 
 I rather doubt the OP is looking for an answer that doesn't even
 compile.
 
 I can only assume you meant:
 my %ages;
 @ages{'alice', 'bob', 'charles'} = @r;

You are right.

Apologies, my work laptop went to god and waiting for repairs so I don't
have the sample code :-(.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: New to Perl

2007-08-10 Thread Ken Foskey
On Fri, 2007-08-10 at 08:39 -0500, Gladstone Daniel - dglads wrote:
 Good Morning all, 
 
 1) I am new to Perl 
 
 2) Running ActiveState Perl 
 
 3) Trying to find/install a module: Spreadsheet::WriteExcel
 
 4) Can anyone provide me instruction on: 
a) where and how I can get it? 
b) How to install it on my PC 


Perl package manager or ppm.  This is the ActiveState version of cpan.

http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/faq/ActivePerl-faq2.html
-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How to read a very large file??

2007-08-08 Thread Ken Foskey
On Wed, 2007-08-08 at 17:39 +0530, sivasakthi wrote:
 Hi Guys,
 
 I have  a very large  file. It may be contain 1lac lines..  also it
 length is increased in dynamically..
 Each time ( per 5 min) i need to read the contents from file  do some
 work ..  Suppose i have read the lines for first 5 min then  after some
 time it reads the  same line also , so it  take more time  it is a
 waste of time..

Look up File::Tail in CPAN.  If you are trying to follow the file as it
grows then this is what you want.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Detect Html

2007-08-08 Thread Ken Foskey
On Wed, 2007-08-08 at 11:59 +0530, kapil.V wrote:
 Hi,
 I tried this to see if the file is an html:
 perl -ne '!html.+?/html!s and print html\n' html.htm
 This does not work. What is the problem?

The html is rarely on the same line as the /html in a html file so
this will very rarely match.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Passing each of the files in a directory as parameter to the perl script

2007-08-08 Thread Ken Foskey
On Wed, 2007-08-08 at 22:26 +0200, Dr.Ruud wrote:

 You might be able to change this to creating (and filling) the files in
 a tmp directory, and move them to the processing directory once they are
 finished. Then there is no need to have those 0-bytes flag files. A bit
 like how a maildir works.

In most systems I have worked on the /tmp directory is a different file
system.  Sometimes the time taken to move the file from one file system
to another is significant enough to cause problems on a fully loaded
system.

This solution may break on systems under excessive load.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: customizing eof chatacter

2007-08-06 Thread Ken Foskey
On Sun, 2007-08-05 at 18:26 +0100, Jorge Almeida wrote:

 I have an interactive, shell-like, program. Some commands read a line
 from STDIN, or the whole STDIN (meaning until CTRL-D is pressed). Now I
 want to modify the program to have a batch mode. Commands would be read
 from STDIN (probably redirected from a file), as well as the data, if
 any. The problem is how to keep the data for several commands in the
 same file. One command would read a part of the data (as if it were the
 whole input), the next command would read the next part, and so on. But
 since some commands pass the input through the shell before using it, I
 can't just read a chunk until some special character is found and call
 it the whole stdin...
 Impossible task, probably...


It sounds like you want something similar to parameter handling,
generally this works on escalating files.  eg  /etc/myprog overridden by
~/.myprog overrridden by a specific options file and so on.

The trick is simply to read them in that order and then just use what is
left.  So if /etc/myprog sets key X and ~/.myprog changes key X to some
other value then the last one to change wins.  You just have to set them
up in the right order and it is not that hard.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




use of end

2007-08-06 Thread Ken Foskey

I have a script that must update the reconciliation system using a
module.

From a design perspective how safe is it to use DB2 updates in an END
block?

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: customizing eof chatacter

2007-08-05 Thread Ken Foskey
On Sun, 2007-08-05 at 13:21 +0100, Jorge Almeida wrote:
 Is there some variable that will do for a file what $/ does for a
 record?
 What I mean is that in
   $s=STDIN
 the value of $s depends on the value of $/, but in
   @arr=STDIN

You mention EOF and you mean EOL (end of line).  Since you know the
correct variable you have read
perldoc perlvar

I am not the expert however I recall reading something about using local
I am guessing something like this:

sub myfunction
{
   local $/ = \r; # I am a mac file!
   my $input;
   open( $input, '', MYMacFile.txt ) 
   or die Unable to open MYMacFile.txt $!;
   while( $input ) {
...
   }
   close( $input );
}


-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: automatically open ports

2007-08-04 Thread Ken Foskey
On Sat, 2007-08-04 at 02:47 +, [EMAIL PROTECTED] wrote:
 I'm sorry. I wasnt clear in my first post. A situation arises when my
 router gets restarted, the internal ip addresses of the computers in
 my home (192.168.1.100 and the like) are shifted around. Normally I
 have the router forward some ports to one of my computers for a few
 services that I like to have, like an ftp server.

Sounds like dynamic IP addresses, DHCP.

Rather than solve the changing configuration,  change the setup of your
machines.  My home system has two static IP's allocated one my major
machine and one my son's so I can easily control it with filtering
rules.

DHCP can also map the mac address (physical number for the network card)
to a specific IP address.  You might want to have a look at that.

In direct answer there is WWW:Mechanise that can connect to a web screen
and perform actions.  IF you want to reconfigure a router then it is
possible that you would connect to the router webserver and reconfigure
it.  I have to say I would not recommend this,  you have lag between
reboot and rebuild for a start.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Cygwin like Module in perl

2007-08-04 Thread Ken Foskey
On Sat, 2007-08-04 at 16:54 +0530, perl pra wrote:
 Hi Gurus,
 
 
 I want  to execute  some of the unix commands on windows, Presently we are
 using Cygwin to run unix commands on Windows.
 
 Now I need to convert all the shell scripts into perl scritp. Is there any
 module in perl which allows me to execute unix commands on Windows.

Cygwin virtually is Unix (yes there are differences, look up cygpath for
example Nd only use forward slashes in directories).  I run tests on
programs destined for Unix on windows all the time,  just write the code
the same and you will learn the very small differences.


-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: automatically open ports

2007-08-03 Thread Ken Foskey
On Fri, 2007-08-03 at 15:49 -0700, [EMAIL PROTECTED] wrote:
 Im not sure where to post this as Im really looking for the
 functionality not specifically that it have to be in the perl
 language.
 
 How would I make something that would automatically open the correct
 ports for a certain machine without my having to be at the machine
 goto 192.168.1.1 in a browser and open the ports manually? Can this be
 done easily?

I don't understand what you want.

a)  Do you want a process to be brought up at boot or automatically when
the port is addressed

b) You would like a system that is somehow brought up and closed
automatically before and after use?

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: FILEHANDLE problem

2007-08-02 Thread Ken Foskey
On Wed, 2007-08-01 at 15:51 -0400, Johnson, Reginald (GTI) wrote:
 I don't see what I am doing wrong here. I am trying to print to the
 filehandle LINOUT but nothing is being printed to the file.
 Ultimately I want to monitor the input file and when it is written to I
 want to take the update and put into another file for processing.

I found File::Tail dead easy and it has been running for months
monitoring transmission logs on our servers at work.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Problem with my code

2007-08-02 Thread Ken Foskey
On Thu, 2007-08-02 at 17:44 +0530, Mihir Kamdar wrote:
...
Have you run it in a debugger and seen what happens?

perl -d script

The snippet does not actually assign to %hash,  I assume it is in the
missing code but you should show a sample line from it.


 while (($key, $value) = each %hash)
  {
  print $OUT_FILE $value;
  }


I find this style more 'normal'.

foreach my $key (keys %hash) {
print $OUT_FILE $hash{$key};
}

Or even this to make code predictable:

foreach my $key (sort keys %hash) {
print $OUT_FILE $hash{$key};
}


-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: FW: Html within code

2007-07-29 Thread Ken Foskey
On Thu, 2007-07-26 at 20:42 -0400, Mr. Shawn H. Corey wrote:
 Tom Phoenix wrote:
  On 7/25/07, Johnson, Reginald (GTI) [EMAIL PROTECTED] wrote:
  
  open (OMARFILE, junk || die input file cannot be openned:$!\n);

The brackets are in the wrong place.

The other answers were just far to clever  cryptic.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: reading from a file

2007-07-24 Thread Ken Foskey
On Tue, 2007-07-24 at 12:44 +0300, Octavian Rasnita wrote:
 From: Jeff Pang [EMAIL PROTECTED]
  --- Octavian Rasnita [EMAIL PROTECTED] wrote:
  You may try the Unix 'tail' command and pipe the
  result to your Perl program.Like:
 
  tail -f access_log|perl -e
 I can do this, but in that case I don't know how to be sure that I don't 
 skip any line of the file.
 The condition is to not skip any line and to not get the same line twice.
 
 I tested the tail command in the command line using:
 
 tail -n 1 /path/to/file

tail -f is the follow option,  look it up man tail.   The solution you
propose you will eventually miss lines from the file,  tail -f wont.

I have used File::Tail successfully as recommended by Angerstein.  It
has run for months without issue or missing a beat.


-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: connect a database in remote server (can connect to the server via SSH)

2007-07-18 Thread Ken Foskey
On Tue, 2007-07-17 at 16:40 +, [EMAIL PROTECTED] wrote:
 Hi, All:
 I am a new to perl. My perl code need to connect to the database in
 the remote server, and I can login that server via SSH. Can anyone
 give me a hint about how can I do that? Many thanks.

There is a proxy module that you can use.

http://perltraining.com.au/talks/dbdproxy.pdf

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Fork()ing and CGI?

2007-07-17 Thread Ken Foskey
On Tue, 2007-07-17 at 00:44 -0400, yitzle wrote:
 I need some guidance...
 I'm thinking of writing a CGI script that someone can pass some data
 and set it running. The script may take a few seconds to run.
 Is it safe/correct/OK to have a CGI script fork, with one thread
 respondng with a HTTP response while the other thread does its work? I
 want the HTTP response to finish sending right away, and not have to
 wait for the script to finish.

I have done this and it works OK.

I used a second CGI that queried the log file stored on the server with
an auto-update flag.

Currently I am reading up on AJAX that seems to be the correct solution
to the problem and makes for some slick applications.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: Spreadsheet::WriteExcel problem with large file

2007-07-16 Thread Ken Foskey
On Mon, 2007-07-16 at 14:23 -0700, a_arya2000 wrote:
 I have like around 24K rows. Thank you.

Sounds like a design problem.   Use a database and connect the excel
spreadsheet to that data source.  Seems a lot easier.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: obtaining file properties

2007-07-14 Thread Ken Foskey
On Sun, 2007-07-15 at 01:05 -0400, Sam DeForest wrote:
 Hi folks,  noob here...
 
 Im looking to produce a script that will return to me some file properties in 
 windows.  I know for unix I can use 'stat'.  The only thing that comes close 
 (as i can find right now) is use of the Win32::File module.  However that 
 would just return the attributes.  Im looking to find size and create 
 date/time.  Could someone point me in a good direction so I can read into 
 further?
 I appreciate the help,

size is dead easy  -s filename

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Dynamically loading perl code

2007-07-13 Thread Ken Foskey
On Fri, 2007-07-13 at 08:37 -0400, Mr. Shawn H. Corey wrote:


 If you want to run scripts, you should use system().  See `perldoc -f 
 system`

or:

open( PROG, '|-', 'myscript.sh options' ) or die ...
while( PROG ) {
}
close PROG
if( $? ) {
   die I have failed;
}

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Global symbol $var1 requires explicit

2007-07-08 Thread Ken Foskey
On Sun, 2007-07-08 at 22:27 +0530, kilaru rajeev wrote: 
 Hi,
 
 Please explain me whats wrong with the following code as it is
 respondingwith the some errors.
 
 #!/usr/bin/perl -w
 use strict;

# Since you are use strict you must declare all variables before using #
them.  This prevents typos.

my ($var1, $var2);

 $var1 = 'Hello World'; # always wanted to do that :-)
 $var2 = $var1\n;
 print $var2;
 exit;
 
 output:
 Global symbol $var1 requires explicit package name at sample.pl line 3.
 Global symbol $var2 requires explicit package name at sample.pl line 4.
 Global symbol $var1 requires explicit package name at sample.pl line 4.
 Global symbol $var2 requires explicit package name at sample.pl line 5.
 Execution of sample.pl aborted due to compilation errors.
 
 Thanks,
 Rajeev Kilaru
-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Global symbol $var1 requires explicit

2007-07-08 Thread Ken Foskey
On Sun, 2007-07-08 at 15:43 -0700, Paul Lalli wrote:
 On Jul 8, 1:25 pm, [EMAIL PROTECTED] (Kilaru Rajeev) wrote:
  On 7/8/07, Ken Foskey [EMAIL PROTECTED] wrote:
   On Sun, 2007-07-08 at 22:27 +0530, kilaru rajeev wrote:
Please explain me whats wrong with the following code as it is
respondingwith the some errors.
 
#!/usr/bin/perl -w
use strict;
 
   # Since you are use strict you must declare all variables before
   # using them.  This prevents typos.
 
   my ($var1, $var2);
 
$var1 = 'Hello World'; # always wanted to do that :-)
$var2 = $var1\n;
print $var2;
exit;
  I have removed the *strict.*
 
 NO NO NO.  *Keep* 'use strict'.  *FIX* the errors!
 
 But, got the output like this:
 
  Name main::varl used only once: possible typo at sample.pl line 3.
  Name main::var1 used only once: possible typo at sample.pl line 2.
 
 Perl is telling you exactly what's wrong.  Why aren't you listening to
 it?  If you had kept `use strict`, and FIXED the errors by declaring
 the variables you intended to use, Perl would have instantly told you
 WHICH variables had the typo.  As it is, with only warnings enabled,
 all Perl can do is tell you that you have a possible typo on each of
 those lines, because it doesn't know which once you *meant* to use!
 
 
 To use an analogy I saw in comp.lang.perl.misc recently: `use strict`
 is like the Check Engine light in your car.  When it lights up, do you
 find and fix the problem with your car, or do you disconnect the wire
 that lets the light turn on?
 
 Paul Lalli

This exact error is why you use strict.

var1 is not varl  and it is incredibly hard to see with the wrong font.
If you declare var1 and then use varl then perl will error,  without
strict it will warn and you could miss the message (and the next when
value is undefined.  Then it goes into production and an untested path
happens.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: help with syntax using an if statement

2007-07-04 Thread Ken Foskey
On Wed, 2007-07-04 at 19:00 +0200, Martin Barth wrote:
 Hi
 
  if (($DeviceType eq Switch) || ($DeviceType eq Router) ||
  ($DeviceType eq Hub) || ($DeviceType eq Access point))
  
  
  what i would like to do is check each device type with where the first
  letter is uppercase or lowercase
 
 this should help:
 
 if( $DeviceType =~ m/^([Ss]witch|[Rr]outer|[Hh]ub|[Aa]ccess point)$/) { ...

Knowing systems:

if( $DeviceType =~ m/^(switch|router|hub|access point)$/i ) {

The i modifier is ignore case.

I think there is a word boundary \ and \ that might be useful rather
than ^$ as well.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Problem with runaway format

2007-07-01 Thread Ken Foskey
On Sun, 2007-07-01 at 05:40 -0400, Mathew Snyder wrote:
 I have a script which places data 4 levels deep in a HoHoHoH.  It grabs 
 tickets
 in our ticket system using the systems API and places attributes about each
 piece of activity into the hash. The has is called %tickets.  It looks like
 
 $tickets{action_creator}{ticket_customer}{ticket_number}{ticket_subject}.

This just looks wrong...  Looks like you are trying to create a sorted
group of tickets from the original data.

I personally would be using a Database,  loading it in if necessary and
then doing a simple select:

select action_creator, ticket_customer, ticket_number, ticket_subject
from my_table
order by action_creator, ticket_customer, ticket_number, ticket_subject

In fact the whole thing looks like a database application waiting to
happen.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Parsing a file within a jar file

2007-06-27 Thread Ken Foskey
On Wed, 2007-06-27 at 08:11 -0500, Daniel W. Hurn wrote:
 Does anyone have any suggestion on how to examine/parse a file within a 
 jar file?

jar is a java file and I think it is simply a zipped file.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Reading a particular line from a file

2007-06-20 Thread Ken Foskey
On Wed, 2007-06-20 at 17:12 +0530, Nath, Alok (STSD) wrote:
 Hi,
   Is it possible to read a particular line by line number ?
 
   For e.g reading line 3 from a file.
 
   I don't want to read each line and count.

No and yes. If it is genuine new random data then no.

If it is fixed length then you can calculate the position and then do a
seek to the position.  (record length +1) * record number (+2 for cr lf
line endings).

You can index before hand.  For example I have a sort process that reads
the file,  does a tell for the position of the records,  the index is
then manipulated and I can read the records in new order by doing a
seek.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Iterate through a hashref using XML::Simple (real post)

2007-06-15 Thread Ken Foskey
On Fri, 2007-06-15 at 14:08 -0700, [EMAIL PROTECTED]
wrote:
 Sweet Chas!
 
 My two cents is to check out XML::Twig at http://www.xmltwig.org/ .
 
 It's easy to get a grip on and well suited to reading attributes as
 well as elements in elements.

Looks interesting,  would this reasonably handle 70,000 statements
containing LOTS of details in them?   I need to process this statement
by statement but it would totally blow memory.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Removing decimal points

2007-06-10 Thread Ken Foskey
On Fri, 2007-06-08 at 19:52 +, ash wrote:
 Hello there!
 
 I need to remove decimal points from numbers. For eg 1.23 or 1.77
 would be just 1. Any suggestion is appreciated. Thank you.

$i = 1.77;
$j = int $i;
print $j;

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: CPAN and Windows

2007-06-01 Thread Ken Foskey
On Fri, 2007-06-01 at 20:38 +, ebarras wrote:
 I am _Very_ new to perl, and programing in general, so keep that in
 mind. I am trying to use some CPAN modules with ActivePerl, and I am
 having a difficult time of it. Is there a tool or something to
 integrate these modules into perl for windows?

Look for ppm Perl Package Manager and install with that.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Outlook CSV Parser

2007-05-30 Thread Ken Foskey
On Wed, 2007-05-30 at 13:34 +0530, Laxminarayan G Kamath A wrote:

 What I am expecting is help with the variant of the regex I used as the
 condition for while loop. I am sure If we modify that regexp a little
 bit, then we can just use it on the record like this :
 
 $_ = $record;
 @fields = /regexp/g;
 
 I tried a lot of different ways but just could not get the right
 regexp :-(. 

CSV is a horrible format.  Far too unreliable,  we have exported CSV
from excel that imported differently into excel.

Is there another option,  eg connecting to Outlook via a remote
connection?

Is there another format available?

I doubt a simple regex will do it if the CSV modules do not work.

What data do you have problems with?  Without samples there is nothing
we can do.


-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: RegEx again

2007-05-20 Thread Ken Foskey
On Sun, 2007-05-20 at 01:42 -0400, yitzle wrote:

 # Look in
 @list1 = qw/big bad blue ball/;
 @list2 = qw/box sand house/;
 @keywords = qw/brown black blue/;
 
 # Add a ^ and $ so the strings match fully
 push @search, qr/^$_$/ for ( @keywords );
 $searchRegEx = join '|',@search;
 print 1 if ( grep $searchRegEx, @list1 );
 print 2 if (grep $searchRegEx, @list2);

Problem is you need slashes.

print 2 if (grep /$searchRegEx/, @list2);

I also wonder why you did not use the simpler:

$searchRegEx = '^('. join( '|',@keywords ). ')$';


-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




overriding posix::uname

2007-05-18 Thread Ken Foskey

sub is_dev
{
my ($server, $host) = POSIX::uname();

if ($host eq aixmbk10) {
return 1;

I want to test this module in a test script.  SO I want to code the
various servers and check that it works.

Is there a way to override the call to POSIX::uname

Thanks
Ken


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: File Handling. Reading and Writting.

2007-05-15 Thread Ken Foskey

 It looks as if you're trying to edit a text file in place. Although
 that's possible for some simple cases, it's generally easier to use
 Perl's $^I functionality.
 

What is $^I?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Thoughts on comments

2007-05-15 Thread Ken Foskey
On Mon, 2007-05-14 at 02:16 -0400, Mathew Snyder wrote:
 Is it possible to use too many comments?  I'm looking at a script I wrote and
 think I may have made it less clear by trying to make it more clear.

Absolutely.

Commenting in a useful clear way I believe takes years to master.
Maintaining your own and other scripts will teach you the difference.
Note the following bad sample

# loop through each entry of the xyz table.
foreach my $key (sort keys xyz) {

It is also very important to document WITH your code.  Take the above
snippet and consider just changing the variable from non-specific to
problem domain, eg $key to $account.  It makes it clearer.

foreach my $account (sort keys xyz) {

Look to the code itself first, use real names and spell them in full.  I
have a production system where prefix is shortened to pfx, pref, prefx.
It is a nightmare to maintain.

Use paragraphing,  keep lines of code that go together with a blank line
above and below.

   something account related;
   
   something customer related;
   something else customer related;

   work out totals for the report;

Generally clearer code is more important than clearer comments.

Coding is a craft.  Simple to learn the basics, years of mastery to get
it right.

Ken


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: About a reg expression ?:

2007-05-13 Thread Ken Foskey
On Sun, 2007-05-13 at 10:49 +0800, 小楊 wrote:
 Does anyone know the following syntax's meaning or usage?
 
 Can anyone help me to understand this syntax? Or if available, can anyone
 provide me some useful example to understand more?
 
 Thank you all that help me.
 
 The syntax is as follow:
 
 */**a (?:black|grey|white) cat/*

Try this:

  * Regex Coach ( http://weitz.de/regex-coach/ )

Nice to explain how things work

-- 
Ken Foskey
FOSS developer

PS:  Thanks goes to http://perltraining.com.au/ for showing me this one.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: regexp ...

2007-05-12 Thread Ken Foskey
On Fri, 2007-05-11 at 10:46 -0700, oryann9 wrote:
  
  Funny I had to explain split /|/, $str returning an
  array of characters.
  
  -- 
  Ken Foskey
  FOSS developer
  
 
 Excellent Ken,
 
 thank you, but why the pipe | and how does this differ
 from ' ' or \s+.  I used Dumper and it showed the
 array of chars, but want to understand.

I took me a while to notice that the pipe is a meta character.  It is
matching an empty string or another empty string.  So /|/ is actually
equivalent to // or //

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: regexp ...

2007-05-11 Thread Ken Foskey
On Thu, 2007-05-10 at 15:32 -0400, Chas Owens wrote:
 On 5/10/07, oryann9 [EMAIL PROTECTED] wrote:
 snip
  Now I am trying to break up string into individual
  chars, but this does not seem to work:
 snip
 
 The idiomatic way is
 
 for my $chr (split //, $str) {
 }

Funny I had to explain split /|/, $str returning an array of characters.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




hash containing a hash, sorting keys help

2007-05-05 Thread Ken Foskey
I cannot get the syntax right for child lookup, Data::Dumper confirms
that I have the structure as I expect (logic may be totally wrong
though).  I going to do a webpage pstree command.

foreach my $child (sort keys( $parent{$pid} )) {
dump_process( $child );
}

Type of arg 1 to keys must be hash (not hash element) at ./visualise.cgi
line 46, near } )

Initial $pid is zero and the entry looks like this:

'0' = {
 'ntp' = 1,
 'hplip' = 1,
 '1' = 1,
 'klog' = 1,
 'cupsys' = 1,
 '101' = 1,
 'root' = 1,
 '117' = 1,
 'avahi' = 1,
 'user' = 1
   },


#!/usr/bin/perl -w
# vi:set sw=4 ts=4 et cin:
# $Id:$

=head1 SYNOPSIS
 
Provide a tree function of processes on a unix server
 
   usage: visualise.cgi user=username

=head1 DESCRIPTION

Use the PS command to generate a tree of commands on a Unix server.

=head1 AUTHOR

Ken Foskey

=head1 COPYRIGHT

Copyright 2007 Salmat

=cut

use warnings;
use strict;

use CGI qw(:standard);
use Data::Dumper::Simple;

my ( $line, $user, $pid, $ppid, $c, $stime, $tty, $time, $command);
my $indent = 0;

my %parent;
my %process;

my $user_selected = param('user');

sub dump_process
{
my $pid = shift;
$indent++;
my $spaces = substr( , 0, $indent );
print $spacesli$process{$pid}/li\n;
print $spacesul\n;
#foreach my $child (sort keys( $parent{$pid} )) {
#dump_process( $child );
#}
print $spaces/ul\n;
$indent--;
}

open( PS, '-|', 'ps -ef' ) or die Unable to run PS command $!;

$line = PS;  # ignore heading!

while( $line = PS ) {
chomp $line;

($user, $pid, $ppid, $c, $stime, $tty, $time, $command) = split( /
*/, $line, 8 );
if( ! $user_selected or $user_selected eq $user ) {
$process{$pid} = $command;
if( $ppid eq 1 ) {
$ppid = $user;  # group users commands under 1.
$parent{0}-{$ppid} = 1; # link up to top process.
}
$parent{$ppid}-{$pid} = 1; 
}
}

print Dumper %parent;

$process{0} = *nix if( ! $process{0} );

dump_process( '0' );

close( PS );



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: hash containing a hash, sorting keys help

2007-05-05 Thread Ken Foskey
On Sat, 2007-05-05 at 07:19 -0700, Tom Phoenix wrote:
 On 5/5/07, Ken Foskey [EMAIL PROTECTED] wrote:
 
  foreach my $child (sort keys( $parent{$pid} )) {
  dump_process( $child );
  }
 
  Type of arg 1 to keys must be hash (not hash element) at ./visualise.cgi
  line 46, near } )
 
 That's saying that you're giving the keys() operator a hash element,
 but it needs a hash. Is $parent{$pid} a reference to a hash? If so,
 you can dereference it as a hash:
 
 keys( %{ $parent{$pid} } )
 
 Now the argument to keys() is the hash whose reference was in $parent{$pid} .

Thanks,  I tried %$parent{$pid} and %($parent{$pid}) but not %{}.

Seems to work now.  Back to making this work :-)

Ta
Ken


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: file lists and diffs?

2007-05-04 Thread Ken Foskey
On Thu, 2007-05-03 at 22:40 -0400, Mathew Snyder wrote:
 I have been given a task of installing a piece of backup software, then 
 tarring
 up all of the associated files in order to automate the installation onto 
 other
 machines.  The only way I can think of doing this is to do an ls -l on / and
 then doing a diff after the installation and manually adding those files to a
 tar command.
 
 What I'd rather do is automate this using perl.  gather a list of the files,
 perform the installation, getting a list of the new files by way of a diff or
 some such and adding all those files to a tar command or some such.
 
 Has anyone done such a thing or know of a module I should look at to achieve 
 this?

You might want to look at the rsync command rather than rolling your
own.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: regular expression

2007-05-04 Thread Ken Foskey
On Sat, 2007-05-05 at 01:01 +0200, xavier mas wrote:
 HI list!,
 
 I have a file with labels and a small text inside. When this text is 
 different 
 of a pattern text (n, for instance), this label must be deleted, for 
 instance:
 
 labelf/label(more text)labeln/label(more text)labelmpl/label...
 
 (labels containing something different to 'n' must be deleted of the string.)
 
 How can I do this?

Looks like XML,  xml::simple may help.

Ken


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




really bad use of postfix

2007-04-28 Thread Ken Foskey

Just like to show how NOT to use postfix.  I have had a frustrating day
tackling this type of unreadable code.

 
   exec_rqst('stga2k_vps.pl',$FileNameIn) if ($a2kqual[4] eq
 VPS); 
   exec_rqst('stga2kif.sh',$FileNameIn)   if ($a2kqual[4] ne
 VPS);
 
 
  if ($a2kqual[4] eq VPS) { 
   exec_rqst('stga2k_vps.pl',$FileNameIn); 
  } 
  else { 
   exec_rqst('stga2kif.sh',$FileNameIn); 
  }
 

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: File::Basename issues

2007-04-28 Thread Ken Foskey
On Fri, 2007-04-27 at 11:16 -0700, Nishi wrote:
 Yes, its the cygwin perl to be blamed.
 Would setting the ACTIVESTATE environment variable help? before running the
 scripts that contain the basename usage?

Cygwin is a Unix environment emulated in Windows.  Paths on Unix are
done by slash  eg /data/scripts/xyz.pl,  this represents (typically) C:
\cygwin\data\scripts\xyz.pl.

To convert between Windows paths and cygwin paths use cygpath command
line tool,  may be a function in perl as well.

For paths to files you can use the cygwin UNC
paths.  //c/some/where/on/C/drive/xyz.pl or //server/share/directory

Activestate is a perl implementation that is straight windows if you
like.  This might be a better fit to your task.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: File::Basename issues

2007-04-26 Thread Ken Foskey
On Wed, 2007-04-25 at 17:15 -0700, Nishi wrote:
 Hi:
 
 The File::Basename from 5.8.0 doesnot work in Perl 5.8.2 or Perl 5.8.7. Is
 there any particular reason.

Are yhou using activestate or cygwin perl.  cygwin will do that because
the filename you provided is not a cygwin filename.  cygpath will
convert filenames if this is the case.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Perl error

2007-04-26 Thread Ken Foskey
On Wed, 2007-04-25 at 10:20 -0500, Kevin Viel wrote:

Thanks.  I have been using this program without problem for a while, 
 I'd like to say over a year, but I am not sure.
 
So, could it be that somehow the environment path variable relating 
 to perl had been changed?  Otherwise, I cannot account for the difference.


Your path to perl may have changed.  `which perl`

If you are running it straight up ./my.pl and check the first line.
Normally should be #!/usr/bin/perl.  If this is the case then talk to
your administrator about upgrading the version of perl on the machine to
a current version.  (It is a royal pain when you have different version
on different boxes)

Thanks
Ken


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Test of scripts with Test::More

2007-04-26 Thread Ken Foskey
On Tue, 2007-04-24 at 14:44 -0400, [EMAIL PROTECTED] wrote:
 Hi,
 
 Recently i wrote a perl module that includes package and a script.
 As part of the module sanity tests, I would like to run the script and verify 
 a success.
 For that, I am using Test::More and Test::Simple.
 Is there any recommendations how to do this?

under your programs create a t directory (t for testing) and add a
series of scripts to test your application as xyz.t.

My safemove module has the following test script.  I also have a check
to ensure that pod is coded in the modules.

#!/usr/bin/perl -w
# vi:set sw=4 ts=4 et cin:
# $Id: SafeMove.t,v 1.2 2006/04/24 02:43:07 foskey Exp $

=head1 NAME

SafeMove.t

=head1 DESCRIPTION

Ensure that the SafeMove module is functioning correctly.

=HEAD1 AUTHOR

Ken Foskey

=cut

# Libraries
use strict;
use warnings;

use Test::More;
use File::Temp;
use File::Basename;

use lib /apps/bin/modules;
use SafeMove;

my $handle;
my $filename;
my $filename2;
my $basename;
my @files; # for glob...


plan( tests=4 );   ## number of test coded.

($handle, $filename) = mkstemp( '/tmp/SafeMove.' );
($handle, $filename2) = mkstemp( '/tmp/SafeMove.' );
close( $handle );

SafeMove::rename_timestamp( $filename );

ok( ! (-f $filename ), $filename should not exist );

@files = glob( $filename* );

ok( @files == 1, $filename* should have one entry );


unlink( $filename );

SafeMove( $filename2, $filename );

ok( -f $filename, moving file to new file name );

mkdir( $filename2 );

SafeMove( $filename, $filename2 );

$basename = $filename2.'/'.basename($filename);
ok( -f $basename, Moving from file to directory );




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Mails should not go in SPAM Box

2007-04-12 Thread Ken Foskey
On Thu, 2007-04-12 at 18:56 +0530, Anish Kumar K wrote:
 Hi
 
 Mails which are send by the perl script are usually found in the SPAM or 
 JUNK as a result most of the mails are not seen by the recipient. Is 
 there any way in the perl script we can set some Magical Header :) by 
 which the mail goes to INBOX only. First of all can we do in the perl 
 script or is it something I need to do in my Mail server. Please help...

One of my clients implemented reverse DNS lookup and it stopped my email
going through.

email is generated from [EMAIL PROTECTED]  reverse DNS looks
up where the email is supposed to come from ie internal.mydomain.com.au
and it fails because this is not a public machine address.

Solution was to fiddle the email address to remove the machine name.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Dialog and Tempfiles in Perl

2007-04-11 Thread Ken Foskey
On Wed, 2007-04-11 at 12:09 -0300, Rodrigo Tavares wrote:
 Hello,
 
 I like to know, if exist anything as tempfile and

http://search.cpan.org/~tjenness/File-Temp-0.18/Temp.pm

 dialog program in Perl. 

http://search.cpan.org/~uncle/Dialog-0.03/Dialog.pod

There are many other better solutions like TK and GTK.  There is also
Windows modules as well.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Sorting dir output

2007-04-10 Thread Ken Foskey
On Tue, 2007-04-10 at 13:19 +0200, Craig Schneider wrote:
 Hi Guys
 
 How could I exec a 'dir' command on a dos system and put the output in
 an array, sort by date and the files that are older than 3 days be moved
 into a folder called 'history'

Look at module  File::Find  this should be able to help you.

For a simplification of the other process you can use opendir function
to read the files in a directory one by one and then issue the stat as
in the other answer.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How to source another perl-file into one

2007-04-08 Thread Ken Foskey
On Sun, 2007-04-08 at 12:15 +0200, Raphael wrote:
 Hi Users,
 
 I want to source another file (also a perl-script) into my one at the
 beginning. There are definitions which are to be loaded before executing
 the rest of the other script. In a shell-script, I can do it with .
 filename, and in perl?
 
 Thanks for any ideas and help.

Modules is what you are after.

create your subroutines or definitions that you want to use in a file
called xyz.pm  (xyz should be something meaningful)

use lib '/where/my/module/is/';
use xyz



-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: MS Word translation

2007-04-03 Thread Ken Foskey
On Tue, 2007-04-03 at 11:56 +0800, Jen mlists wrote:
 Hello,
 
 Would you please tell me what's the correct module for translating a
 word document to the plain text?Thanks.

There is a Perl Interface in OpenOffice.org that might be useful for
you.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Calling bash things inside perl script.

2007-04-03 Thread Ken Foskey
On Tue, 2007-04-03 at 10:33 +0530, Nath, Alok (STSD) wrote:
 Hi,
   Before starting my problem I just want to thank all the active
 members
   who had literally mentored me in learning perl.
 
   I have bunch of this bash scripts which has lot of functions.
   I wanted to call and use them in a perl script.I am not sure how
   to do this.I did a cpan search but did not find anything
 helpful.
 
   Any idea how to do this ?

look up dotsh  it has some ability to integrate shell and perl.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




zoned decimal

2007-03-26 Thread Ken Foskey
Is there a module that deals with zoned decimal from the mainframe '}'
is plus zero for example, after it is converted to ASCII?
Convert::IBM390 only seems to handle it in ebcdic format and it is
already mucked up before we get the file.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: perldoc -q How can I make my Perl program run faster?

2007-03-24 Thread Ken Foskey
On Thu, 2007-03-22 at 17:17 -0700, oryann9 wrote:

 So in general in a web environment with 8-12gb RAM,
 mod_Perl and a MySQL/Postgres backend, do you or
 people you know statically link libc.a?

My understanding is with mod_perl the perl is constantly loaded into
Apache,  not starting and stopping the perl instance would mean that the
static versus dynamic would not be a really great saving.

Whenever I see performance tuning I always look towards the code itself
first.   Always profile your code to find out where the time is really
spent if it is a real issue, if it isn't then don't waste your time
looking to tenths of a second spend it on answering another business
question that may make thousands of dollars.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: GUI with Perl

2007-03-17 Thread Ken Foskey
On Thu, 2007-03-15 at 23:33 -0400, yitzle wrote:
 TIme for a quick factoid about me: I'm running Perl off Cygwin. No
 Gnome installed here.

GTK is available on Windows, I am reasonably sure it is in cygwin as
well.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Question about system call

2007-03-13 Thread Ken Foskey
On Tue, 2007-03-13 at 02:29 -0400, Mathew wrote:
 I recently forgot about the unlink function and had been trying to
 remove files using the less efficient system call to run rm -f
 /path/to/files.  I found, however, that this didn't work at all.
 
 I've since replaced it with unlink and get the results one can expect to
 get so it isn't a matter of trying to find a way to get the former to
 work.  I'm just wondering what might have caused it to not work.

Spaces in the filename.  My most common problem.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: private method

2007-03-04 Thread Ken Foskey
On Sun, 2007-03-04 at 14:31 +0100, D. Bolliger wrote:
 Chas referred to a _convention_ - which does not enforce privacy. 
 IMO it's useful, otherwise it would not be widely used, and for example, 
 Test::Pod::Coverage would require subroutines starting with an underscore to 
 be documented. :-)

Never knew this one.  Very handy.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




  1   2   >