Replacing variable value in perl script

hi I have this line in my perl script

 
if (($cookie =~ /^cookie(.*)\/(.*)/) && ($ !~ /^cookie(10)\/(.*)|/)) {
                        $cookienumber = "$1.$2";
                        }

now if the result is cookie1/0,

my $cookienumber would be 1.0

but if the result is cookie1/0/0

my $cookienumber would be 1/0.0

how can I replace the variable for result 1/0.0 to 1.0.0?

How can I change $1 value from 1/0 to 1.0?

Please help thanks

---------- Post updated at 05:55 PM ---------- Previous update was at 05:30 PM ----------

Not sure I fully understand, but are you looking for something like this ?

$
$ cat -n cookies
     1  cookie1/0
     2  cookie1/0/0
     3  cookie1/0/0/0
     4  cookie1/0/0/0/0
     5  notacookie1/0/0
$
$ perl -lne '/^cookie/ && s!/!.!g; print' cookies
cookie1.0
cookie1.0.0
cookie1.0.0.0
cookie1.0.0.0.0
notacookie1/0/0
$
$

tyler_durden

change of plan :stuck_out_tongue:

I need help with the regular expressions instead as I have tweaked my script

if $cookie =~ /^cookie(.)\/(.)\/(.)/

$cookietype="$1.$2.$3"

so if my $cookie is cookie1/0/0

my $cookietype will be 1.0.0

Problem is, if my $cookie is cookie1/0,

it doesnt match any of the pattern so it'll set the value to 0 by default
(defined in my final else statement).

I added elsif statement as below

elsif $cookie =~ /^cookie(.)\/(.)/
$cookietype="$1.$2"

and the value became 0, as if it doesnt match the pattern :frowning:

please help.

$
$
$ cat -n cookies
     1  cookie1/0
     2  cookie1/0/0
     3  cookie1/0/0/0
     4  cookie1/0/0/0/0
     5  notacookie1/0/0
$
$
$ perl -lne 'chomp($cookie=$_);
>            if ($cookie =~ /^cookie(.)\/(.)\/(.)$/) {$cookietype = "$1.$2.$3"}
>            elsif ($cookie =~ /^cookie(.)\/(.)$/) {$cookietype = "$1.$2"}
>            else {$cookietype = "0"}
>            print $cookietype' cookies
1.0
1.0.0
0
0
0
$
$

tyler_durden

it worked!, thank you so much! :smiley:

Glad to know that!

tyler_durden