Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1115823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:12:45+00:00 2026-05-17T03:12:45+00:00

$ cat flaglist.log flag1 flag2 flag3 flag4 $ Perl code my $infile = flaglist.log;

  • 0
$ cat flaglist.log
flag1
flag2
flag3
flag4
$

Perl code

my $infile = "flaglist.log";
open my $fpi, '<', $infile or die "$!";
while (<$fpi>) {
    chomp;  
    if ($ENV{$_}) {   # something wrong here
        func($_);
    }       
    else {  
        print "oops\n";
    }       
}

$ perl code.pl
oops
oops
oops
oops
$

All the four flags are names of environment variables that are set (I checked using echo $flag1 from the shell).

Here the if condition always returns false. If I write $ENV{flag1}, it results to true and func() is called as I expected.

What am I doing wrong at the if statement?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T03:12:45+00:00Added an answer on May 17, 2026 at 3:12 am

    The code seems to work for me. Try stripping any whitespace from the input lines:

    while (<$fpi>) {
        s/\s+//g;
        # ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$ cat names projectname_flag_jantemp projectname_flag_febtemp projectname_flag_marchtemp projectname_flag_mondaytemp $ Perl code: my $infile = names;
cat file_ro.py import sys def file_open(filename): fo=open(filename,'r') fo.seek(7) read_data=fo.read(3) fo.close() print read_data file_open(file.py) But
I have these: $ cat a.tmp ABB.log ABB.log.122 ABB.log.123 I wanted to find a
I want to cat an apache log and then output the result to a
I tried the following code unsuccessfully cat pbcopy >> newFile How can you save
When I use cat test.file, it will show printf This is a test log
function getWriters(cat, lev, id) { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome,
$ cat read.sh #!bin/bash // how can I read the columnwise data to awk-script?
$ cat isbndb.sample | wc -l 13 $ var=$(cat isbndb.sample); echo $var | wc
How can I cat a remote file? Currently, it works for local files only.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.