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 8708693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:11:54+00:00 2026-06-13T04:11:54+00:00

I have the question in Perl: To write a Perl script which will ask

  • 0

I have the question in Perl:
To write a Perl script which will ask the user for a temperature and then ask whether it is to be converted to degree Celius or Fahrenheit. Perform the conversion and display the answer. The equations for temperature conversion are:

1) Celsius to Fahrenheit:C=(F-32) x 5/9
2) Fahrenheit to Celsius:F=9C/5 + 32

My script is:

#!/usr/bin/perl
use strict;
use warnings;

print "Enter the temperature: ";
my $temp = <STDIN>;
print "Enter the Conversion to be performed:";
my $conv = <STDIN>;
my $cel;
my $fah;

if ($conv eq 'F-C') {

   $cel = ($temp - 32) * 5/9;
   print "Temperature from $fah degree Fahrenheit is $cel degree Celsius";
}

if ($conv eq 'C-F') {

    $fah = (9 * $temp/5) + 32;
    print "Temperature from $cel degree Celsius is $fah degree Fahrenheit"; 
}

After I enter $temp and $conv from the keyboard, blank output will appear.Where am I going wrong? Please help. Thanks in advance.

  • 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-06-13T04:11:55+00:00Added an answer on June 13, 2026 at 4:11 am

    After the input, you will have a newline character in your variables. Use chomp to get rid of it.

    Then there will be a second problem – you are using $fah or $cel in your output statement. This should be the $temp variable, otherwise you will get an error like this:

    Use of uninitialized value $cel in concatenation (.) or string at…

    Here is the updated code:

    #!/usr/bin/perl
    use strict;
    use warnings;
    print "Enter the temperature: ";
    my $temp = <STDIN>;
    chomp($temp);
    print "Enter the Conversion to be performed:";
    my $conv = <STDIN>;
    chomp($conv);
    my $cel;
    my $fah;
    if ($conv eq 'F-C')
    {
     $cel = ($temp - 32) * 5/9;
     print "Temperature from $temp degree Fahrenheit is $cel degree Celsius";
    }
    if ($conv eq 'C-F')
    {
     $fah = (9 * $temp/5) + 32;
     print "Temperature from $temp degree Celsius is $fah degree Fahrenheit"; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a perl script (or any executable) E which will take a file
I have a Perl question like this: Write a Perl program that will read
I have written a Perl script for the following bioinformatics question, but unfortunately there
I have question about XSLT1.0. The task is to write out in HTML all
Suppose I have a Perl script, namely mytest.pl. Can I run it by something
What should you call after printing HTML from a Perl CGI script? I have
I have a perl script creates a text file, writes captured lines from a
I have a need to upgrade a Perl CGI script where the users must
i'm trying to write a script which would process certain files. The data are
I have to modify some Perl scripts for a piped run and write a

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.