ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to search the passwd file for a specific gid, and then dump those results into a file. I have almost all of the code, except i can't seem to get only those that match. Can someone please help?
Why don't you post what you have. While you're waiting for a reply you could look up "match" under "man perlop". Hit "/" then type "match", use "n" to go forward.
"$gid = $group" means set the variable gid to the same value as the variable group. The operation succeeds (why wouldn't it) and returns the value true. Which means that line is the same thing as "if (1)".
Double equals signs, "==", means compare numbers.
I didn't spend much time looking at the rest of the script but am not sure you really want to have another "while (<PASSWD>)" loop inside the first one, and you almost certainly don't want to be asking for the output filename in any loop.
The reason why i was asking for the filename inside the while loop is because i wanted to make sure the $group requested matched that $gid before asking for the filename. Otherwise it would ask for the filename before checking if the $group requested was even valid. Although it makes sense what you said because when i run it, it kept asking for a filename hehe. I appreciate your help.
If you don't want to bother the user for a filename when the search term wasn't found, you could save the hit to some arbitrary filename and ask the user for a new name at the end of the loop, then rename the file to that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.