Hi,
I am a newbie at PERL and really wanted to understand how server-side programming really works and operates since I use at the workplace. I use ASP and wanted to learn more about server-side programming since I am in the field of web design, development and multimedia.
Here are some tips and need some help how to program:
The way I learn is that I need an detailed explanation why and how we need use certain functions in PERL:
I wonder if there is a website that shows source code and detailed explanations that is easy to understand.
But anyway, I just need help how to program in PERL: Here are some tips and help on how to program:
I am a newbie at PERL and really wanted to understand how server-side programming really works and operates since I use at the workplace. I use ASP and wanted to learn more about server-side programming since I am in the field of web design, development and multimedia.
Here are some tips and need some help how to program:
The way I learn is that I need an detailed explanation why and how we need use certain functions in PERL:
I wonder if there is a website that shows source code and detailed explanations that is easy to understand.
But anyway, I just need help how to program in PERL: Here are some tips and help on how to program:
Code:
#!/usr/bin/perl
=comment
The script assigns gen# accounts to a tab separated list of names and
id numbers provided at the bottom of the code under __DATA--
The following few lines explains some of the necessary syntax to
accomplish this task:
=cut
#The first two lines of the data below the __DATA__ syntax can be read with the following:
$line = <DATA>;
chomp $line;
print "first line: $line\n";
$line = <DATA>;
chomp $line;
print "second line: $line\n";
#The 'split' function is useful for splitting a string from a given character:
#In this case the username is being split from the number
#by specifying the tab in regexp notation (will learn later) in the first argument
#of the split function:
($name, $number) = split(/\t/, $line);
#You could use the following to read the whole list:
# the <DATA> command will keep reading one line at time until
# the internal pointer for <DATA> reads EOF, at which point,
# the 'while' loop is excausted
while ($line = <DATA>) {
print "line is: $line";
}
=comment
to do:
modify the while loop above to include a 'split' function to
separate the name from the number into a hash.
The hash should be designed to store the id number by using
the full name as key.
After populating the hash, save the keys (sorted) into an array.
The reason for saving the keys into an array is to help printing
a new list, sorted by name.
Print the hash data using a 'for' loop (use the loop index to generate the gen numbers)
and coordinating with the array to produce a sorted list in the following format:
gen1|Croft, Amy|4853
gen2|Fitzgerald, Brandon|7465
gen3|Fong, Ji-Men|2365
gen4|Fung, Kei Y.|8563
etc.
Last important example to demonstrate concatenation:
$gen = "gen" . $i; same as "gen3" if $i is equal to 3
Use the same technique to concatenate the data above, which is separated by 'pipes' (|)
=cut
__DATA__
Fong, Ji-Men 2365
Lwin, Pyi-Soe 2367
Lanferman, Alexander 3425
Wells, Shou 3669
Sira, Flavio 3756
Croft, Amy 4853
Todorova, Elina 5978
Han, Jason 6574
Tang, Michael 6892
Fitzgerald, Brandon 7465
Stout, John 8397
Fung, Kei 8563
Hoang, Hop 8657
Sundara, Rhama 9154
Comment