problem with regexp?

W

Wmute

Hello,

I am trying to replace some old Perl scripts with Ruby, however

i get stuck with this line

if line =~/($time)/ && line =~/(xxx)/

<<
$time is a global variable containing the current day/month, but it
wont match!
what am i doing wrong?


I am new to Ruby, so please dont be offended.
 
M

Marcin Mielżyński

Wmute said:
if line =~/($time)/ && line =~/(xxx)/
in Ruby $.. wont reference a variable like in perl, use #{...}


if line =~ /#{time}/ && line =~ /(xxx)/ ....

in case of /#{(time)}/ regexp will be compiled each time...

so you may consider:

r = /#{time}/ , or:
r = Regexp.new(time)


....
probably some loop
....

if line =~ r && ...

lopex
 
M

Michael Ulm

Wmute said:
Hello,

I am trying to replace some old Perl scripts with Ruby, however

i get stuck with this line



if line =~/($time)/ && line =~/(xxx)/

You probably want

if line =~ /#{$time}/ and line =~ /#{xxx}/

(assuming there is a variable called xxx).

HTH

Michael

--
Michael Ulm
R&D Team
ISIS Information Systems Austria
tel: +43 2236 27551-219, fax: +43 2236 21081
e-mail: (e-mail address removed)
Visit our Website: www.isis-papyrus.com

---------------------------------------------------------------
This e-mail is only intended for the recipient and not legally
binding. Unauthorised use, publication, reproduction or
disclosure of the content of this e-mail is not permitted.
This email has been checked for known viruses, but ISIS accepts
no responsibility for malicious or inappropriate content.
---------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top