Gossamer Forum
Home : General : Perl Programming :

string matching problem

Quote Reply
string matching problem
i have this code
Code:
$found = 'nope'; $user = 'delicia';

my (%rec2) = &array_to_hash2($_, @hits2);
if ($user eq $rec2{'Userid'}) { $found eq 'found her'; }
print qq|<p>-$rec2{'Userid'}- $found -$user-|;

which is producing the following result:
-delicia- nope -delicia-
i put the dashes around the variables to see if there were any weird characters or spaces. why doesn't the code see that the two strings are identical???


Quote Reply
Re: [delicia] string matching problem In reply to
What do you see if you do:

Code:
use Data::Dumper;
print Dumper({ user_id => $rec2{'Userid'}, test => $user } );

That should print out any extra characters in the string

Also - in array_to_hash2() do you "chomp" the line, to remove any ending newlines/return breaks?

Cheer

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] string matching problem In reply to
dumper shows:

$VAR1 = { 'test' => 'delicia', 'user_id' => undef };

see chomp below. get record is used for one-to-one relationship and doesn't call array to hash. for some reason it isn't matching $key2 to $data[0]. i guess the problem is related to the split_decode in my other post about using the colon as a delimiter.

Code:
open (DBX, "<$db2_file_name") or &cgierr("error in get_records. unable to open db file: $db2_file_name.\nReason: $!");
flock(DBX, 1);
LINE: while (<DBX>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_;
chomp ($line);
@data = &split_decode2($line);
#next LINE if ($restricted and ($db_userid ne $data[$auth_user_field]));
if ($data[$db2_key_pos] eq $key2) {
$found = 1;
for ($j = 0; $j <= $#db2_cols; $j++) { # Map the array columns to a hash.
$rec2{$db2_cols[$j]} = $data[$j];
}
last LINE;
}

if there's some reason i can't use the colon as a delimiter, i can just use that as a condition to use a regular split function.
Quote Reply
Re: [delicia] string matching problem In reply to
Yeah so based on that debug, %rec2 doesn't exist properly. It feels like this whole decoding stuff is far too complex for what it needs to be. What is the actual line of data its trying to extract from?

In your code above:

Code:
@data = &split_decode2($line);

Try adding a dump of @data:

Code:
use Data::Dumper;
print Dumper( { data => \@data } );

See if that contains what you are expecting

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] string matching problem In reply to
ok, dumper shows every line in the file, but here's the line i want:

Code:
$VAR1 = { 'data' => [ '2819:delicia:Reynolds Delicia:18.4:20151015:Yes::zzzzz' ] };
is that what it should look like? it's exactly like the actual line in the file.

it should be seeing that data[1] delicia eq user delicia and then mapping the array so rec2{'Userid'} eq delicia
Quote Reply
Re: [delicia] string matching problem In reply to
Can you email me the .db file so I can test it and see what it does my end

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!