Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

split number?

Status
Not open for further replies.

marcel2

Vendor
Mar 9, 2003
14
NL
Hope you can help me out.

I have got the next code this code is decoding part of a number the hole number is 92259. The problem is that $1 = standing for the numbers 59 but I want to have $2 for the 5 and $3 for the 9, please help me to change this code.

92259 now 59
if ($NINE_CODE=~/^22(.+)$/) { $NINE_CODE="$SP_WAVES [$1]"; }

must be 92259 $2=5 $3=9
if ($NINE_CODE=~/^22(.+)$/) { $NINE_CODE="$SP_WAVES[$2], zicht $SP_WATER_VIS[$3]"; }

Hope you understand my needs and will help me.

Greatings,
Marcel
 
Isn't this just:
Code:
if($NINE_CODE =~ /^22((\d)(\d))$/) {
  printf "%d %d %d\n", $1, $2, $3;
}
Cheers, Neil
 
Try changing your code like this:
Code:
if ($NINE_CODE=~/^22((\d)(\d))$/) { $NINE_CODE="$SP_WAVES[$2], zicht $SP_WATER_VIS[$3]"; }
That should put 59 in $1, 5 in $2, and 9 in $3.
 
Thanks for the code, I new and just am trying to change a perl written script for me.So I tryed it and found some thing I think has to be changed to before it works.

sub urldecode{
local($val)=@_;
$val=~s/\+/ /g;
$val=~s/%([0-9a-hA-H]{2})/pack('C',hex($1))/eg;
return $val;
}
This part is written in my script to, hope you can tell me what to change to get this code to work

if ($NINE_CODE=~/^22((\d)(\d))$/) { $NINE_CODE="$SP_WAVES[$2], zicht $SP_WATER_VIS[$3]"; }


Thanks,
Marcel
 
Sorry, right now I don't have enough information to help.

The urldecode looks fine. All it does is takes a urlencoded string and converts any urlencoded values to ascii (i.e. %41 = A). Looking at urldecode it would appear that a urlencoded string is passed in with a number of hex digits seperated by +'s. But what is passed in and what is expected out I can't tell from the listed code.

I would need to see where $NINE_CODE comes from (i.e. is it passed in from a web form) and any manipulations that it goes through before. Does $NINE_CODE get manipulated through urldecode?

If you can provide more detail I may be able to help you.
 
This is the part that gets the code and puts it into a mysql.

if($sec_param==9) {$NINE_CODE=substr($cur_group,1,4);
if($NINE_CODE!~/^\d+$/) {$NINE_CODE="null";}

The $1 is working fine but what do I need to do if I want to split $1.

This lookt like the right thing to do
if ($NINE_CODE=~/^22((\d)(\d))$/) { $NINE_CODE="$SP_WAVES[$2], zicht $SP_WATER_VIS[$3]"; }

Hope you can help me now.
Marcel
 
Thanks for all the help you have given me but I did solf the problem whit the next code;
($NINE_CODE=~/^18((.)(.))$/) Now it's working perfect.

Thanks again.
Marcel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top