Monday, April 23, 2012

Perl, generating new data (new hash) using two different hash tables

I've bumped into a very complicated problem (in my perspective as a newbie) and I'm not sure how to solve it. I can think of the workflow but not the script.



I have file A that looks like the following: Teacher (tab) Student1(space)Student2(space)..



Fiona       Nicole Sherry 
James Alan Nicole
Michelle Crystal
Racheal Bobby Dan Nicole


They sometimes have numbers right next to their names when there are two of the same name (ex, John1, John2). Students may also overlap if they have more than two advisors..



File B is a file that has groups of teachers together. It looks similar but the values are comma-delimited.



Fiona       Racheal,Jack
Michelle Racheal
Racheal Fiona,Michelle
Jack Fiona


The trend in file B is that a key has multiple values and each value becomes a key as well to easily find who is grouped with who.



The output I would like is which students will be likely to receive similar education based on their teacher/groups.So I would like the script to do the following:




  1. Store file A into a hash and close

  2. Open file B, go through each teacher to see if they have students (some may not, the actual list is quite big..). So if I take the first teacher, Fiona, it will look in stored file A hash table to see if there is a Fiona. If there is, (in this case, Nicole and Sherry), pop them each as new keys to a new hash table.



    while (<Group>) {
    chomp;
    $data=$_;
    $data=~/^(\S+)\s+(.*)$/;
    $TeacherA=$1;
    $group=$2;

  3. Then, look at the group of teachers who are grouped with Fiona (Racheal, Jack). Take 1 person at a time (Racheal)



    if (defined??) {
    while ($list=~/(\w+)(.*)/) {
    $TeacherB=$1;
    $group=$2;

  4. Look at file A for Racheal's students.

  5. Fill them as values (comma-delimited) for student keys made from step 2.

  6. Print student-student and teacher-teacher group.



    Nicole  Bobby,Dan,Nicole    Fiona   Racheal
    Sherry Bobby,Dan,Nicole Fiona Racheal


    Since the next teacher in Fiona's group, Jack, didn't have any students, he would not be in this results. If he had, for example, David, the results would be:



    Nicole  Bobby,Dan,Nicole    Fiona   Racheal
    Sherry Bobby,Dan,Nicole Fiona Racheal
    Nicole David Fiona Jack
    Sherry David Fiona Jack



I'm so sorry for asking such a complicated and specific question. I hope other people who are doing something like this by any chance may benefit from the answers.
Thank you so much for your help and reply. You are my only source of help.





PHP Class Not Loading

I'm using WordPress and I'm trying to write a plugin that uses a file from another plugin. The URL to get the file is correct. I'm able to include the file when I'm calling a static function from the class, it is saying that the class is not loading.



//loading the file
$url=plugins_url().'/nextgen-gallery/admin/functions.php';
include $url;


The filename is functions.php and in it is a class defined nggAdmin



However, when i call the function nggAdmin::create_gallery();, i get the following error:



Fatal error: Class 'nggAdmin' not found in /var/www/html/wordpress/wp-content/plugins/Product/addProductForm.php on line 27




Bind only specific items to gridview from list

I have a list where one item have 4 different elements



Item



Id int
Name String
Value String
Enable bool


I want to Bind the List<item> to a gridview. Currently I am displaying all the items. But I want to display only the Name and Enable fields only.
What is the easy way of doing this? Without creating new list



Thanks





C++0x: Variadic templates

Can I use variadic templates without using the template parameters as function parameters?



When I use them, it compiles:



#include <iostream>
using namespace std;

template<class First>
void print(First first)
{
cout << 1 << endl;
}

template<class First, class ... Rest>
void print(First first, Rest ...rest)
{
cout << 1 << endl;
print<Rest...>(rest...);
}

int main()
{
print<int,int,int>(1,2,3);
}


But when I don't use them, it doesn't compile and complains about an ambiguity:



#include <iostream>
using namespace std;

template<class First>
void print()
{
cout << 1 << endl;
}

template<class First, class ... Rest>
void print()
{
cout << 1 << endl;
print<Rest...>();
}

int main()
{
print<int,int,int>();
}


Unfortunately the classes I want to give as template parameters are not instantiable (they have static functions that are called inside of the template function).
Is there a way to do this?





how to select option to submit different php page

drop down select "sales" go to sales.php, other options selected go to addFund.php...



<form name='searform' method='post' action='<?php echo $home;?>addFund.php'>
Search : <input type='text' id='sear' name='sear'> by
<select id='psel' name='psel' onchange='change()'>
<option value='email'>Email</option>
<option value='name'>Username</option>
<option value='domain'>Domain name</option>
<option value='sales'>Sales</option>
</select>
<input type='submit' name='sub' id='sub' value='Go' onclick='gopage()'>
<input type='submit' name='dir' id='dir' value='Direct'>
</form>


How to submit different pages





Cordova 1.6.1 setInfo error

I recently upgraded to cordova 1.6.1 but i can't get it to deploy on the simulator or the device itself. The debugger shows Error: executing module 'setInfo' are you sure you have loaded iOS version of cordova-1.6.1.js? Though i'm sure i already did. Any help?





Translating oracle right outer join to sql server

I'm fairly new to SQL and I'm trying to translate some oracle commands to sql server. The issue lies with converting the following right outer join:



where
SOURCE_FORMATS.LOC_SIMPLE_ENTITY_ID = FILEFORMAT_INTERNAL_SIGNATURES.LOC_FILEFORMAT_ID (+)


As far as I can understand in SQL this has to be represented in the "from" section to be something like:



from
SIMPLE_ENTITIES "SOURCE_FORMATS" RIGHT OUTER JOIN FILEFORMAT_INTERNAL_SIGNATURES
on SOURCE_FORMATS.LOC_SIMPLE_ENTITY_ID = FILEFORMAT_INTERNAL_SIGNATURES.LOC_FILEFORMAT_ID


Is this logic correct?