CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Pattern Matching..Need Help

 



iamperl
New User

Sep 30, 2014, 12:13 AM

Post #1 of 7 (8494 views)
Pattern Matching..Need Help Can't Post

Hi,

How can I extract the number which is next to EEE in the following line.(condition is the number should be extracted only if the EEE is found in the line).

1234567 EEE 8901234


BillKSmith
Veteran

Sep 30, 2014, 5:06 AM

Post #2 of 7 (8488 views)
Re: [iamperl] Pattern Matching..Need Help [In reply to] Can't Post

What have you tried?

Code
use strict; 
use warnings;
my $sample = '1234567 EEE 8901234';
(my $number) = $sample =~ /EEE\s(\d+)/;
print $number;


OUTPUT:

Code
8901234

Good Luck,
Bill


iamperl
New User

Sep 30, 2014, 10:06 PM

Post #3 of 7 (8470 views)
Re: [BillKSmith] Pattern Matching..Need Help [In reply to] Can't Post

Thank you very much Bill it's working perfectly. I missed (\s) when I was trying.

One more question->Could you please let me know how to read .pdf format file into the program for processing? I am able to read .txt format file without any issues but unable to read .pdf file.


(This post was edited by iamperl on Sep 30, 2014, 10:08 PM)


BillKSmith
Veteran

Oct 1, 2014, 5:03 AM

Post #4 of 7 (8442 views)
Re: [iamperl] Pattern Matching..Need Help [In reply to] Can't Post

Post a sample. Tell us what errors you are getting.


On some systems (e.g. windows), you must use the function binmode for image files. Its use is recommended even if you do not need it.
Good Luck,
Bill


iamperl
New User

Oct 1, 2014, 5:39 AM

Post #5 of 7 (8437 views)
Re: [BillKSmith] Pattern Matching..Need Help [In reply to] Can't Post

Hi Bill,
I am a beginner in PERL.I've written a code using PERL to print ranks(inputs from a file .txt) that belongs to specific category and that are lesser than a given rank(user given).For testing my code I used a .txt document which contains some ranks that are related to EC category. In this case I am getting my intended output. But when I am reading a .pdf file the program is exiting immediately. I guess the reason for early exiting is I am wrong with the pattern that should be matched when reading .pdf file. Kindly please help me in fixing the issue. I am attaching the screen shots of the input files .txt and .pdf. Thanks.
Attachments: INPUTS.zip (25.2 KB)


BillKSmith
Veteran

Oct 1, 2014, 6:57 AM

Post #6 of 7 (8427 views)
Re: [iamperl] Pattern Matching..Need Help [In reply to] Can't Post

You do not seem to understand what a .pdf file is. I do not now anything about the format, but I do know that in general the file does not contain text, but rather an image of your document. Extracting text from that image requires character recognition software. This is well beyond the capability of most perl programmers. You may find a module on CPAN that will help. I suspect that you will need commercial software to preprocess your file.
Good Luck,
Bill


Laurent_R
Veteran / Moderator

Oct 1, 2014, 3:02 PM

Post #7 of 7 (8387 views)
Re: [iamperl] Pattern Matching..Need Help [In reply to] Can't Post

To iamperl: please open a new thread when you have questions on a totally different subject. This will give you more chances to get good answers, and also allow a better referencing for people looking for answers.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives