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:
how would i get a part of a text file into a variable

 



gerble1000
User

Nov 8, 2013, 1:02 PM

Post #1 of 3 (1028 views)
how would i get a part of a text file into a variable Can't Post

hay guyz
i have this text file that has this line in it


Code
require("InitialJSLoader").handleServerJS({"require":[["GraphExplorer","init",["m_0_0"],[145634995501787,100004468957112,"CAACEdEose0cBACYxggh75LrXW4vkjFlw0M8c4zIf6J7bIlt8xxlpyC6Qla3a36ll2QxNZBbZBERceG6qI5uVwpZAmI05MuQeWA0DoVUqSXPppmvRi2pe7XhN2wo0nLZAPIX9ZAbgqv8DEFFkU06CdFtUiCewZCsENCz5RLp1DeCbzvvT1EjaReKabwcLJOEbgZD",["apps.uses","apps.rates","apps.saves","books.reads","book


i would need to grab this string which could change length
CAACEdEose0cBACYxggh75LrXW4vkjFlw0M8c4zIf6J7bIlt8xxlpyC6Qla3a36ll2QxNZBbZBERceG6qI5uVwpZAmI05MuQeWA0DoVUqSXPppmvRi2pe7XhN2wo0nLZAPIX9ZAbgqv8DEFFkU06CdFtUiCewZCsENCz5RLp1DeCbzvvT1EjaReKabwcLJOEbgZD

as far as i am aware the number of characters leading up to the string stay the same but im not 100% sure on that
im thinking maybe count the "" quotes and grab the string inside the 11th and 12th quote on that line.

tricky one :)
any ideas


Laurent_R
Veteran / Moderator

Nov 8, 2013, 3:29 PM

Post #2 of 3 (1014 views)
Re: [gerble1000] how would i get a part of a text file into a variable [In reply to] Can't Post

Yes, I have many ideas, this is something that I am doing almost daily, there are a number of ways to do that, split and regexes are the most likely candidates, but there is no way I can say how to do it without having a pattern, and a pattern can't be derived from a single line of input.

If you know something on how these records are constructed, please provide as much information as you can, and, if you don't (actually even if you do) please provide a more significant data sample (at least a few dozens lines).


gerble1000
User

Nov 8, 2013, 5:06 PM

Post #3 of 3 (1011 views)
Re: [Laurent_R] how would i get a part of a text file into a variable [In reply to] Can't Post

thankyou for making me think about it with split function.
i have made it work though might not be the best way.
i done this

Code
open(FILE, '<:utf8', 'token.txt'); 
my @lines = <FILE>;
close FILE;


my @values = split('"', @lines[24]);

open (FILE, '>token.txt');
print FILE @values[11];
close File;



(This post was edited by gerble1000 on Nov 8, 2013, 5:06 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