CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
string compare find match data

 



strandmoran
New User

Nov 10, 2011, 3:52 AM

Post #1 of 3 (3963 views)
string compare find match data Can't Post

#!/usr/bin/perl
#
# translate from C to Perl! I am NUTS!
#
$buffer='&vv0=3002+++%24+4.1+Q%3A+2&vv3=3007+++%24+8.3+Q%3A+7&vv42=3007+++%24+8.3+Q%3A+7&';
$buffer =~ tr/+/ /;
$buffer =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$buffer =~ s/<!--(.|\n)*-->/ /g;
$buffer =~ tr/\\|[|]|<|!|"|$|{|}|*|#|'|>|||;|%/ /;
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($key,$value)=split(/=/,$pair);
$formdata{$key}.="$value";
}
$vv0=$formdata{'vv0'}; # this are not good style!

---- begin code in C --> translate to PERL -----
String[] ss;
String[] sU;
for( int i = 0; i < 49; i++ ){ ss[i] = "vv" + i; }

String[] sU;
int[] cu;
int count;
for( int i = 0; i < 49; i++ )
{
if( ss[i].compareTo( $formdata ) == 0 ) # $formdata USED as follow my IDEA!
{
sU[count] = $formdata; # $formdata USED as follow my IDEA!
cu[count] = i;
count++;
}
}

---- print out html code ------------
print OUTF "<tr> \n";
print OUTF "<td> vv0: </td>\n";
print OUTF "<td> $vv0 </td>\n"; # Perl get NUTS! this are not good style!
print OUTF "</tr>\n";

---- code in C --> translate to PERL -----
for( int i = 0; i < count; i++ )
{
System.print( "<td> " + ss[cu[i]] + " </td>\n");
System.print( "<td> " + sU[i] + " </td>\n");
}


FishMonger
Veteran / Moderator

Nov 10, 2011, 6:14 AM

Post #2 of 3 (3956 views)
Re: [strandmoran] string compare find match data [In reply to] Can't Post

Do you have a question?


strandmoran
New User

Nov 10, 2011, 8:15 AM

Post #3 of 3 (3945 views)
Re: [FishMonger] string compare find match data [In reply to] Can't Post

SOLVED BY STRANDMORAN :
$buffer='&vv0=3002+++%24+4.1+Q%3A+2&vv3=3007+++%24+8.3+Q%3A+7&vv42=3007+++%24+8.3+Q%3A+7&';
$buffer =~ tr/+/ /;
$buffer =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$buffer =~ s/<!--(.|\n)*-->/ /g;
$buffer =~ tr/\\|[|]|<|!|"|$|{|}|*|#|'|>|||;|%/ /;
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($key,$value)=split(/=/,$pair);
$formdata{$key}.="$value";
}

for($ii = 0; $ii < 50; $ii++ ){
$dd[$ii]='vv' . $ii;
}

$jj=0;
$nrp=0;
while (($ky, $val) = each (%formdata)){
$val = $formdata{$ky};
print " ($ky) <==> $val ($dd[$jj]) \n";
for($ii = 0; $ii < 50; $ii++ ){
if( $ky eq $dd[$ii] )
{
print "YES, I FIND: dd= $dd[$ii] > ky= $ky <==> val= $val \n";
$prx[$nrp]=$ky;
$prn[$nrp]=$val;
$nrp++;
}
}
$jj++;
}

for($ii = 0; $ii < $nrp; $ii++ ){
print "RESULT: $prx[$ii] ----- $prn[$ii] \n";
}

---- print out html code ------------

for($ii = 0; $ii < $nrp; $ii++ ){
print OUTF "<tr> \n";
print OUTF "<td> $prx[$ii]: </td>\n";
print OUTF "<td> $prn[$ii] </td>\n";
print OUTF "</tr>\n";
}

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives