Hi

As you are new here, you need to first learn how to post questions and what you should do before asking questions here. First you have to try yourself that how you will learn.

Here is the little bit code I write for you, It asks any string(first/last) name and checks with each line of the music.txt file, if matches prints the details as you asked.

use strict; use warnings; use Data::Dumper; open(FH, "<", "./music.txt") or die $!; while(1) { print "Enter Either First or Last name of the artist -1 to qui +te>"; my $input =<STDIN>; chomp($input); if($input eq '-1') { exit; } if($input =~/^$/) { next; } &findArtist($input); } sub findArtist { my $userInput=shift; my $eachLine; my ($artistName,$cdTitle,$date,$price); my $flag=0; seek(FH, 0, 0); while($eachLine=<FH>) { ($artistName,$cdTitle,$date,$price)= split(/:/,$eachL +ine); if($artistName =~/$userInput/i){ print "Artist Name:$artistName\n","CD title:$c +dTitle\n","Date:$date\n","Price:\$$price\n"; $flag=1; } } print "Artist not found\n" unless($flag); } close(FH);
Update:

Fixed the bug posted by marto, thanks marto, good exercise for me.


All is well

In reply to Re: extraction of data by vinoth.ree
in thread extraction of data by crazyghost

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.