I have to read individual lines but store only values within the quotes
(values after =)
I heard in java there is some get property which picks values after '='
and so on.
Let me know if there is any ruby equivalent to this or any other method
to get this done.
I heard in java there is some get property which picks values after '='
and so on.
Let me know if there is any ruby equivalent to this or any other method
to get this done.
I was just wondering, should we not refuse to use ^ for the beginning
of a string ( even knowing it is a line )? I personally have abandoned
^ for \A for quite some time now. Is nobody going to follow ;).
Just my 0.03€ ( yeah inflation )
R.
···
On Mon, Aug 10, 2009 at 9:20 PM, Joel VanderWerf<vjoel@path.berkeley.edu> wrote:
Joel VanderWerf wrote:
Harry Kakueki wrote:
h = Hash[*(shellwords(source.gsub("="," ")))]
source.gsub(/^([^=]+)=/) {$1}
sorry, should be:
source.gsub(/^([^=]+)=/) {$1 + " "}
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
where a & b are variables i am storing these values into.
You would never do that. You store multiple values in arrays. For
instance,
data = ["hello", "hi", "goodbye"]
puts data[1]
--output:--
"hi"
You can get the data out of your file without using regex's like this:
results =
IO.foreach("data.txt") do |line|
pieces = line.split("=")
val = pieces[1].strip #remove spaces on the left and the right
val = val[1...-1] #slice off the quotes
results << val
end
On Mon, Aug 10, 2009 at 9:20 PM, Joel VanderWerf<vjoel@path.berkeley.edu> wrote:
source.gsub(/^([^=]+)=/) {$1 + " "}
I was just wondering, should we not refuse to use ^ for the beginning
of a string ( even knowing it is a line )? I personally have abandoned
^ for \A for quite some time now. Is nobody going to follow ;).
Didn't the OP want each line converted? It's getting hard to remember... Anyway, I did mean ^ in my answer, but maybe I was confused about the question.
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
I was just wondering, should we not refuse to use ^ for the beginning
of a string ( even knowing it is a line )? I personally have abandoned
^ for \A for quite some time now. Is nobody going to follow ;).
I didn't follow you, but I've been using \A..\z for years.
This is certainly an area where Ruby can trip you up dangerously, if
you're expecting Perl-like regular expression behaviour.
Sorry my bad. I did not realize from the snippet that you were doing
the whole source in one thing. But I should have, given the *g*sub.
Yes of course you need to use ^.
As a matter of fact my point was not to use it on lines, because ^
matches at the beginning of a *line* while when we are treating lines
there are no lines anymore and we want to match at the beginning of a
*string*, hence \A.
Cheers
Robert
···
2009/8/17 Joel VanderWerf <vjoel@path.berkeley.edu>:
Robert Dober wrote:
On Mon, Aug 10, 2009 at 9:20 PM, Joel VanderWerf<vjoel@path.berkeley.edu> >> wrote:
source.gsub(/^([^=]+)=/) {$1 + " "}
I was just wondering, should we not refuse to use ^ for the beginning
of a string ( even knowing it is a line )? I personally have abandoned
^ for \A for quite some time now. Is nobody going to follow ;).
Didn't the OP want each line converted? It's getting hard to remember...
Anyway, I did mean ^ in my answer, but maybe I was confused about the
question.
where a & b are variables i am storing these values into.
You would never do that.
Well, I guess that's not true. You can do this:
results = ["hello", "hi", "goodbye"]
a, b, c = results
puts a, b, c
--output:--
hello
hi
goodbye
-----------------------
HI,
Let me be more clear over the requirement , my intention to read from
a remote file & store the values into a variable so that i can make use
of these variables for my automation.
let me try reading this array using a File.open if it works!!