The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]
Scripts / handy tips
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Previous Message  |  Next Message 
 Re: Searching the ports
Author: parv 
Date:   15-04-02 07:00

Benjamin Lutz wrote:
> #!/usr/bin/perl

why not add "-w" there...

#!/usr/bin/perl -w


> open FILE, "/usr/ports/INDEX";

you should check for errors...

open (FILE, "</usr/ports/INDEX") or die "open failed: $!\n";


> while ($_ = <FILE>) {

that's funny, i see "FILE" in angle brackets as i reply, but was omitted from the source code as seen in this forum. below is my try to use the html entities...

while($_ = <FILE>) {

...while at it, remove "$_ = " as that's what $_ is assigned by default anyway...

while(<FILE>) {

> $thisline[1] =~ s/\/usr\/ports\/(.*)/$1/;

instead of escaping "/" when using "/" as the delimiters for s/// or m//, just use different delimiter...

$thisline[1] =~ s#/usr/ports/(.*)#$1#;

> my $input;
>
> if (@ARGV) {
> $input = $ARGV[0];
> #} else {
> # print "Enter a category: ";
> #
> # $input = <STDIN>;
> # chomp $input;
> }

dead code, enh? if that's going to be removed (eventually), above can be translated to...

my $input = $ARGV[0] if ( scalar(@ARGV) );

- parv

 Reply To This Message  |  Forum List  |  Flat View   Newer Topic  |  Older Topic 

 Topics Author  Date
 Searching the ports   new
William Cooper 21-02-02 14:06 
 Re: Searching the ports   new
parv 22-02-02 10:34 
 Re: Searching the ports   new
Benjamin Lutz 09-04-02 02:48 
 Re: Searching the ports   new
parv 15-04-02 07:00 
 Re: Searching the ports   new
parv 15-04-02 07:05 
 Re: Searching the ports   new
el_kab0ng 19-09-05 18:09 
 Re: Searching the ports   new
Dan 19-09-05 18:31 
 Re: Searching the ports   new
el_kab0ng 19-09-05 18:38 
 Re: Searching the ports   new
parv 19-09-05 23:09 


 Forum List  |  Need a Login? Register Here 
 User Login
 User Name:
 Password:
 Remember my login:
   
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum

phorum.org