xjlittle has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I have been learning perl for the last month or so. Having gone through several tutorials writing practice code I decided it was time to try one of my own.
Following is some code that works for removing emacs tmp files and core files generated by the kernel from the /home/john and /lib directories. One of my goals for this is to easily change which directories are parsed.
My question is on the way I setup the parameters to be passed to the subroutine. Is this the correct way to setup multiple arguments for the subroutine?
All of these are really good answers. I will start implementing (or learning how to use them) immediately.
One of the reasons that I made this post is to learn the correct way and get into the habit of doing things that way. Fortunately I don't have any bad habits to break since I have never programmed before-I am a network administrator by profession. All of you have supplied me with good habits to get into.
Thank you very much!
John
I have been learning perl for the last month or so. Having gone through several tutorials writing practice code I decided it was time to try one of my own.
Following is some code that works for removing emacs tmp files and core files generated by the kernel from the /home/john and /lib directories. One of my goals for this is to easily change which directories are parsed.
My question is on the way I setup the parameters to be passed to the subroutine. Is this the correct way to setup multiple arguments for the subroutine?
#!/usr/bin/perl -w $user = "/home/john"; $lib = "/lib"; &directs($lib); &directs($user); sub directs { foreach (@_) { opendir(DIRS,$_); @tmps = readdir(DIRS); closedir(DIRS); } &remove; } sub remove { foreach $line(@tmps) { if (($line =~ /~$/ ) || ($line =~ /^core\./)) { unlink "$line"; #print "$line\n"; } } }
All of these are really good answers. I will start implementing (or learning how to use them) immediately.
One of the reasons that I made this post is to learn the correct way and get into the habit of doing things that way. Fortunately I don't have any bad habits to break since I have never programmed before-I am a network administrator by profession. All of you have supplied me with good habits to get into.
Thank you very much!
John
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: using a subroutine
by bgreenlee (Friar) on Aug 08, 2004 at 22:23 UTC | |
by xjlittle (Beadle) on Aug 10, 2004 at 00:32 UTC | |
Re: using a subroutine
by ysth (Canon) on Aug 08, 2004 at 22:42 UTC | |
by beable (Friar) on Aug 08, 2004 at 22:57 UTC | |
by ysth (Canon) on Aug 08, 2004 at 23:15 UTC | |
by xjlittle (Beadle) on Aug 10, 2004 at 00:34 UTC | |
Re: using a subroutine
by Zaxo (Archbishop) on Aug 09, 2004 at 06:14 UTC | |
by xjlittle (Beadle) on Aug 10, 2004 at 00:50 UTC | |
by xjlittle (Beadle) on Aug 10, 2004 at 00:28 UTC | |
Re: using a subroutine
by bradcathey (Prior) on Aug 09, 2004 at 00:31 UTC | |
by xjlittle (Beadle) on Aug 10, 2004 at 00:42 UTC | |
Re: using a subroutine
by Jasper (Chaplain) on Aug 09, 2004 at 08:36 UTC | |
by xjlittle (Beadle) on Aug 10, 2004 at 00:05 UTC | |
Re: using a subroutine
by mpeg4codec (Pilgrim) on Aug 09, 2004 at 17:58 UTC | |
by xjlittle (Beadle) on Aug 09, 2004 at 23:51 UTC | |
Re: using a subroutine
by trammell (Priest) on Aug 09, 2004 at 16:52 UTC | |
by xjlittle (Beadle) on Aug 09, 2004 at 23:53 UTC | |
Re: using a subroutine
by TomDLux (Vicar) on Aug 10, 2004 at 01:52 UTC |
Back to
Seekers of Perl Wisdom