Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
How to use Perl references?

Posted by YenTran (YenTran), 18 June 2005
Please help me with this project.

Write a program that produces report of the current directory that lists all symlinks that are pointing to other directories. This program should include 2 subroutines, the first one will return references to array to be passed to the second sub routine, the second sub routine frame work is provided but it needs to be modified to be using references.

sub list_syms {


}

sub pr_sl2dirs {

my @syms = @_;
$\ = "\n";

print "\n", "[[ 2. symlinks to directories ]]", "\n";

foreach my $sym ( @syms ) {

   unless ( -l readlink $sym ) {

      print $sym  if ( -d $sym );
   }
}

print "..." x 20;
}


Posted by admin (Graham Ellis), 18 June 2005
Why have you chosen that particular specification for the subroutines?  Are you by any chance asking us to complete your coursework?  

Posted by YenTran (YenTran), 18 June 2005
Yes, it is an assignment and I am stuck  

Posted by admin (Graham Ellis), 18 June 2005
As our Posting FAQ says, we can't provide complete answers to coursework assignments here, as that would be doing you a dis-service in the long term.   I am also worried that you may not have permission to post the question - when you signed up here, you agreed not to post copyright material unless it's your own copyright, or you have clearance to do so.

How far have you got so far?  I woudl suggest you start off writing the top level structure of what you want and call a couple of subroutines as per the specification.   Don't write the "real" code of the subroutines at first - just have them return the same thing every time so that you can test the code out piece by piece.  Then go on to the code of the subs ....

Posted by YenTran (YenTran), 19 June 2005
Thank you for reminding me about the Posting Rules.

I've gotten some progress and the work is actually finished.  The first sub routine will return references to the second sub routine, something like this:

my $ref = list_syms();
pr_sl2dirs($ref);

sub list_syms {
     opendir(DIR, '.') || die "Can't open the current directory: $!";
     my @links = grep {-l } readdir(DIR);
     closedir DIR;
     return \@links;
}

I've tested the same code but for listing directories under the current directory (grep -d) and it works.  Now I need to test if this piece of code work for listing symlinks that point to directories (grep -l) .  Can you tell me how to create symlink to point to directories for testing?  I can't connect to my lab's test environment now. Thx.



Posted by admin (Graham Ellis), 19 June 2005
on 06/19/05 at 19:35:06, YenTran wrote:
Thank you for reminding me about the Posting Rules.


I'm unclear as to whether that means you are OK under copyright rules to post the assignment original.  If you're not, please replace the question in your original post with a link - that way, we can all see the question and you'll be legal  

On your link question, I've answered that in the separate thread you started ...



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho