07-18-2013
Yes. However its a good practice to add checks before assigning $1, $2 to make sure that the regexp above worked and those special variables were defined. The above script assumes that every line exactly matches the regexp given.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
$mystring = "name:blk:house::";
print "$mystring\n";
@s_format = split(/:/, $mystring);
for ($i=0; $i <= $#s_format; $i++) {
print "index is $i,field is $s_format";
print "\n";
}
$size = $#s_format + 1;
print "total size of array is $size\n";
i am expecting my size to be 5, why is it... (5 Replies)
Discussion started by: new2ss
5 Replies
2. Shell Programming and Scripting
I am interested in 2 and 36th fields in this input file. I was wondering if there was a more efficeint way to do this.
($pt1,$bkup_name,$pt3,$pt4,$pt5,$pt6,$pt7,$pt8,$pt9,
$pt10,$pt11,$pt12,$pt13,$pt14,$pt15,$pt16,$pt17,
... (7 Replies)
Discussion started by: reggiej
7 Replies
3. Shell Programming and Scripting
Collegues
I have flat file in the following format.
137 (NNP Kerala) (NNP India)
92 (NN Rent) (NN Range)
70 (NNP Thiruvananthapuram) (NNP Kerala)
43 (NNP Tourist) (NNP Home)
40 (NNP Reserve) (NNP Now)
25 (SYM @) (NN hotelskerala)
25 (NNP Thiruvananthapuram-695001) (NNP Kerala)
23 (NN... (3 Replies)
Discussion started by: jaganadh
3 Replies
4. UNIX for Advanced & Expert Users
Hi,
I have to split a line of the form
1232423#asdf#124324#54534#dcfg#wert#rrftt#4567
into an array in perl. I am using
@fields;
@fields=split('#',$line);
if($fields eq "1")
But this is not working. By using the syntax, the statements in "if" are never executed. Please help.... (9 Replies)
Discussion started by: rochitsharma
9 Replies
5. Shell Programming and Scripting
hi, I have a seemingly really stupid question, but here goes!
What do you enter into split delimiter to seperate something like this
"December 12, 1995"
and get
December
12
1995
?
thanks (5 Replies)
Discussion started by: ade214
5 Replies
6. Homework & Coursework Questions
Hi... I have a question regarding the split function in PERL.
I have a very huge csv file (more than 80 million records). I need to extract a particular position(eg : 50th position) of each line from the csv file. I tried using split function. But I realized split takes a very long time.
Also... (1 Reply)
Discussion started by: castle
1 Replies
7. Shell Programming and Scripting
Hi... I have a question regarding the split function in PERL.
I have a very huge csv file (more than 80 million records). I need to extract a particular position(eg : 50th position) of each line from the csv file. I tried using split function. But I realized split takes a very long time.
Also... (1 Reply)
Discussion started by: castle
1 Replies
8. Shell Programming and Scripting
Hi,
I have tried the split and join functions but stuck with unexpected results. Any help appreciated. I pass multiple values at command line like perl test.pl -type java,xml. This works good for me but i am not sure how to print it in the required format.
Here is the code i tried:... (4 Replies)
Discussion started by: nmattam
4 Replies
9. Shell Programming and Scripting
my @d =split('\|', $_);
west|ACH|3|Y|LuV|N||N||
Qt|UWST|57|Y|LSV|Y|Bng|N|KT|
It Returns d as 8 for First Line, and 9 as for Second Line . I want to Process Both the Files, How to Handle It. (3 Replies)
Discussion started by: vishwakar
3 Replies
10. Shell Programming and Scripting
Hi,
I need your help for below with shell scripting or perl
I/P
key, Sentence
customer1, I am David
customer2, I am Taylor
O/P
Key, Words
Customer1,I
Customer1,am
Customer1,David
Customer2,I
Customer2,am
Customer2,Taylor (4 Replies)
Discussion started by: monishathampi
4 Replies
LEARN ABOUT CENTOS
perl::critic::policy::regularexpressions::prohibitcapturewithout
Perl::Critic::Policy::RegularExpressions::ProhibitCapturUserhContributed PePerl::Critic::Policy::RegularExpressions::ProhibitCaptureWithoutTest(3)
NAME
Perl::Critic::Policy::RegularExpressions::ProhibitCaptureWithoutTest - Capture variable used outside conditional.
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
If a regexp match fails, then any capture variables ($1, $2, ...) will be undefined. Therefore it's important to check the return value of
a match before using those variables.
This policy checks that the previous regexp for which the capture variable is in-scope is either in a conditional or causes an exception or
other control transfer (i.e. "next", "last", "redo", "return", or sometimes "goto") if the match fails.
A "goto" is only accepted by this policy if it is a co-routine call (i.e. "goto &foo") or a "goto LABEL" where the label does not fall
between the "goto" and the capture variable in the scope of the "goto". A computed "goto" (i.e. something like "goto (qw{foo bar
baz})[$i]") is not accepted by this policy because its target can not be statically determined.
This policy does not check whether that conditional is actually testing a regexp result, nor does it check whether a regexp actually has a
capture in it. Those checks are too hard.
This policy also does not check arbitrarily complex conditionals guarding regexp results, for pretty much the same reason. Simple things
like
m/(foo)/ or die "No foo!";
die "No foo!" unless m/(foo)/;
will be handled, but something like
m/(foo) or do {
... lots of complicated calculations here ...
die "No foo!";
};
are beyond its scope.
CONFIGURATION
By default, this policy considers "die", "croak", and "confess" to throw exceptions. If you have additional subroutines or methods that may
be used in lieu of one of these, you can configure them in your perlcriticrc as follows:
[RegularExpressions::ProhibitCaptureWithoutTest]
exception_source = my_exception_generator
BUGS
This policy does not recognize named capture variables. Yet.
AUTHOR
Chris Dolan <cdolan@cpan.org>
COPYRIGHT
Copyright (c) 2006-2011 Chris Dolan.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.16.3 2014-06Perl::Critic::Policy::RegularExpressions::ProhibitCaptureWithoutTest(3)