- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: regular expression in perl
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2002 06:19 AM
05-24-2002 06:19 AM
I have the following format:
email address = email@email.com
Does anyone know how can I guarantee to retrieve email@email.com and assign it to a variable?
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2002 06:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2002 06:47 AM
05-24-2002 06:47 AM
Re: regular expression in perl
Basically, my perl file will be feed a file, where I need to search for a specific field, email address:
the file will have email field formatted this way:
email address = email@email.com
here is my perl code:
while($line =
{
if ($line =~ /^email address/)
{
my ($address) = (m/email\s*address\s*=\s*(\S.*)/);
print $address;
}
}
basically, $line will be "email address = email@email.com"
Than, I will need to basically, to parse $line and assign email value to a local variable.
I tried your way, but when I print $address, nothing is displayed.
Thanks for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2002 06:54 AM
05-24-2002 06:54 AM
Re: regular expression in perl
1---
while(
{
if (m/^email address/)
{
my ($address) = (m/email\s*address\s*=\s*(\S.*)/);
print $address;
}
}
---
or
2---
while($line =
{
if ($line =~ /^email address/)
{
my ($address) = ($line =~ m/email\s*address\s*=\s*(\S.*)/);
print $address;
}
}
---
also possible:
3---
while(
{
if ($line =~ m/^email address = (.*)/)
{
my $address = $1;
print $address;
}
}
---
note also that your code is quite rigid with spaces. compare
m/^email address = (.*)/
to
m/\bemail\s+address\s*=\s*(\S.*)/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2002 07:08 AM
05-24-2002 07:08 AM
Re: regular expression in perl
Here is what I have:
while($line =
{
if ($line = m/^email address/)
{
my ($address) = ($line =~ m/\bemail\s+address\s*=\s(\S.*)/);
print $address;
}
}
my template contains the following line:
email address = lz@yahoo.com
For some reasons, print $address doesn't display anything. ;-(
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2002 07:13 AM
05-24-2002 07:13 AM
Re: regular expression in perl
Your example works fine!!
Thanks a lot!