Re: Problem with regex

2006-05-12 Thread Karl-Heinz Kuth

Hello,



my $Data = Hello, i am a litte String.$ Please format me.$$$ I am the end
of the String.$$ And i am the last!

The regex should replace $ with the string br, $$ with p and $$$ with
brbr (please don't think about the why)

If tried to use the following:
$data =~ s/\$\$\$/brbr/gm; #should catch every occurrence of $$$
$data =~ s/\$\$/p/gm; #should catch $$
$data =~ s/\$/br/gm; #the rest

So data should look after the first regex:
Hello, i am a litte String.$Please format me.brbrI am the end of the
String.$$And i am the last!
And after the second:
Hello, i am a litte String.$Please format me.brbrI am the end of the
String.pAnd i am the last!
And the last:
Hello, i am a litte String.brPlease format me.brbrI am the end of the
String.pAnd i am the last!

But all regexes i tried (the one above are only one try) failed! When i
print out the string it looks like:

Hello, i am a litte String. Please format me. I am the end of the
String.3398 And i am the last!

Where the number after String. differs between every run.

Can someone help me ?


This works at least on my machine:

use strict;
use warnings;

my $Data = 'Hello, i am a litte String.$ Please format me.$$$ I am the 
end of the String.$$ And i am the last!';


$Data =~ s/([^\$]*)\${3,3}([^\$]+)/$1\br\\br\$2/gm;
$Data =~ s/([^\$]*)\${2,2}([^\$]+)/$1\p\$2/gm;
$Data =~ s/([^\$]*)\${1,1}([^\$]+)/$1\br\$2/gm;
print Data: $Data \n;

___END___

Notice, I change the double quotes to single quotes for $Data.
For me, the regex is clear. But if not for you, I can explain.
There are maybe some better solution, this is just a quick one.

Regards
Karl-Heinz


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Problem with print function

2006-05-09 Thread Karl-Heinz Kuth

Timothy,


How about this:

print $char x $number_of_chars . \n  for 1..$number_of_lines;


that's another way to do it. Thanks for the hint. This looks a little 
more smarter than the other solution, but that's only my opinion. I find 
it more readable.


Thanks
Karl-Heinz

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Problem with print function

2006-05-09 Thread Karl-Heinz Kuth

Suresh,


  Why not use brackets?:
  
  print (($char x $number_of_chars . \n ) x  $number_of_lines, \n);


that's one way to do it. I did not set the outer brackets.  :-*

Thanks
Karl-Heinz

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Problem with print function

2006-05-08 Thread Karl-Heinz Kuth

Hi,

I've got the following problem:

use strict;
use warnings;

my $char = -;
my $number_of_lines = 3;
my $number_of_chars = 20;

print This is the output I want: \n;
my $line = $char x $number_of_chars . \n;
print $line x $number_of_lines, \n;

# I do not want to use the var $line. So how to write
# it in one statement?
# My try isn't correct.
print The output with 1 statement: \n;
print  $char x $number_of_chars . \n  x  $number_of_lines, \n;

Regards
Karl-Heinz

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: calling a external program

2005-11-02 Thread Karl-Heinz Kuth

Hi Markus,

I’m looking for a way to call an external program and get back the 
result in an array without seeing anything on the STDOUT.


If ‘m using in example

$path = “\\”;

$result = system(“dir”,  $path);

 

I can see the output on the STDOUT but I can’t find a way to put it in 
an array to make a post processing.


Only to forward the STDOUT to a file is a idea, but based on other 
reasons not useful for me.


The variable $result contain only the return code if the external 
program us supporting this.


try something like:

@output = `$externel_program 21`;
$return_code = ($? 8); # if needed

With 21 you will get STDOUT and STDERR in the array @output. 
Otherwise STDOUT would be ignored and you will only see it on the display.


Hope it helps
Karl-Heinz



___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Reading environment varible

2005-06-29 Thread Karl-Heinz Kuth

Dear Bill and the others,

You can't set $foo_token (or $foo_token_dir ) to $ENV{ FOO_TOKEN}. 
The value ot the variable has to be %%FOO_TOKEN%_DIR%.


What you set in the BAT file was :
FOO_TOKEN=BAR
BAR_DIR=c:\bar

So the only ENV vrbls available are FOO_TOKEN and BAR.
The %'s are used to indicate to the shell to interpolate.  eg:

%FOO_TOKEN% is interpolated to the value of 'FOO_TOKEN' env vrbl
which is 'BAR' so 'CALL SET %FOO_TOKEN%_DIR=c:\bar' sets 'BAR_DIR'
to 'C:\bar'


That's true, and the indirection is what I want! If I don't want
to use the inderection, I wouldn't ask.

It's a little bit complecated, but I think I have to explain it. 

I set  CALL SET %FOO_TOKEN%_DIR=c:bar in a cmd-file to declare 
directories I will use in my script. All directories are decleared in

that way. So if there are changing of the structure of your directory, you just
change it here.


Fine so you just set BAR_DIR to c:\bar - no problem so far


Correct, but that's not what I want.


You may ask, why don't you use a fix prefix like SET FOO_DIR=c:bar?
That's because, I want to be flexible. If someone has already used FOO_DIR
in his environment, you have a problem. So I want to be able to change 
the prefix in an easy way. 


No problem with the indirection.


Correct, because it's no problem, I want to use it that way.

In the script, I run the cmd-file, so that I have all the directories in an 
environment variable. In real life, it's not that easy to get them in the 
perl hash %ENV. But this should not be a part of the discussion.


Sure it is - whatever is in the output of set will also be in %ENV if
you immediately run a perl script.


You should execute the cmd-file before, so that the environment 
variables are set and perl can use them. I made this workaround to solve 
this problem, because it's the easiest way. In my real perl script I do 
it in the script, so that perl can use the env vars. A simple system 
call does not solve this. I can tell how I do it, but this is not part 
of the problem.


 So I read in the ini-file and it has the value %%FOO_TOKEN%_DIR%.
Now I want the other way back to get the name of the directory, in that 
case c:bar. 



Who's reading the ini file - perl or a bat script ?  If Perl is reading
it, it's not gonna work unless the script shells off the commands you
want to do next.  It the bat script does it, it would firsst have to break
up the two levels of indirection and do them one at a time as you did:


Sorry for that, perl is reading the ini-file via a perl module into a 
hash and I create an env var for every entry (for some good reasons). 
Later I can refer to the env var instead of the ini-file hash. This env 
variables will be placed in a perl variable later in the script, like 
the line

my $foo_token_dir = %%FOO_TOKEN%_DIR%;
In my original script I use an env var, that I created. The env var, 
that I use, has exact this value.


I know, that the shell interpolates the inderection and perl does not. 
But perl (so I) should do it! That's my problem.



I think we do - but I don't think you do.  ;)  You need to 'splain
more about how you get from ini file to scrip/bat file.


So the perl script does the following:
1) reads the cmd-file
2) set the env vars
3) reads the ini-fle
4) set env vars for every entry
5) Interpolate the indirection

