Sponsored Content
Full Discussion: substr function in perl
Top Forums UNIX for Dummies Questions & Answers substr function in perl Post 302302556 by tukuna82 on Tuesday 31st of March 2009 09:44:17 AM
Old 03-31-2009
Question substr function in perl

Hi friends,

I have written a perl code and it works fine but I am not sure tommorow it works or not, please help me.
problem : When diff is 1 then success other than its failure but tomorrow its 20090401 and the enddate is 20090331. thats why I write the code this type but it does not work and when date = 20090402, enddate = 20090331, it should failure.
Thanks in advance.

Here is one part of the my code..
Code:
#!/usr/bin/perl

use strict;
my $status = "";
my $dt = `date +%Y%m%d`;
#my $dt = "20090401";
my $enddate="20090331";
my $diff = $dt - $enddate;
#print $diff;
if ((substr($dt,7)=01 && (substr($enddate,7)=31)) || (substr($dt,7)=01 && (substr($enddate,7)=30)))
        {
           $status = "successful";
        }
        elsif ($diff = 01)
        {
            $status = "successful";
        }
        else
        {
            $status = "failure";
        }
print $status;


Last edited by otheus; 04-15-2009 at 09:04 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trouble using substr function with Bourne shell script

Hi, I'm a newbie to UNIX scripting and I'm having some trouble compiling my script. I'm using the Bourne Shell and cannot seem to use the substr function correctly. I'm trying to extract the last two digits of a year that's stored in a variable based off of a condition. I've searched the... (4 Replies)
Discussion started by: E2004
4 Replies

2. Shell Programming and Scripting

copy substr in existing string in Perl

Any clue to write something to a particular location in Perl? Suppose $line = ‘abc cde 1234” How to write ( example string "test") on location 4 without parsing the whole line. Output should be $line = ‘abctest 1234” this is not search and replace. just to add substring into... (3 Replies)
Discussion started by: jaivipin
3 Replies

3. UNIX for Dummies Questions & Answers

substr in perl

Let's assume that I have a file with contents delimited by pipe: "The mouse|ran up|the|clock" "May|had a|little|lamb" How would I use 'substr' to get the 3rd field. For example, "the" from the first line, and "little" from the second line? # Loop over a file and read $LINE { ... (2 Replies)
Discussion started by: ChicagoBlues
2 Replies

4. Shell Programming and Scripting

20090620231013 to date format i am using substr, any simple way in perl?

Hi Everyone, $tmp="20090620231013"; $tmp = substr($tmp,0,8)." ".substr($tmp,8,2).":".substr($tmp,10,2).":".substr($tmp,12,2); So my output is: 20090620 23:10:13. I only can think substr is easy, any perl can do this just one line very simple efficient one? :eek: Thanks (3 Replies)
Discussion started by: jimmy_y
3 Replies

5. Shell Programming and Scripting

use of substr function in awk

i want to get substring of second coloum of an file using awk substring function.please help me out (2 Replies)
Discussion started by: RahulJoshi
2 Replies

6. Shell Programming and Scripting

The function of substr clause in awk command

Hello all, Please help me in letting me know the function of *substr* function in awk... actually i am new with this function i can play with awk but for this function needs your help in making me understand the correct way of using it. I am writting a code please advice regarding this... (4 Replies)
Discussion started by: jojo123
4 Replies

7. Shell Programming and Scripting

help required for 'expr substr' function

hi iam trying to extract a certain portion of the string whose value is stored below,but am getting syntax eror.The command is shown below for file in GMG_BASEL2*.txt do m1= cat reporting_date.txt year= expr substr $m1 1 2 echo $year done m1 has date 10/31/2009 but this vale... (6 Replies)
Discussion started by: jagadeeshn04
6 Replies

8. Shell Programming and Scripting

perl file, one line code include "length, rindex, substr", slow

Hi Everyone, # cat a.txt a;b;c;64O a;b;c;d;ee;f # cat a.pl #!/usr/bin/perl use strict; use warnings; my $tmp3 = ",,a,,b,,c,,d,,e,,f,,"; open(my $FA, "a.txt") or die "$!"; while(<$FA>) { chomp; my @tmp=split(/\;/, $_); if ( ($tmp =~ m/^(64O)/i) || ($tmp... (3 Replies)
Discussion started by: jimmy_y
3 Replies

9. Shell Programming and Scripting

Converting shell to Perl I run into shell built in function trap and need alternative in Perl

I am working on converting shell to Perl script. In shell we have built in function trap Do you know alternative in Perl or actually we don't need it? Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies

10. Shell Programming and Scripting

Perl substr or similar help

I have a large string containing about 17,500 characters and I would like to obtain the value for token. token only appears in the entire string once and is towards the end of the string at the 17,200 area but that could change. Using perl can someone assist me with obtaining the value which in... (10 Replies)
Discussion started by: azdps
10 Replies
CORELIST(1)						 Perl Programmers Reference Guide					       CORELIST(1)

NAME
corelist - a commandline frontend to Module::CoreList DESCRIPTION
See Module::CoreList for one. SYNOPSIS
corelist -v corelist [-a|-d] <ModuleName> | /<ModuleRegex>/ [<ModuleVersion>] ... corelist [-v <PerlVersion>] [ <ModuleName> | /<ModuleRegex>/ ] ... corelist [-r <PerlVersion>] ... corelist --diff PerlVersion PerlVersion OPTIONS
-a lists all versions of the given module (or the matching modules, in case you used a module regexp) in the perls Module::CoreList knows about. corelist -a Unicode Unicode was first released with perl v5.6.2 v5.6.2 3.0.1 v5.8.0 3.2.0 v5.8.1 4.0.0 v5.8.2 4.0.0 v5.8.3 4.0.0 v5.8.4 4.0.1 v5.8.5 4.0.1 v5.8.6 4.0.1 v5.8.7 4.1.0 v5.8.8 4.1.0 v5.8.9 5.1.0 v5.9.0 4.0.0 v5.9.1 4.0.0 v5.9.2 4.0.1 v5.9.3 4.1.0 v5.9.4 4.1.0 v5.9.5 5.0.0 v5.10.0 5.0.0 v5.10.1 5.1.0 v5.11.0 5.1.0 v5.11.1 5.1.0 v5.11.2 5.1.0 v5.11.3 5.2.0 v5.11.4 5.2.0 v5.11.5 5.2.0 v5.12.0 5.2.0 v5.12.1 5.2.0 v5.12.2 5.2.0 v5.12.3 5.2.0 v5.12.4 5.2.0 v5.13.0 5.2.0 v5.13.1 5.2.0 v5.13.2 5.2.0 v5.13.3 5.2.0 v5.13.4 5.2.0 v5.13.5 5.2.0 v5.13.6 5.2.0 v5.13.7 6.0.0 v5.13.8 6.0.0 v5.13.9 6.0.0 v5.13.10 6.0.0 v5.13.11 6.0.0 v5.14.0 6.0.0 v5.14.1 6.0.0 v5.15.0 6.0.0 -d finds the first perl version where a module has been released by date, and not by version number (as is the default). --diff Given two versions of perl, this prints a human-readable table of all module changes between the two. The output format may change in the future, and is meant for humans, not programs. For programs, use the Module::CoreList API. -? or -help help! help! help! to see more help, try --man. -man all of the help -v lists all of the perl release versions we got the CoreList for. If you pass a version argument (value of $], like 5.00503 or 5.008008), you get a list of all the modules and their respective versions. (If you have the "version" module, you can also use new-style version numbers, like 5.8.8.) In module filtering context, it can be used as Perl version filter. -r lists all of the perl releases and when they were released If you pass a perl version you get the release date for that version only. As a special case, if you specify the module name "Unicode", you'll get the version number of the Unicode Character Database bundled with the requested perl versions. EXAMPLES
$ corelist File::Spec File::Spec was first released with perl 5.005 $ corelist File::Spec 0.83 File::Spec 0.83 was released with perl 5.007003 $ corelist File::Spec 0.89 File::Spec 0.89 was not in CORE (or so I think) $ corelist File::Spec::Aliens File::Spec::Aliens was not in CORE (or so I think) $ corelist /IPC::Open/ IPC::Open2 was first released with perl 5 IPC::Open3 was first released with perl 5 $ corelist /MANIFEST/i ExtUtils::Manifest was first released with perl 5.001 $ corelist /Template/ /Template/ has no match in CORE (or so I think) $ corelist -v 5.8.8 B B 1.09_01 $ corelist -v 5.8.8 /^B::/ B::Asmdata 1.01 B::Assembler 0.07 B::Bblock 1.02_01 B::Bytecode 1.01_01 B::C 1.04_01 B::CC 1.00_01 B::Concise 0.66 B::Debug 1.02_01 B::Deparse 0.71 B::Disassembler 1.05 B::Lint 1.03 B::O 1.00 B::Showlex 1.02 B::Stackobj 1.00 B::Stash 1.00 B::Terse 1.03_01 B::Xref 1.01 COPYRIGHT
Copyright (c) 2002-2007 by D.H. aka PodMaster Currently maintained by the perl 5 porters <perl5-porters@perl.org>. This program is distributed under the same terms as perl itself. See http://perl.org/ or http://cpan.org/ for more info on that. perl v5.16.2 2013-08-25 CORELIST(1)
All times are GMT -4. The time now is 12:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy