LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-11-2010, 03:56 PM   #1
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Rep: Reputation: 33
!=~ is equal to =~ ?? perl script acting unusual


Hi,

Code:
#!/usr/bin/perl

$out = "File";
open FILE, $out or die $!;

while(<FILE>){

if( $_ !=~ /NAME.SRC1.*Running./){
print "$_\n";
  }
}

close FILE;
File
Code:
NAME(SRC0)                                       STATUS(Ended normally)
NAME(SRC01)                                      STATUS(Running)
NAME(SRC1)                                       STATUS(Running)

When I execute.

Code:
check.pl 
NAME(SRC0)                                       STATUS(Ended normally)

NAME(SRC01)                                      STATUS(Running)

NAME(SRC1)                                       STATUS(Running)

now when I change !=~ to =~

Code:
#!/usr/bin/perl
$out = "File";


open FILE, $out or die $!;
while(<FILE>){

if( $_ =~ /NAME.SRC1.*Running./){

print "$_\n";

  }
}

close FILE;
I get this
Code:
check.pl 
NAME(SRC1)                                       STATUS(Running)
Which make sense. But the first one !=~ brings a false positive.

Any Ideas?

Thanks
 
Old 04-11-2010, 04:22 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613
The operator is !~, not !=~
 
Old 04-12-2010, 02:56 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
In addition, always start Perl progs with
Code:
#!/usr/bin/perl -w
use strict;
http://perldoc.perl.org/
http://www.perlmonks.org/?node=Tutorials
 
  


Reply


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
New to Perl, and its acting funny SuperDude123 Programming 18 10-03-2009 12:33 AM
Shell script - Pass command options with equal sign fabdog Linux - Newbie 5 02-13-2009 07:32 AM
perl Script acting strange. knockout_artist Linux - Newbie 3 10-28-2008 02:34 PM
Perl to create an empty line if fields are equal ryedunn Programming 2 08-16-2006 04:14 PM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 11:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:51 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration