LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-21-2009, 05:10 AM   #1
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Arrow matching pattern in perl


hi all......

This is my perl script:

while ($text){
if($text=~ /^\s+\S+\s+CHAR|VARCHAR2/){
print ($text);


CONTENTS TO BE MATCHED IN A FILE:

NAME CHAR(5);
VIN CHAR(5);
CLASS VARCHAR2(18,2);
ADDS CHAR(30);

here i am not able to match any of these....can anyone please help me......

Thanks in advance......

Last edited by vinaytp; 06-21-2009 at 05:12 AM.
 
Old 06-21-2009, 05:18 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Well, /^\s/ will fail on the lines you've posted,
none of them begin with whitespace
 
Old 06-21-2009, 05:50 AM   #3
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
Talking

Quote:
Originally Posted by Tinkster View Post
Well, /^\s/ will fail on the lines you've posted,
none of them begin with whitespace
sorry...actually it has white spaces..i forgot to put.....

Last edited by vinaytp; 06-21-2009 at 05:51 AM.
 
Old 06-21-2009, 07:06 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
simpler:
1) split the line into array on whitespaces
2) iterate the array using for loop
3) check for each item, use /^(CHAR|VARCHAR)/
 
Old 06-21-2009, 01:27 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Btw, if the code-snippet is complete ... where do you
change $text for the next iteration? Or is the whole
file in the scalar?



Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with perl - pattern matching johngreg Programming 5 10-13-2008 02:08 PM
Perl pattern matching - greedy wondergirl Programming 2 06-17-2008 04:32 PM
Perl pattern matching in VB rigel_kent Programming 1 05-30-2006 12:00 PM
Perl Pattern Matching Question pete1234 Programming 2 08-27-2005 11:26 AM
pattern matching in perl ludeKing Programming 9 04-02-2004 10:53 AM


All times are GMT -5. The time now is 09:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration