CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Basic comparison problem


New User

May 21, 2010, 10:30 AM

Post #1 of 3 (788 views)
Basic comparison problem Can't Post

Goal: read all lines of a file, colon delimited, searching for a specific server name (always located in the first field). If the current server equals the servername in that 1st field, then populate 2 other variables based on 2nd and 3rd fields.

On an aix system.

When I try to compare strings using eq, it always evaluates true.

When I try with == it always evaluates false.

Where system hostname = x100

/inputfile reads:

x100:KRB Master:NIM
x101:Some other stuff:Cognos, WAS

# Read the Description File
open(INP, $desc_file) || die("Could not find $desc_file ! Aborting!");

$text = <INP>;
while ($text){


if ( $host eq $ahost ){

$text = <INP>;

Thanks ahead for help!


May 21, 2010, 11:46 AM

Post #2 of 3 (784 views)
Re: [aixrus] Basic comparison problem [In reply to] Can't Post



use strict;
use warnings;

chomp( my $host = `hostname` );

# Read the Description File
my $desc_file = "/inputfile";
open my $input_fh, '<', $desc_file or die "Could not open $desc_file: $!\n";

while( my $text = <$input_fh> ){
my ( $ahost, $desc, $apps ) = split /\:/, $text;
if( $host eq $ahost ){
# Do something with $ahost, $desc and $apps

close $input_fh or die "Could not close $desc_file: $!\n";


I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

New User

May 24, 2010, 11:58 AM

Post #3 of 3 (761 views)
Re: [shawnhcorey] Basic comparison problem [In reply to] Can't Post


I tried the first change you made, which was the chomp... and it worked!

All I needed to do was chomp $host, even though the var looked ok, it had the CR in it, thus causing the comparison to be strange.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives