Hello! I'm havin problems at using subroutins, I'm starting using Perl and I have no idea what the problem is... It say's that theres an uninitialized in numeric eq (==) at "Busqueda Binaria Recursiva" line 15,<STDIN> line 5. Can you please help me?

#!/usr/bin/perl use strict; use warnings; sub busca_binaria_rec{ my ($conjunto,$elemento,$primero,$cuantos)=@_; my $izquierda=$primero; my $derecha=$cuantos; my $medio=($izquierda+$derecha)<<2; if($izquierda>$derecha){ return (-1); } else{ if((@{$conjunto}[$medio])==$elemento){ return($medio); } if(@{$conjunto}[$medio]<$elemento){ $medio+=1; busca_binaria_rec((\@{$conjunto}),$elemento,$medio,$derecha); }else{ $medio-=1; busca_binaria_rec((\@{$conjunto}),$elemento,$izquierda,$medio) +; } } } { my @conjunto; #creamos las variables para el elemento a buscar así + como para el conjunto en el que se buscará y su tamaño print "Introduce el elemento a buscar(en el rango de -20,000 hasta + 20,000):";#se le pide al usuario que introduzca el elemento a buscar my $buscado = <STDIN>; print "Introduce cuantos elementos contiene el conjunto(siendo 100 +00 el numero maximo):";#se le dice al usuario que introduzca el tamañ +o del conjunto y las restricciones my $cuantos=<STDIN>;#el usuario introduce el tamaño del conjunto e +n la variable cuantos #llena el conjunto print "Ingresa los numeros del conjunto seguidos por un enter :)"; for(my $i=0;$i<$cuantos;$i++) { $conjunto[$i] = <STDIN>; } #ordena my $temp=0; for(my $i=0;$i<$cuantos;$i++){ for(my $j=0;$j<$cuantos;$j++){ if($conjunto[$i]<$conjunto[$j]){ $temp=$conjunto[$i]; $conjunto[$i]=$conjunto[$j]; $conjunto[$j]=$temp; } } } if((busca_binaria_rec(\@conjunto,$buscado,0,$cuantos-1))!=-1){#si +el elemento se encuentra en la lista, imprime su posicion my $posicion= &busca_binaria_rec(\@conjunto,$buscado,0,($cuant +os-1)); print "El elemento se encuentra en la posicion: $posicion"; }else{# si el elemento no esta, se le indica al usuario su ausenci +a print "El elemento no esta en el conjunto"; } }

In reply to Recursive Subroutin Problem by Panfi96

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.