I am new to PERL so please forgive me If I am being dumb here.

I have a file like below -

SLNO FirstName LastName Desgination ----------------------------------------------------- 1 Pragya Singh Developer 2 George Shepered SME 3 Akshay Bhargav SME 4 Amey Deshmukh Developer 5 Bhushan Bhatkar Quality 6 Dinesh Yadav Support ------------------------------------------------------

I want to write a PERL program for below -
Provide user an option to print all last names with designation or firstnames with designation. Depending on the user input, print the "lastname designation" or "first name designation". Keep waiting for input if not given.

I gave it a shot but only able to read\open it

#!/perl/bin/perl $fname = "Designations.txt"; open (WXYZ, $fname) or die "Couldn't open file Designations.txt, $!"; while (<WXYZ>) { print "$_"; } print "Enter First Name or Last Name: \n \n"; $name = <STDIN>; print "Entered name is : $name \n"; --------------------------------------------

After I enter the name it should give me a desgination belonging to that person.

What should I use a while loop along with if statements and match operators ??

Please help me, I am confused what if there are many names in the file.

Please help


In reply to How to search a Name from a file and extracts its designation by amey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.