Hi Shlomi,

Thanks for your reply. 

> Please add "use strict;" and "use warnings;" to your code.

Done. Phew, there was a whole lot of warnings/errors to be fixed :-/


> Why are you using "do" instead of "use" or "require"? 

Because I didn't know better :) Changed it to "require" since this is
some kind of config file, containing mainly path variables to be
configured by the user. Now, following another hint, it's like that:

******************* config file *****************
#!/usr/bin/perl
use strict;
use warnings;

our $cuttux='s/db$//g';


******************* main script *****************

sub selTux {
        our $cuttux;
        DEBUG("$cuttux\n"); # <-- correct!
        my $deftux;
        ($deftux=$db)=~tr/[A-Z]/[a-z]/;
        DEBUG("$deftux\n");
        $deftux=~$cuttux;
}


> See
> http://perl-begin.org/ for more information and recommended books and
> tutorials.

Thanks for the info, will check.


> Normally <ARGV> - shortened to <> is preferable over <STDIN>;

I initially used this syntax but received an error because I start my
script with 1-2 parameters (one required, second one optional):

oracle:/opt/data/magna/wartung>dbmove.pl T D
Can't open T: No such file or directory at
/opt/data/magna/wartung/dbmove.pl line 291.
Can't open D: No such file or directory at
/opt/data/magna/wartung/dbmove.pl line 291.

With <STDIN> this works.


> You can do one of the following:
> 
> 1. Put the left-hand-part of the s/// in a qr// variable:
> 
> (Untested)
> <<<
> my $exp = qr{hello$};
> 
> my $string = "Time to say hello";
> 
> $string =~ s{$exp}{goodbye};
> >>>
> 
> 2. You can also try using the stringified eval "" (which could be
error
> prone
> and generally not recommended.
> 
> 3. You can try constructing a closure:
> 
> (Untested)
> <<<
> 
> my $op = sub { my $s = shift; $s =~ s{hello$}{goodbye}; return $s; };
> 
> .
> .
> .
> 
> print $op->("Time to say hello"), "\n";
> >>>

I am very sorry but I do not understand what you mean. My aim is to
enable the user to define a complete substitution syntax for getting a
username from a database name (after a fixed scheme). (See the code from
the config file above.)

(tr [A-Z] [a-z] always as in code snippet above)
E.g. I have a database name "MYDB" --> username is "my" (s/db$//g)
E.g. I have a database name "STGKK_STP15M3" --> username is "stp15m3"
(s/^STGKK_//g)



Regards, 
Nora 




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to