| |||||||||||
| |||||||||||
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:
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.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |