Re: Re: Comparing Directories

2004-06-23 Thread sudhindra k s
Hi 

Thanks. I tried this script. It compares the filenames within the directory very well. 
But i want to compare even the contents and report the differences between the files. 

Regards
Sudhindra
  


On Tue, 22 Jun 2004 LRMK wrote :
>
>This must do the STYLE="text-decoration: none; border-bottom: medium solid green;" 
>HREF="http://search.targetwords.com/u.search?x=5977|1job|AA1VDw">job but 
>there must be a more nice looking way of doing this
>
>
>Code
>___
>
>compare("c:\\program files","d:\\program files");  #Example call
>
>
>sub compare($$){
> my ($p1, $p2) [EMAIL PROTECTED];
>
>
> print "comparing $p1 with $p2\n";
>
> v Loading direcrory 1
> opendir(DIR1, $p1);
> my @dirList1 = readdir(DIR1);
> closedir(DIR1);
>
> v Loading direcrory 2
> opendir(DIR2, $p2);
> my @dirList2 = readdir(DIR2);
> closedir(DIR2);
>
> my %hash1;
> my %hash2;
> foreach my $item (@dirList1){
> $hash1{$item} = 1;
> }
>
> foreach my $item (@dirList2){
> $hash2{$item} = 1;
> }
>
>
>  Counting the items that are in Path 1
>but not in path 2
> my $c=0;
> foreach my $key (sort keys %hash1){
>
> if ($hash2{$key}!=1){
> #print "$key\n";
> $c++
> }
>
> }
> print "Number of items that are in $p1 but not in $p2 - $c\n";
>
>  Counting the items that are in Path 2
>but not in path 1
> $c=0;
> foreach my $key (sort keys %hash2){
>
> if ($hash1{$key}!=1){
> #print "$key\n";
> $c++;
> }
>
> }
> print "Number of items that are in $p2 but not in $p1 - $c\n";
>
>print "___\n";
>
>
> ### Comparing Sub
>directories
> foreach my $key (sort keys %hash1){
> if
>(($hash2{$key}==1)&&(isSubDirectory($p1,$key))&&(isSubDirectory($p2,$key))){
>
> compare($p1 . "\\" . $key, $p2 . "\\" . $key);
>
> }
> }
>}
>
>
>
>
> Sub to check whether an item is a valid
>sub directory of the given path
>sub isSubDirectory($$){
> my ($path, $item)[EMAIL PROTECTED];
> if ($item =~m/^(\.)+$/){
> return 0;
> }
> my $myItem = $path. "\\" . $item;
> if (-d $myItem){
> return 1;
> }else{
> return 0;
> }
>
>
>}
>
>
>
>LRMK
>- Original Message -
> From: "sudhindra k s" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Tuesday, June 22, 2004 1:24 PM
>Subject: Comparing Directories
>
>
>
>Hi
>
>I have two directories with a path as shown below
>c:\test\result\... and d:\test2\result2\...
>
>The directory stucture and files after these are the same. i.e if there is a
>directory xyz within c:\test\result\, there will be a corresponding
>directory xyz within d:\test2\result2\ with the file names also being the
>same.
>
>now i want to compare the contents of the directories and output the
>difference between the two if any. How can i acheive this?
>
>Regards
>Sudhindra
>
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
> 
>
>




Re: pattern matching

2004-06-23 Thread James Edward Gray II
On Jun 23, 2004, at 12:59 PM, [EMAIL PROTECTED] wrote:
OK. I am reading a file. This line is at the bottom of the
file and the "---**" is a sign that the section is  
complete.
This may be a sign that you aren't reading the file in the easiest  
possible way.  I wonder if setting the input separator to this sequence  
would be the way to go.  Something like:

