1 kwi 2008

Inwersja SELECT, ComboBoxa

function inwersja() {
  len = document.test.branze.length

  for (i = 0; i < len; i++) {
    if (document.test.branze.options[i].selected)
      document.test.branze.options[i].selected = false
    else
      document.test.branze.options[i].selected = true
  }
}
<FORM METHOD=POST ACTION="" NAME="test">
  <select name="branze" multiple size="5">
    <option selected value="0">--------- wybierz --------</option>
    <option value="1">5</option>
    <option value="2">20</option>
    <option value="3">100</option>
  </select>
  <INPUT TYPE="button" Value="INWERSJA" onClick="inwersja()">
</FORM>
1 kwi 2008

Test numeru operatora

sub process_number
{
 $_ = shift;

 return $PLUS if (/^60[1,3,5,7,9]/);
 return $ERA if (/^60[0,2,4,6,8]/);
 return $IDEA if (/^50[1-9]/);
 return undef;
}
1 kwi 2008

Funkcja escape i unescape w PERLU

sub unescape
{
 my $to_decode = shift;
 return undef unless defined($to_decode);
 
 $to_decode =~ tr/+/ /;
 $to_decode =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
 return $to_decode;
}

sub escape
{
 my $to_encode = shift;
 return undef unless defined($to_encode);
 $to_encode=~s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
 return $to_encode; 
}