Perl: How to convert xxx@dom.ain.com to domaincom


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl: How to convert xxx@dom.ain.com to domaincom
# 1  
Old 04-30-2008
Perl: How to convert xxx@dom.ain.com to domaincom

Hi,

Is there a way to convert xxx@dom.ain.com to domaincom, so to remove everything before and including @ and then to remove the dot from the rest of the line?

I know I can do:

Code:
$str = "xxx\@dom.ain.com";
print "String before: $str\n";
$str =~ s/.*?@//;
$str =~ s/\.//g; 
print "String after: $str\n";

Which outputs:
Code:
String before: xxx@dom.ain.com
String after: domaincom

But is there a way of combining the two operations into one?

Thanks!
# 2  
Old 04-30-2008
Quote:
Originally Posted by Juha
But is there a way of combining the two operations into one?
Because the first substitution can only occur once, doing it with /g is harmless:

Code:
s/(.*?@|\.)//g

In the general case, mixing non-/g and /g substitutions isn't really possible, and extracting tokens between separators isn't really doable if you want to do some other substitution at the same time.
# 3  
Old 04-30-2008
Thanks era!!! I tried probably everything else but left the brackets away Smilie
# 4  
Old 04-30-2008
Quote:
Originally Posted by Juha
Thanks era!!! I tried probably everything else but left the brackets away
Actually they aren't necessary. Good catch, or something ...

Samma på finska?
# 5  
Old 04-30-2008
If by brackets you mean () they are not even necessary:

Code:
$str = "xxx\@dom.ain.com";
print "String before: $str\n";
$str =~ s/[^@]*@|\.//g; 
print "String after: $str\n";


Last edited by KevinADC; 04-30-2008 at 03:34 AM.. Reason: I posted a different regexp
# 6  
Old 04-30-2008
Quote:
Originally Posted by era
Actually they aren't necessary. Good catch, or something ...

Samma på finska?
oops, sorry, we were posting at about the same time. Your post was not there when I read the thread. Smilie
# 7  
Old 04-30-2008
Yep Smilie Samma på finska Smilie

Thanks for both of you era and KevinADC!
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning DOM Object value to an array

Hi, I have the following code that makes use of a URL that I store in a variable then create a document object below to work on it. $dom = new DOMDocument; @$dom->loadHTML($html); $links = $dom->getElementsByTagName('a'); $links = $dom->getElementsByTagName('a'); ... (0 Replies)
Discussion started by: mojoman
0 Replies

2. Red Hat

Gnome3 locksup on new Linux kernel 12.6.xxx & 12.5.xxx

Hi Forum Ive been having a problem with the kernal(s) for some strange reason it every time I try and access the date and time/calendar or system settings it locks up the whole laptop and nothing responds. :(. This doesn't happen 11.10.xxx kernel . Any help would be much appreciated and thank you... (1 Reply)
Discussion started by: ShinTec
1 Replies

3. AIX

echo $varibla | mail -s "subject" "xxx@xxx.com" not ruuning as expected

Hi Folks, As per the subject, the following command is not working as expected. echo $variable | mail -s "subject" "xxx@xxx.com" Could anyone figure it out whats wrong with this. I am using AIX box. Regards, (2 Replies)
Discussion started by: gjarms
2 Replies

4. UNIX for Advanced & Expert Users

Perl XML::DOM: How to test if element exists?

Hi, I'm trying to write a script for some xml file handling, but I'm not getting too far with it. I've got the following xml content <?xml version="1.0" encoding="UTF-8"?> <Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <Operation name="OPER1"> <Action name="ACTION1">... (2 Replies)
Discussion started by: Juha
2 Replies

5. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

6. AIX

Perl Module (XML:DOM) dependency

Hi All, I am facing dependency on AIX :confused:.I am trying to run an script which requires PERL MODULE (XML::DOM) to be installed. Please find the attached file which shows the error i am getting (cant locate XML/DOM.pm in @INC). Please let me know how to install PERL MODULE (XML::DOM) ... (3 Replies)
Discussion started by: srivatsa86
3 Replies

7. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies

8. News, Links, Events and Announcements

Halloween IX: It Ain't Necessarily SCO

Check this out: http://www.opensource.org/halloween/halloween9.php (0 Replies)
Discussion started by: Neo
0 Replies
Login or Register to Ask a Question