Problem with if statement in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with if statement in perl
# 1  
Old 10-04-2008
Problem with if statement in perl

Code:
if (($fields[16] eq $hwp) && ($fields[18] eq 'Y'))
{
        $fields[22] = "INTEGRAL";
}
elsif ($fields[16] eq $hwp)
{
        $fields[22] = "INTEGRAL";
}
elsif ($fields[16] ne $hwp)
{
        $fields[22] = "SEPARATE";
}

print "$fields[16] $fields[18] $fields[22]\n";

Output:
Quote:

34 Y SEPARATE
34 Y SEPARATE
34 Y SEPARATE
34 Y SEPARATE
34 Y SEPARATE
34 Y SEPARATE
34 Y SEPARATE
34 Y SEPARATE
34 Y SEPARATE
The problem here is that the first condition is true so it should print INTEGRAL but it is printing SEPARATE.

I am absolutely clueless because the same logic is working fine for another condition in the program.

Cheers,
AK
kamitsin
# 2  
Old 10-04-2008
Suggest you temporarily modify your code to print out $hwp. I think you will find that it's value is not 34.
# 3  
Old 10-04-2008
if (($fields[16] eq $hwp) && ($fields[18] eq 'Y'))

Does $hwp = 34?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl - what does this statement mean -Regex

push @MACARRAY, "$+{catalog} $+{machine}\n" if ($info =~ /(?<catalog>catalog).+?(?<machine>\*+)/ms); I am (still) trying to solve problem. Looking around on the server I found this piece of code. Specifically what does "$+{catalog} $+{machine}\n" do ? Thanks in advance (1 Reply)
Discussion started by: popeye
1 Replies

2. Shell Programming and Scripting

Understanding perl statement

can someone help me how to interpret this line? my ($class, $hashref) = @_; my $portfolio = {}; if ($hashref->{portfolio_id}) { ($portfolio) = GEmySQL->get ("select * from portfolio where portfolio.id=$hashref->{portfolio_id}"); } =============== Question: how do... (2 Replies)
Discussion started by: onlinelearner02
2 Replies

3. Shell Programming and Scripting

Multiple Conditions Perl if Statement

Hello, I'm trying to put together a script that involves pulling data from a config file. I'm attempting to write an if statement to validate one of the pieces of data from the config file, but I think I'm fat fingering it somehow. $config{VALUE} is being pulled from a config file but can only... (4 Replies)
Discussion started by: Picch
4 Replies

4. UNIX for Dummies Questions & Answers

Help with Perl If statement

Hi All, I am writing a perl script where I take 2 variables from the user as STDIN to scan the lines of a file to produce as output. How can I do an IF loop to test this for example in the mock file 12 10 35 20 37 5 45 12if I take user input as 40 and 10, how can I get the output lines in... (3 Replies)
Discussion started by: pawannoel
3 Replies

5. Shell Programming and Scripting

Perl nested if statement

I'm just having a bit of trouble running this code. It tells me that there's a syntax error on line 29. Any help appreciated. #!/usr/bin/perl # # Phone Book Application # %phonebook = ( "Wayne", '34687368', "Home", '378643287', "Work", '017374637', "School",... (2 Replies)
Discussion started by: cabaiste
2 Replies

6. Shell Programming and Scripting

Condition statement in perl

#!/usr/bin/perl $output1 = "/home/log.txt" $output2 = "/home/grep.txt" #Statement1 creates an output file called log.txt. #Statement2 greps a line from log.txt and store the result in grep.txt I want to create a condition where if the file grep.txt is empty repeat process. Thanks. (1 Reply)
Discussion started by: sureshcisco
1 Replies

7. Shell Programming and Scripting

help with if statement perl scripting

Sorry for the newbie question I need to create a perl script to check the modifed time of a file I already have that part created but need help in creating a if statement that basicly will check to see if the modifed time is at least 2hrs older then the current time if the stament is true to... (2 Replies)
Discussion started by: nettech207
2 Replies

8. Shell Programming and Scripting

Help with perl and if file statement

Hello and thank you in advance. I have a perl script that will basically copy files out of a directory , creat a new current date stamped dir and move them that current time stamped dir and append the file names with current time stamp. I need to add line(s) that this is only run if FileX... (1 Reply)
Discussion started by: Dadwith2boys
1 Replies

9. UNIX for Dummies Questions & Answers

Perl / Interpret Unix If statement

Hi all, I am a newbie, so please let me know if there is a better way to do this. I coded a perl script, that scans a Unix script and picks out certain strings (strings that precede ".log"). However I want to limit the strings it picks up based on the "If statements" in the unix script. ... (0 Replies)
Discussion started by: syera123
0 Replies

10. Shell Programming and Scripting

perl if statement

Hello guys, I was wondering why my code doesn't read a variable when using if statement as follows: $userlist='users.txt'; $user='b999'; open (ACTULOG, ">>$userlist"); print ACTULOG "$user\n"; close (ACTULOG) this will work and prints... (3 Replies)
Discussion started by: Bashar
3 Replies
Login or Register to Ask a Question