Yes, you are right. I understand. Even the problem is hard to describe.

Thanks
Karl-Heinz

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Reading environment varible

2005-06-29 Thread Karl-Heinz Kuth

Hi,

first time I answer myself ;-). Here's my solution:

I cut off the cmd-file for the example and set the env var in the 
script. After all, the value of the env var %%FOO_TOKEN%_DIR% will be 
 created without using the env vars FOO_TOKEN or BAR_DIR directly.


The idea was to use the system command set and redirect the output of 
that statement. The analyse of the output is quite simple.


Thanks to Bill, who said, that the command set %FOO_TOKEN%_DIR works 
properbly in the shell.


Here is the script:

--- beginn ---

use strict;
use warnings;

# init
$ENV{ FOO_TOKEN }   = BAR;
$ENV{ BAR_DIR } = c:\\bar;
my $foo_token_dir   = ;
my @foo_indirect= ;
my $foo_token_value = ;
# end of init

# set the var as you like
$foo_token_dir   = %%FOO_TOKEN%_DIR%;
#$foo_token_dir   = %BAR_DIR%;

# main

$foo_token_dir =~ s/^%//;
$foo_token_dir =~ s/%$//;

# in real life, don't forget to check the index and the output!
@foo_indirect= `set $foo_token_dir 21`;
$foo_token_value = $foo_indirect[ 0 ];
$foo_token_value =~ s/^\s+//;
$foo_token_value =~ s/\s+$//;
$foo_token_value =~ s/([^=]+)=(.*)/$2/ ;

print foo_token_dir:. $foo_token_dir   . \n;
print foo_token_value:  . $foo_token_value . \n;

# end of script

Bye
Karl-Heinz

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Problem: Send Mail with MIME::Lite

2004-07-22 Thread Karl-Heinz Kuth
List,

if I start a script (code at the end of the mail) with a correct/incorrect
smpt server address I get the following output:

Output correct smpt-server address:
D:\tempperl -w send_mail.pl
Send mail...
OK - RC: 0

Output incorrect smpt-sever address:
D:\tempperl -w send_mail.pl
Send mail...
Failed to connect to mail server: Invalid argument

My problem: The script seems to die, but I don't want that. I want
that the script terminates correctly, because I want to set a special
returncode and write a logfile. So the output should be:
Send mail...
Error - RC: $?

Any suggestions? Is there a way to check the server before?

Environment: Win2000, ActiveState 5.6.1

Code of the script:

use strict;
use MIME::Lite; 

my $smpt_server = 'incorrect smpt-server';
# my $smpt_server = 'correct smpt-server';

my $from = 'from: address';
my $to = 'to: address';
my $subject = 'subject';
my $mailtext = 'mailtext';

my $mail_object = MIME::Lite-new(
From = $from,
To   = $to,
Subject  = $subject,
Type = 'Text',
Data = $mailtext);

print Send mail... \n;

if  ( $mail_object-send_by_smtp( $smpt_server ) ) {
#
print OK - RC: $? \n;
#
} else {
#
print Error - RC: $? \n;
#
} # end if  ( $mail_object-send_by_smtp( $smpt_server ) ) {

# End of script

Thanks in advance
Karl-Heinz


___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Problem with use strict

2002-10-30 Thread Karl-Heinz Kuth

I have a problem with use strict:

There are two files. The file test_template.pl calls the file test_modul.pl
via a variable. I read this file name from an ini-file. But for the example
I wrote it into a variable ($modul).

File: test_template.pl:

use strict;
my $Simulation = y;
my $modul = e:\\temp\\test_modul.pl;
print Simulation before:  $Simulation \n;
require $modul;
print Simulation after:   $Simulation \n;

File: test_modul.pl

use strict;
$main::Simulation = f;
print Simulation modul:   $main::Simulation \n;

If I call test_template.pl, I will get the following output:
Simulation before: y
Simulation modul:  f
Simulation after;  y

But I want to get 
Simuation after :  f

How do I have to change the code in the file test_modul.pl, so that
the value of the variable $Simulation is also changed in the
test_template.pl?

Thanks in advance!

Bye
Karl-Heinz

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs