logo
down
shadow

In Perl, how can I tell if a string is a number, but without using modules?


In Perl, how can I tell if a string is a number, but without using modules?

Content Index :

In Perl, how can I tell if a string is a number, but without using modules?
Tag : perl , By : Brian Cupps
Date : January 11 2021, 05:14 PM

this will help for comments ikegami and melpomene.
The reason why I want to try it because the module is a "program" as well. I want to learn how to realize it by myself. After all, we meet all kinds of data which need to handle.
"The first word is identifier, which will not be considered. The rest part of the string would be number or alphabet only. "
#!/usr/bin/perl -w

use strict;
use warnings;
#import Scalar::Util qw(look_like_number);

my @log=("a1 9 2 3 1","gl act car","zo4 4 7", "abl off key dog","a8 act zoo");
print "original log:\n";
$"=";\t";   #control array's delimiter
print "@log\n";

my @values;
my @letter_log;
my @letter_idf;
my @dig_log;
my $s;
my $i;
my $s_r;

$i=0;
foreach(@log)
{
  @values=split(/\s+/,$_);chomp(@values);
  @_= m/$values[0]\s/;
print "25 \$'=$';\n";
  $s=$';
  $s_r=substr($s,0,1);
  if($s_r =~ /\D/)  
  {  print"26.0: $'\ts=$s\ts_r=$s_r\n";    
     $letter_idf[$i]=$values[0];
     $letter_log[$i]=$s;
     print "26:  $letter_idf[$i]\t$letter_log[$i]\n";$i++;
  }
  else{$dig_log[$i]=$_;}
}

@_=sort { $letter_log[$a] cmp $letter_log[$b] } 0..$#letter_log;
chomp(@_);

print"35:  srt letter  log: @letter_log\n";
#foreach(@letter_log){print "$_;\t";}

print"38: nsrt letter log: ";
for($i=0;$i<=$#letter_log;$i++){print"$letter_idf[$_[$i]] "."$letter_log[$_[$i]];\t";}
print"\n";
print"41: digital log:";
foreach(@dig_log){print "$_;\t";}

print "\n";

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Is there a way to avoid putting the Perl version number into the "use lib" line for Perl modules in non-standa


Tag : perl , By : kennystone
Date : March 29 2020, 07:55 AM
wish of those help Currently I have installed via the following prescription, which seems to fix things.
perl Makefile.PL --no-manpages --skipdeps PREFIX=/non/system/location INSTALLSITELIB=/non/system/location/lib INSTALLSITEBIN=/non/system/location/bin INSTALLMAN1DIR=/non/system/location/man/man1 INSTALLMAN3DIR=/non/system/location/man/man3

Defining constants for a number of scripts and modules in perl


Tag : perl , By : Mostapen
Date : March 29 2020, 07:55 AM
I hope this helps you . Create a module to hold your configuration information.
In file My/Config.pm in your perl library path:
package My::Config;
use warnings;
use strict;
use Carp ();

my %setup = (
   one => {path => '/some/path'},
   two => {path => '/other/path'},
);

my $config = $setup{ $ENV{MYCONFIG} }
     or Carp::croak "environment variable MYCONFIG must be set to one of: "
              .(join ' ' => keys %setup)."\n";

sub AUTOLOAD {
    my ($key) = our $AUTOLOAD =~ /([^:]+)$/;
    exists $$config{$key} or Carp::croak "no config for '$key'";
    $$config{$key}
}
use My::Config;

my $path = My::Config->path;

A proper way of using Perl custom modules inside of other Perl modules


Tag : eclipse , By : Cube_Zombie
Date : March 29 2020, 07:55 AM
Hope that helps I strongly disagree with modifying @INC in modules. It causes all kinds of headaches. Let the script (or even the calling process via the PERL5LIB environment variable) setup @INC correctly.
script.pl:
use FindBin qw( $RealBin );
use lib
   "$RealBin/../ModulesFolder1",
   "$RealBin/../ModulesFolder2";

use ModuleInFolder1;
use ModuleInFolder2;  # Works fine.

Perl to generate one executable file for a script which uses any number of modules and libraries


Tag : perl , By : Arun Thomas
Date : March 29 2020, 07:55 AM
will be helpful for those in need pp script provided with PAR::Packer is able to create single-file executables. An example from its page:
pp -o foo foo.pl bar.pl   # Pack 'foo.pl' and 'bar.pl' into 'foo'

Can I re-use modules compiled with a different build of Perl, but with the same version number?


Tag : perl , By : Tonix
Date : March 29 2020, 07:55 AM
I wish this help you It turns out that, YES, you can re-use modules compiled with different builds of Perl that have the same version number. The trick, as stated above, is to build your localperl with the ./Configure flags as close as possible to your system Perl. You can determine the ./Configure flags your system Perl uses by running perl -V. You should then use those settings with the flags listed above. My intuition is that -Dcc= and -Darchname= are the critical ones to match, though I have not had time to test this assumption.
So, what was my problem if I had already done all of this, and it still wasn't working? Simple - the test script! In my shebang line, I was still pointing to a faulty build of Perl that I had compiled earlier that day! D'oh! Once I pointed the script to the new build with all of the extra ./Configure options, it worked perfectly fine and was able to use all of the modules built with system Perl.
Related Posts Related QUESTIONS :
  • How can I extract sentences with a particular phrase, in Perl?
  • Dequeue an array in perl with thread::queue
  • How do I tell perl to execute a piece of generated Perl code?
  • Why does a positive lookahead lead to captures in my Perl regex?
  • In a digital photo, how can I detect if a mountain is obscured by clouds?
  • How can I pass a hash to a Perl subroutine?
  • Why do I get 'use: command not found' when I run my Perl script?
  • How can I take a reference to specific hash value in Perl?
  • How do I find the sum of all values from two different arrays in Perl?
  • How can I determine which package my constructor was called from?
  • How do I install Perl's Lingua::Lid?
  • How can I copy a directory but ignore some files in Perl?
  • How can I build something like Amazon S3 in Perl?
  • What does Perl's -p command-line switch do?
  • How can I get the high-res mtime for a symbolic link in Perl?
  • How can I get the ultimate URL without fetching the pages using Perl and LWP?
  • How can I create a new file using a variable value as the name in Perl?
  • Why does my Perl CGI program fail with "Software error: ..."?
  • How can I handle -r=<pattern> with Perl's Getopt::Long?
  • Is there a way that I can force mod_perl to re-use buffer memory?
  • How do I issue an HTTP redirect with Perl's CGI.pm?
  • Can I pass a regex to isa() with Moose-based objects?
  • How can I tell Perl's IO::Socket::INET which interface to use?
  • How do I print a hash structure in Perl?
  • What reasons could there be for converting Perl to Java?
  • Command executed in SSH terminal displays extra line contents
  • Documentation on Serving static files
  • Is Perl cpan's 2.4 Spreadsheet::WriteExcel entirely compatible running code written for its preceding 2.2 version?
  • Command line arguments only work for first element of array
  • Enable a user option to override a value for a variable
  • Assign number to variable in perl subroutine [assign returned list to variables]
  • Comparing three files in Perl
  • Perl - Directory Management on Different Operating Systems
  • Display lines outside multiline comment block
  • Is there a fairly portable and succinct method for parsing an environment variable from a script?
  • Need help understanding how Perl 5 is parsing a compound assignment statement referencing same variable
  • What exactly is happening in this piece of perl code?
  • Tail call Recursion "Optimising"
  • "isn't numeric" error in "sort" after "uniq"
  • Having trouble with the one_of feature in Getopt::Long::Descriptive
  • LWP::UserAgent loses content data when redirecting via POST
  • Bit selection in perl
  • How to use timestamp to get recent files in Perl
  • Perl, How to sort hash (of arrays) keys according to specific positions in arrays
  • Perl How to remove a directory after program finishes
  • Using Mojo::DOM to extract untagged text after heading
  • How do I check if an object is valid when pushed to an ArrayOf[] member in my perl Moo class?
  • Perl: How to deal with a duplicated modules installation?
  • How to print filtered output list of an external command in Perl?
  • Sorting with filehandle perl
  • Why do official perl docker images have two version of perl?
  • How to change markdown fenced block language
  • How to read every single file in a directory using foreach perl
  • Perl: Verifying user input
  • How to automate the LSF waiting based on job name in perl
  • Verifying user input in perl
  • Perl File::Find isn't running recursively
  • Is it possible to change Perl installation directory
  • Perl Term::Readline for multiple terminal history
  • unpacking an unknown serialised format with variable length
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com