How to Convert a String to INT PERL

104 4
    • 1). Right-click your PERL file and select "Open With." Click your PERL editor, then click "Open." If you do not have a specialized PERL editor, click "Notepad," then click "Open." You can edit PERL code with the internal Windows Notepad program.

    • 2). Create your PERL function to parse the string and convert the string to the "int" data type. Type the following code anywhere in your PERL code file:

      sub convert_to_in {

      my $string;

      foreach my $string (split(//, shift())) {

      $string = $string * 10 + $d;

      }

      return $string;

      }

      This function converts any string into the integer data type. You can send any string to the function to convert it to a number.

    • 3). Call the new function in your code. Scroll down to the part of your code where you need to convert the string. Type the following code to convert your string:

      $converted= convert_to_int("123");

      The code above converts the string "123" to the numeric value and stores it in the "$converted" variable. Replace "123" with your own string to convert.

    • 4). Press "Ctrl" and "S" to save your changes. Use your PERL editor to run the file and test your changes, or open the file in your Web browser to test the code.

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.