LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 02: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, 03:22 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
The operator is !~, not !=~
 
Old 04-12-2010, 01:56 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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

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

All times are GMT -5. The time now is 09:43 AM.

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
Open Source Consulting | Domain Registration