Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string extraction

Status
Not open for further replies.

sappleg

Programmer
Apr 15, 2008
31
CA
Hi Guys,

I am trying to extract and print a string, which also includes a 'period'. I want all the text before the 'period' sign. For example, the text looks like:

SREI120RE04.
SREI5151RE04.
SREI5151RE05.
SREI5151RE06.

I want to print only text before the period sign, so my output will be:

SREI120RE04
SREI5151RE04
SREI5151RE05
SREI5151RE06

I am trying the following code, but it is not working:
($site is where the above string is defined)

@value=split({$site},".")[1];
foreach $worstation (@value)
{
print "$counter $worstation $date \n";
}

Please suggest and help.
Thanks in advance.
 
You could just remove the dot from the end of the string, or if it is the only dot use tr///:

Code:
$site =~ tr/.//d;
print $site;

There is no need to use split, and your usage is not correct anyway. Did you read the split() functions manpage?




------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
A dot is a special character in a regex, which is what split expects as its first parameter. If you went down that route, you'd have to escape it
Perl:
my @x = split(/\./, $site);

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Thank you guys. It's working now using the above methods.

Quite Appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top