system( "echo -en 'Enter Pattern :\c'"); $pat = ; open (FILEONE,"file1"); while(){ if($pat=~$_){print $_;} close(FILEONE); open (FILETWO,"file2"); while(){ if($pat=~$_){print $_;) close(FILETWO); end of code-----------------------------------> plz. help me thanks in advance manojvajram __________________________________ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <20040714233447.84157.qmail@web40609.mail.yahoo.com> [ref] => [htmlstate] => on_nl2br [postusername] => Manojkumar [ip] => manojvajram@yah [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 1 [islastshown] => [isfirstshown] => 1 [attachments] => [allattachments] => ) --> > system( "echo -en 'Enter Pattern :\c'"); > $pat = ; > open (FILEONE,"file1"); > while(){ > if($pat=~$_){print $_;} > close(FILEONE); > open (FILETWO,"file2"); > while(){ > if($pat=~$_){print $_;) > close(FILETWO); > > end of code----------------------------------->[/ref] Main problem is you need to chomp() your pattern text, and you have your regex comparisons backwards. The lines: if($pat=~$_){print $_;} Should be: if ($_ =~ $pat) { print $_; } Or, the simpler print if /$pat/; Or, what you *really* want: print if /$pat/o; Other issues: 1. Add "use strict;" at the top of all your programs. "use warnings;" is recommended as well. 2. Don't use system("echo") to print a prompt. Use Perl's print() function. 3. Always check the return value from system calls like open(). 4. Use whitepsace and indententation. 5. Learn statement modifiers for writing clearer code. Perl's not C. Instead of: if (COND) { EXPR; } you can write the clearer: EXPR if COND; 6. Consider a loop to process the two files rather than duplicating code. 7. Since $pat never changes in your program adding /o to the regex will speed up the program. see perldoc perlre for more details. [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <2E4528861499D41199D200A0C9B15BC001D7F0F0@FRISTX> [ref] => [htmlstate] => on_nl2br [postusername] => Bob [ip] => Bob_Showalter@t [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> > system( "echo -en 'Enter Pattern :\c'"); > $pat = ; > open (FILEONE,"file1"); > while(){ > if($pat=~$_){print $_;} > close(FILEONE); > open (FILETWO,"file2"); > while(){ > if($pat=~$_){print $_;) > close(FILETWO); > > end of code----------------------------------->[/ref] I think , it will really help if you spend some time learning perl. Learning Perl , etc from Oreilly is a great starter. Perl is the easiest to learn language I have seen. Coming back to your problem , What you seem to be doing is a simple grep. If you are not on windows , you could say grep PATTERN file1 file2 If you really want to use perl , you can use a commandline like perl -ne '/PATTERN/ && print' Doing it in a seperate perl script is also simple. Just be careful about the matching Regular expression HTH Bye Ram [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <1089895918.6183.67.camel@indl253ga.idc.oracle.com> [ref] => <20040714233447.84157.qmail@web40609.mail.yahoo.com> [htmlstate] => on_nl2br [postusername] => Ramprasad [ip] => ramprasad.padma [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 3 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> search text - PERL Beginners

search text - PERL Beginners

Plz. help me . I am new to perl I want to accept a pattern from screen and search the pattern in my one or two text data base and print the details The pattern from screen may consist spaces and special char. line / - etc. I use redhat linux 8.0 I have coded like below but fetched no result code------------------------------------------> system( "echo -en 'Enter Pattern :\c'"); $pat = <STDIN>; open (FILEONE,"file1"); while(<FILEONE>){ if($pat=~$_){print $_;} close(FILEONE); open (FILETWO,"file2"); while(<FILETWO>){ if($pat=~$_){print $_;) close(FILETWO); end of code-----------------------------------> plz. help me thanks in advance manojvajram __________________________________ Do you Yahoo!? Yahoo! Mail is ...

  1. #1

    Default search text

    Plz. help me . I am new to perl
    I want to accept a pattern from screen
    and search the pattern in my one or two text data base
    and print the details

    The pattern from screen may consist spaces and special
    char. line / - etc.
    I use redhat linux 8.0
    I have coded like below but fetched no result
    code------------------------------------------>
    system( "echo -en 'Enter Pattern :\c'");
    $pat = <STDIN>;
    open (FILEONE,"file1");
    while(<FILEONE>){
    if($pat=~$_){print $_;}
    close(FILEONE);
    open (FILETWO,"file2");
    while(<FILETWO>){
    if($pat=~$_){print $_;)
    close(FILETWO);

    end of code----------------------------------->
    plz. help me
    thanks in advance
    manojvajram



    __________________________________
    Do you Yahoo!?
    Yahoo! Mail is new and improved - Check it out!
    http://promotions./new_mail
    Manojkumar Guest

  2. #2

    Default RE: search text

    manojkumar vajram wrote: 

    Main problem is you need to chomp() your pattern text, and you have your
    regex comparisons backwards.

    The lines:

    if($pat=~$_){print $_;}

    Should be:

    if ($_ =~ $pat) { print $_; }

    Or, the simpler

    print if /$pat/;

    Or, what you *really* want:

    print if /$pat/o;

    Other issues:

    1. Add "use strict;" at the top of all your programs. "use warnings;" is
    recommended as well.

    2. Don't use system("echo") to print a prompt. Use Perl's print() function.

    3. Always check the return value from system calls like open().

    4. Use whitepsace and indententation.

    5. Learn statement modifiers for writing clearer code. Perl's not C. Instead
    of:

    if (COND) { EXPR; }

    you can write the clearer:

    EXPR if COND;

    6. Consider a loop to process the two files rather than duplicating code.

    7. Since $pat never changes in your program adding /o to the regex will
    speed up the program. see perldoc perlre for more details.
    Bob Guest

  3. #3

    Default Re: search text


    On Thu, 2004-07-15 at 05:04, manojkumar vajram wrote: 

    I think , it will really help if you spend some time learning perl.
    Learning Perl , etc from Oreilly is a great starter. Perl is the easiest
    to learn language I have seen.

    Coming back to your problem , What you seem to be doing is a simple
    grep. If you are not on windows , you could say
    grep PATTERN file1 file2

    If you really want to use perl , you can use a commandline like
    perl -ne '/PATTERN/ && print' <file1> <file2>

    Doing it in a seperate perl script is also simple. Just be careful about
    the matching Regular expression


    HTH
    Bye
    Ram




    Ramprasad Guest

Similar Threads

  1. text search through Pdf
    By wkotesh@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 0
    Last Post: December 31st, 08:45 PM
  2. Text Search
    By Alun Davies in forum Dreamweaver AppDev
    Replies: 1
    Last Post: April 6th, 08:37 AM
  3. Exclude text from search
    By tda2 in forum Macromedia ColdFusion
    Replies: 0
    Last Post: February 16th, 09:18 PM
  4. Search Engine for text
    By prince_of_darkness webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 2
    Last Post: July 28th, 02:26 PM
  5. full text search
    By Tommy in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: July 9th, 01:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •