Find the answer to your Linux question:
Results 1 to 3 of 3
I want to make a Perl script that makes you type the word of the option you want via STDIN. For example: Suppose you are in a script where you ...
  1. #1
    Just Joined! heyyeh's Avatar
    Join Date
    Aug 2008
    Posts
    71

    [SOLVED] Perl: Use STDIN to parse strings

    I want to make a Perl script that makes you type the word of the option you want via STDIN.

    For example:
    Suppose you are in a script where you must type 'area' to activate 'Area.pl' or 'perimeter' to load 'Perimeter.pl'. As a matter of fact, that's what I'm trying to make. But when I test it out, I get an error saying that the STDIN inside the if statement only does kindly to numbers.

    Code:
    $root = '.';
    if (<STDIN> == 'area') {
         system "/usr/bin/perl $root/Area.pl";
    }
    As you can see, instead of numbers, I wanted STDIN to respond to letters type in, but I get an error and stuff falls apart!

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    "==" is Perl's numeric comparison operator. To do a string comparison, use "eq":
    Code:
    $root = '.';
    if (<STDIN> eq 'area') {
         system "/usr/bin/perl $root/Area.pl";
    }
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined! heyyeh's Avatar
    Join Date
    Aug 2008
    Posts
    71
    Alright. That's all I needed.

    The thread is now Case Closed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...