LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-24-2012, 02:04 PM   #1
mrm5102
Member
 
Registered: Apr 2011
Location: Philadelphia
Posts: 154

Rep: Reputation: 3
Equivalent to Perl's "=~" Operator?


Hello All,

Alright, so this is driving me absolutely insane. I can't seem to find this ANYWHERE...
I've tried every combination and synonym I can think of for this trying to search Google.

What is the Expect/Tcl equivalent to Perl and Bash's "=~" operator, (i.e. the "contains" operator).
I'm trying to do an if statements to check if a line contains a specific string, and the only operators I could find anywhere for Expect are (==, !=, <=, >=, <, >)...

Anyone have any clue if it's possible to do a pattern match in an Expect Script's if statement?
Any thoughts would be much appreciated.

Thanks in Advance,
Matt
 
Old 07-24-2012, 08:53 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
I don't know enough about Tcl to say whether it includes a functional equivalent to Perl's =~ binding operator.

But you might be interested in this: http://search.cpan.org/~rgiersig/Expect-1.15/Expect.pod
 
Old 07-24-2012, 09:16 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,396

Rep: Reputation: 814Reputation: 814Reputation: 814Reputation: 814Reputation: 814Reputation: 814Reputation: 814
I don't know tcl either but the Tcl Reference Manual page for strings says:

Quote:
string first needleString haystackString ?startIndex?
Search haystackString for a sequence of characters that exactly match the characters in needleString. If found, return the index of the first character in the first such match within haystackString. If not found, return -1.
...
 
Old 07-25-2012, 08:21 AM   #4
mrm5102
Member
 
Registered: Apr 2011
Location: Philadelphia
Posts: 154

Original Poster
Rep: Reputation: 3
Hey guys, thanks for your replies...

I came across what I was looking for last night.
Expect/Tcl doesn't exactly have a REGEX operator like Perl's "=~" operator but I did find this and it seems to do what I need.

Here's an example of the regexp command for Expect/Tcl in the If Statement below:
Code:
set myString "foo"

expect {
    -re ".*foo.*" {
            send "ls -l\r"
            # Loop through the previous send command's output line-by-line
            foreach line [split $expect_out(buffer) "\n"] {
                # If the current line contains $myString, then...
                if {[regexp ".*$myString.*" $line]} {
                        puts "FOUND WHAT I'M LOOKING FOR!"
                }
            }
}

Thanks Again,
Matt
 
  


Reply

Tags
expect, tcl


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: how to save an e-mail attachment on disk keeping the "&" character (no "%26"!!) d1s4st3r Programming 5 09-29-2010 09:30 PM
"Failed Dependency error" while installing RPM for "DateTime" perl modules giridhargopal.cj Linux - Newbie 7 11-19-2008 12:05 AM
Is there an "apt-get" equivalent of "yum list available"? geeeeky.girl Linux - General 3 07-20-2008 08:40 PM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 04:51 AM
Perl question concerning the "next" operator joesbox Programming 3 03-27-2005 08:59 PM


All times are GMT -5. The time now is 06:08 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration