Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > problem with regexp?

Reply
Thread Tools

problem with regexp?

 
 
Wmute
Guest
Posts: n/a
 
      02-03-2006
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.

 
Reply With Quote
 
 
 
 
Marcin Mielżyński
Guest
Posts: n/a
 
      02-03-2006
Wmute wrote:

>
> 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
 
Reply With Quote
 
 
 
 
Michael Ulm
Guest
Posts: n/a
 
      02-03-2006
Wmute wrote:

> 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: http://www.velocityreviews.com/forums/(E-Mail 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.
---------------------------------------------------------------


 
Reply With Quote
 
Wmute
Guest
Posts: n/a
 
      02-03-2006
Thanks! problem solved!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments