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:
Need the data at the end of a line, but nothing else

 



ACtheMadScripter
Deleted

Oct 30, 2000, 10:48 PM

Post #1 of 5 (502 views)
Need the data at the end of a line, but nothing else Can't Post

I need the price off the end of this line but nothing else from it.

This is the line
New item posted, #971884540 (TomCruise Missles):::971798140:::-1.00:::Posting fee of $-1.00 charged.:::-4.92

i know i need to use reg exp, but the syntax always confuses me.

Plz help a Mad Man out :)


------------------
AC the Mad Scripter
Script long and prosper!


ACtheMadScripter
Deleted

Oct 30, 2000, 10:56 PM

Post #2 of 5 (502 views)
Re: Need the data at the end of a line, but nothing else [In reply to] Can't Post

P.S. The number at the end can be positive or negitive and can also be a number into the 1000's as in 5000.00 or -5000.00

Thanks for all help ,

------------------
AC the Mad Scripter
Script long and prosper!


japhy
Enthusiast

Oct 31, 2000, 11:52 AM

Post #3 of 5 (502 views)
Re: Need the data at the end of a line, but nothing else [In reply to] Can't Post

You can use split:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


($price) = (split /:/, $string)[-1];
</pre><HR></BLOCKQUOTE>

Or a regular expression:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


($price) = $string =~ /([^:]+)$/;
</pre><HR></BLOCKQUOTE>

Or my RegexParser module (requires Perl 5.6.0):

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use RegexParser 'reverse_match';
($price) = reverse_match $string => qr/([^:]+)$/;
</pre><HR></BLOCKQUOTE>

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher



ACtheMadScripter
Deleted

Oct 31, 2000, 12:20 PM

Post #4 of 5 (502 views)
Re: Need the data at the end of a line, but nothing else [In reply to] Can't Post

Excellent, i am gunna use the split function.
That seems to be good for my needs.
We arn't updated to 5.6.0 yet.
Can you help me to understand why that particular function (split) works the way it does and why it doesn't it read the -1.00 in the string


japhy
Enthusiast

Oct 31, 2000, 12:38 PM

Post #5 of 5 (502 views)
Re: Need the data at the end of a line, but nothing else [In reply to] Can't Post

The split() function splits a string into pieces based on some regular expression. You want the last one, so I took the element of the list it returns with an index of -1, which is the last element. Read perldoc -f split for more info, or read the perlfunc documentation online at http://www.perldoc.com/.

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


 
 


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

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