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: Beginner:
pattern matching

 



changalrai
New User

Sep 21, 2010, 1:31 PM

Post #1 of 2 (460 views)
pattern matching Can't Post

HI All,

i have file called file.txt it contains :

name: karemaips01;

name: karemadom02;

name: karemadbo01;

name: karemadom01.emea.pfizer.com;

name: karemasss05;

name: ka-lvsapp;

name: emakars001.pfizer.com;

name: ka-lvsn1;

name: ka-efss;

name: ka-lvsn2;

name: karemafil-c;

name: ka-lvscluco;

name: ka-lvsdb;



I need to check line by line and capture only after :(colan) and before ;(semicolan). after capture and print.

examples: name: karemaips01;

karemaips01



thanks.


7stud
Enthusiast

Sep 21, 2010, 1:45 PM

Post #2 of 2 (458 views)
Re: [changalrai] pattern matching [In reply to] Can't Post

1)

Code
use strict;  
use warnings;
use 5.010;

my $string = 'name: karemaips01;';

my @pieces = split /:/, $string;
say substr $pieces[1], 0, -1;

---output:--
karemaips01

If you don't want the space in front of the name, start the substr() at position 1; or split() on a colon and a space.

2)

Code
use strict;  
use warnings;
use 5.010;

my $string = 'name: karemaips01;';

$string =~ /: (.+?) ;/xms;
say $1;

--output:--
karemaips01



(This post was edited by 7stud on Sep 21, 2010, 1:51 PM)

 
 


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

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