local $/ = '---**';
I need to be able to pick up that line, and see if there is
also code on the beginning of that line that I need to save.
save( $1 ) if m/^(.+)\Q---**\E$/;
So in this case I was searching for words (with colon's)
and perhaps other code that precedes the ""
and to try and discard the end of the line. (After the word
FILING, there is a page break character, but it's all being
read in as one line.)
Is that a form feed character?  Is it the only one in the file?  You  
might be able to use that somehow.  Ideas:

local $/ = "\f";
# or ...
save( $1 ) if m/^([^\f]+)\f/;
# or ...
my $words = (split m/\f/, $your_line)[0];
This is a sample of the line:
Comment: FILING  
--- 
-

That's why I tried (and failed :>) with this:
if (/(\w+:?\s*\w*:?)+(.*?\*+\s*-+\s*\*+\s*)$/)  {
s/$2//;
}
I hope that helps.
Hopefully the above might give you some fresh ideas.
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: pattern matching

2004-06-23 Thread Murzc
>Would something like this do the trick?

 > $_ = $1 if /((\s*\w+:?)+)/;

True. But I need to test the line to see if it contains
those '*--**'. Otherwise how do I know that
the line needs to be edited.

(I am reading a file with many lines. I have to 
detect when the line comes with this pattern.
Words, colons,  a possible page break, followed by "---", as indicated in my 
earlier e mail.)

Thanks for the time
PS The reason I put .*? is I wanted to perform a non-greedy
match on everything from the words until the "*-".
i am suprised that that would be incorrect. 

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




RE: pattern matching

2004-06-23 Thread Bob Showalter
[EMAIL PROTECTED] wrote:
> Hi,
> 
> I have a string similar to:
> Comment: FILING
>
---
-
> 
> This is read in as one line (with the page feed).
> I was trying to whatever follows the words and I tried this.

Trying to remove?

> 
> if (/(\w+:?\s*\w*:?)+(.*?\*+\s*-+\s*\*+\s*$)/)  {
 ^^
 This is no good.
> s/$2//;
> }
> 

Would something like this do the trick?

   $_ = $1 if /((\s*\w+:?)+)/;

This captures "Comment: FILING"

HTH

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




Re: pattern matching

2004-06-23 Thread Murzc

OK. I am reading a file. This line is at the bottom of the 
file and the "---**" is a sign that the section is complete.

I need to be able to pick up that line, and see if there is 
also code on the beginning of that line that I need to save.
So in this case I was searching for words (with colon's)
and perhaps other code that precedes the ""
and to try and discard the end of the line. (After the word
FILING, there is a page break character, but it's all being 
read in as one line.)

This is a sample of the line:
Comment: FILING 


That's why I tried (and failed :>) with this:
if (/(\w+:?\s*\w*:?)+(.*?\*+\s*-+\s*\*+\s*)$/)  {  
s/$2//;
}

I hope that helps.

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




Re: pattern matching

2004-06-23 Thread James Edward Gray II
(Let's keep our discussion on the list for all to see.)
On Jun 23, 2004, at 12:44 PM, [EMAIL PROTECTED] wrote:

Let's try to get a little simpler with our approach.  Does >this grab
what you need?

m/(\W+)$/

James
What a quick response. Thanks.
No problem.
I assume you mean do this? Am I right?
m/(\W+)$/
s/$1//;
No, I don't mean that.  Perhaps I didn't understand what you needed.  I 
thought you wanted to capture the characters after the words.

Are you trying to remove them instead?  If so, use:
s/\W+$//
That would replace all non-word characters at the end of your string 
with nothing, deleting them.

If I'm still not getting it, try explaining your goal again.
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: pattern matching

2004-06-23 Thread James Edward Gray II
On Jun 23, 2004, at 12:34 PM, [EMAIL PROTECTED] wrote:
Hi,
I have a string similar to:
Comment: FILING
 
--- 
-

This is read in as one line (with the page feed).
I was trying to whatever follows the words and I tried this.
Let's try to get a little simpler with our approach.  Does this grab  
what you need?

m/(\W+)$/
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



pattern matching

2004-06-23 Thread Murzc

Hi,

I have a string similar to:
Comment: FILING


This is read in as one line (with the page feed).
I was trying to whatever follows the words and I tried this.

if (/(\w+:?\s*\w*:?)+(.*?\*+\s*-+\s*\*+\s*$)/)  {   
s/$2//;
}

I am getting errors as the program runs (Windows Perl 5.6.0)

The program bombs, displays $_ and then,
/: nested *?+ in regexp at etc. 

I tried taking out some of the pattern to pin point the error, and different errors 
happened.

Any suggestions?

Thanks

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




Re: Using MIME::Lite to send mail/or attachments

2004-06-23 Thread Wiggins d Anconia
> 
> Can anyone tell me where I can find MIME::Lite or any other perl
method to send attachments/documents in mail format? If you have tips or
scripts on using it to send mail (documents attached), please let me know.
>  

MIME::Lite can be found on CPAN with most other modules.  You can use,

perl -MCPAN -e 'install MIME::Lite' 

to have CPAN install the module.  If you are on Windows with ActivePerl
you should consider using ppm. 

MIME::Lite has standard POD documentation that you can raed with perldoc
after the module is installed, or on the web through the
http://search.cpan.org

HTH,

http://danconia.org

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




Using MIME::Lite to send mail/or attachments

2004-06-23 Thread jason corbett
Can anyone tell me where I can find MIME::Lite or any other perl method to send 
attachments/documents in mail format? If you have tips or scripts on using it to send 
mail (documents attached), please let me know.
 
Thanks,
JC



Re: Quoting a scalar in a substitution

2004-06-23 Thread James Edward Gray II
On Jun 23, 2004, at 11:23 AM, Richard Barrett-Small wrote:
Hello all,
Howdy.
Will really appreciate help with this: I'm pulling my hair out with 
this
one.

I have a list of contents in the @contents array and the script finds 
those
headings in the html and adds anchors to them. The trouble is, the
substitution won't match when there's a question mark in the content 
item:
Try:
m/\Qvariable_with_meta_chars\E/
The \Q ... \E construct escapes the meta characters for you so you get 
a literal match.  Hope that helps.

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



Quoting a scalar in a substitution

2004-06-23 Thread Richard Barrett-Small
Hello all,

Will really appreciate help with this: I'm pulling my hair out with this
one.

I have a list of contents in the @contents array and the script finds those
headings in the html and adds anchors to them. The trouble is, the
substitution won't match when there's a question mark in the content item:

I've quoted the pattern in the if loop but it won't work in a subtitution.
Clearly the question mark is being treated as a regex operator (0 or1)
rather than the literal. So, items 2 and 3 on the list below are not being
matched - how do I quote the scalar $item, question marks and all, in the
substitution below?

Contents list:

Background
Why China needed asset management?
The scope of operation for AMCs in China?
Ongoing AMC business in China
Asset management as part of China's overall financial reforms
The persistent problem of China's SOEs
Foreign participation in China's asset management sector
Conclusion
Information sources

Script:

foreach $item (@contents) {
if (q/$item<\/b><\/p>/) {

my $abbrev = $item;
$abbrev =~ s/(.).*/$1/;
$abbrev =~ s/ //g;
print "$item\n";


s/${item}<\/li>/$item<\/a><\/li>/;
s/${item}<\/b><\/p>/\n$item<\/a><\/span><\/p>/;

}
else { print "$item\n"; }
}



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




writing to a DOC

2004-06-23 Thread John
I have store a greek text in mysql database field.
Using my script i retrieve the greek text and then i store it in a file.doc.

When i email the file.doc (through MIME::Lite) i can open it with the Microsoft Word 
and then it asks me the encoding of the document.

I click on simple text and i can see the document with no problems.

My problem is the dialog (Office Word) that prompts me to click on the encoding,

Can i avoid it and Word recognise the ISO-88590-7 automatically?

Thanks in advance.

Re: open CONSOLE?

2004-06-23 Thread LRMK
For windows try this

sub executeTool($){
my ($toolPath) = @_;
my $comspec = $ENV{'COMSPEC'}; # Get the path to the command line
interpriter if this ENV var is not available in your system you will need to
hard code this part

open(TOOL, "$comspec /c $toolPath|");
my $result = ; # you will need to put this in a loop if the
too gives multiple lines of output
close(TOOL);
return $result;
}

if your too going to give multiple lines of out put you will need to make
some small changes






LRMK
- Original Message - 
From: "Randy W. Sims" <[EMAIL PROTECTED]>
To: "perl.org" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, June 23, 2004 3:59 PM
Subject: Re: open CONSOLE?


> perl.org wrote:
> > Hi,
> >
> > Is there a way to explicitly open a handle to the "console", or wherever
> > STDOUT/STDERR are directed to by default?
> >
> > My process is running in an environment in which STDOUT and STDERR have
> > already been redirected.  I want to intercept these streams when running
> > command line tools, then restore them afterwards.  I want to be able to
call
> > my command line tool like:
> >
> > my ${ret} = `command 2>&1`;
> >
> > and have ${ret} get the both STDOUT and STDERR.  This piece gets called
a lot
> > so I want to avoid temp files if I can.  This has to work on Windows if
that
> > makes any difference (I think that means no /dev/console, etc.).  I know
> > about:
> >
> > open( RESTORESTDOUT, '>>&STDOUT' );
> >
> > and I think I can restore the redirected STDOUT from there, but how to I
open
> > STDOUT so that it goes to the "console", as if it had never been
redirected?
> >
> > Hopefully this makes some sense.
>
> open( OUT, 'con' ); # IIRC
>
> I /think/ you can also use POSIX::fdopen() or IO::Handle::new_from_fd()
> to get the standard streams.
>
> Randy.
>
> -- 
> 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: open CONSOLE?

2004-06-23 Thread Randy W. Sims
perl.org wrote:
Hi,
Is there a way to explicitly open a handle to the "console", or wherever 
STDOUT/STDERR are directed to by default?

My process is running in an environment in which STDOUT and STDERR have 
already been redirected.  I want to intercept these streams when running 
command line tools, then restore them afterwards.  I want to be able to call 
my command line tool like:

my ${ret} = `command 2>&1`;
and have ${ret} get the both STDOUT and STDERR.  This piece gets called a lot 
so I want to avoid temp files if I can.  This has to work on Windows if that 
makes any difference (I think that means no /dev/console, etc.).  I know 
about:

open( RESTORESTDOUT, '>>&STDOUT' );
and I think I can restore the redirected STDOUT from there, but how to I open 
STDOUT so that it goes to the "console", as if it had never been redirected?

Hopefully this makes some sense.
open( OUT, 'con' ); # IIRC
I /think/ you can also use POSIX::fdopen() or IO::Handle::new_from_fd() 
to get the standard streams.

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



Re: warning with eval, not with inline

2004-06-23 Thread Randy W. Sims
perl.org wrote:
Given this piece of code (where ${components[${i}]} is 'email'):
eval
{
  my ${name} = 'IWAPI::ExternalTasks::' . ${components[${i}]};
  no strict;
  eval( &${name}( -files => [EMAIL PROTECTED], -area => ${area}, -wftask =>
${wftask}, -wfworkflow => ${wfworkflow} ));
  use strict;
};
This gives "Use of uninitialized value at" regarding the inner eval.  If I
change this to:
IWAPI::ExternalTasks::email( -files => [EMAIL PROTECTED], -area => ${area}, -wftask =>
${wftask}, -wfworkflow => ${wfworkflow} );
Then I do not get this message, but that would mean a big switch in my script
which I would prefer to avoid.  What would be happening differently when this
is invoked with eval that could cause this?  I am 100% certain that all of the
variables shown here are defined.  

Any clues would be greatly appreciated.
It's hard to tell without more context, but your inner eval looks like 
it should be of the form eval "STRING". I.E. put it in quotes. You'll 
have to figure out what needs to be escaped as there is not enough 
context for me to make a guess and I'm not familiar with IWAPI::*.

See `perldoc -f eval`
Randy.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: open CONSOLE?

2004-06-23 Thread Randy W. Sims
perl.org wrote:
Hi,
Is there a way to explicitly open a handle to the "console", or wherever 
STDOUT/STDERR are directed to by default?

My process is running in an environment in which STDOUT and STDERR have 
already been redirected.  I want to intercept these streams when running 
command line tools, then restore them afterwards.  I want to be able to call 
my command line tool like:

my ${ret} = `command 2>&1`;
and have ${ret} get the both STDOUT and STDERR.  This piece gets called a lot 
so I want to avoid temp files if I can.  This has to work on Windows if that 
makes any difference (I think that means no /dev/console, etc.).  I know 
about:

open( RESTORESTDOUT, '>>&STDOUT' );
and I think I can restore the redirected STDOUT from there, but how to I open 
STDOUT so that it goes to the "console", as if it had never been redirected?

Hopefully this makes some sense.
open( OUT, 'con' ); # IIRC
I /think/ you can also use POSIX::fdopen() or IO::Handle::new_from_fd() 
to get the standard streams.

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



Re: a way to make this more secured and better written?

2004-06-23 Thread Jason Gray
or would this be much better?

#!/usr/bin/perl -T

use strict;
use warnings;

use CGI();
use Mail::Mailer;

my $q = CGI->new();

# Email address where form submits are sent.
my $email = '[EMAIL PROTECTED]';

# Your subject for the form submits.
my $subject = '[INFO] Site Comment';

print $q->header();

foreach my $field(qw(name email city state message)) {
 if($q->param($field) =~ /^\s*$/) {
  print "Please fill in your $field.\n";
  exit;
 }
}

my $m = Mail::Mailer->new('sendmail');
 $m->open({From => $q->param('email'), To => $email, Subject => $subject,})
or die;
  print $m "Name: " . ucfirst($q->param('name')) . "\n";
  print $m "Location: " . ucfirst($q->param('city')) . ", " .
$q->param('state') . "\n\n";
  print $m $q->param('message');
 $m->close();

print "Thank you for contacting us.";



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




Re: The Proper way to define a global variable.

2004-06-23 Thread Chris Welch

> From: John W. Krahn wrote:  
> Jason Corbett wrote:
> > 
> > Hello. I am using variables that are local in my scripts by doing the my 
> > $variable_name technique.
> > 
> > Can someone tell me if there is an official way to define a global variable?
> 
> Perl doesn't really have "global" variables (like BASIC does), except
> for some of the special variables listed in perlvar.pod.  Perl's
> variables are either package or lexically scoped.

Can you not use our?



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




Re: cut and substitute

2004-06-23 Thread John W. Krahn
Amit Virmani wrote:
> 
> Problem:
> I have a field $cusip that has to change from ABC123-XX-7 (9 characters with '-') to 
> ABC123XX (first 8 characters only without '-')
> 
> I have following lines of code:
> :
> :
> $cusip =~ s/\-//g;
> $cusip =~/.${8}$/$1/g;
> :
> :
> 
> Is there a shorter way to transform this.

No, not really.  You can do it in one line though:

$cusip = join '', ( $cusip =~ /[^-]/g )[ 0 .. 7 ];


John
-- 
use Perl;
program
fulfillment

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




[Doubt] : Validate Printer Port

2004-06-23 Thread suresh.pasupula
Hi,

 

How to validate the given printer port?

I want to know if it is a TCP/IP or local port. If it is a TCP/IP Port
then I wan to validate if it exists (Raw port 9100).

Also I want to validate the format of IP-Address.

 

Could anyone let me know how can I achieve this?

 

Thanks and Regards

Suresh