Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Perl Programming Language

/e option in the s/// command


#############################
use strict;
use warnings;

my $var = "''''''''''''";

my $p_pulse = q{./\\};
my $n_pulse = q{'\\/};

my $knt = 1;

print $var;
$var =~ s/^((...){$knt}).../$1 . (($1 =~ m{'}) ? $n_pulse : $p_pulse)/
e;       ## <---- offending line
print $var;
##########################

when I run the above piece of perl code i get the following warnings:
      Use of uninitialized value in concatenation (.) or string at
line 12.
And when i change the $var to "..........." it works fine.

what could be the problem here?

TIA,
-rakesh

On Jun 5, 6:34 am, sharma@hotmail.com wrote:

The $1, $2, $3 <etc> variables are set after every successful pattern
match.  In your replacement, you are doing a pattern match.  That
pattern match succeedes, because the current value of $1 does indeed
match m{'}.  That successful match causes $1 to be set to undef,
because that pattern match doesn't have any capturing parentheses.  So
it is the first $1 listed in your replacement - the one that's
concatenated to the result of the ?: operator - that's undefined.

It worked fine when you changed $var to all periods because then the
inner pattern match was not successful and so $1 wasn't changed.

You can fix this by saving off the value of $1 in your replacement, as
follows:

$var =~ s/^((...){$knt}).../my $save = $1; $save . (($save =~ m{'}) ?
$n_pulse : $p_pulse)/e;

Hope this helps,
Paul Lalli

On Jun 5, 3:46 pm, Paul Lalli <mri@gmail.com> wrote:

Thanks a lot Paul for your explanation!

Your suggested fix runs perfect.

Best regards,
-rakesh.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc