perl doubt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl doubt
# 1  
Old 11-15-2011
perl doubt

Hi,

Please help me to understand the following code:
Code:
perl -lne 'print if "$_ " =~ /(5 (?:\d+ ){5})\1/'

What the regular expression "?:" does?
Also, whether the expression "\1" is the same as in sed (i.e) printing the elements inside pair of parentheses?

Last edited by royalibrahim; 11-16-2011 at 01:21 AM..
# 2  
Old 11-15-2011
Quote:
Originally Posted by royalibrahim
...
What the regular expression "?:" does?
Also, whether the expression "\1" is same same as in sed (i.e) printing the elements inside pair of parentheses?
"(?: )" is the non-capturing (or grouping-only) parenthesis. It groups regex components, but does not capture them. And so, the regex components are not stored in variables $1, $2, $3, ... etc.

"\1" is the back-reference, or reference to an earlier parenthesized expression. Yes, its role in Perl is the same as in sed, but with certain limitations.

tyler_durden
# 3  
Old 11-16-2011
Thanks durden_tyler !!

Can you also please explain what the command does?
# 4  
Old 11-16-2011
Quote:
Originally Posted by royalibrahim
...Can you also please explain what the command does?
Sure.
It prints the standard input if it is comprised of two groups of regex components, each of which consists of the digit 5 followed by a space followed by five groups of tokens, each of which, in turn, consists of one or more digits followed by a space.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. Shell Programming and Scripting

Doubt..

Hi experts, In one of our code we have used some command like this. name=${name##*/} Can someone please let me know what exactly it does? Thanks & Regards, Sathya V. (1 Reply)
Discussion started by: Sathya83aa
1 Replies

3. Shell Programming and Scripting

Trivial perl doubt about FILE

Hi, In the following perl code: #!/usr/bin/perl -w if (open(FILE, "< in_file")) { while (<FILE>) { chomp($_); if ($_ =~ /patt$/) { my $f = (split(" ", $_)); print "$f\n"; } } close FILE; } Why changing the "FILE" as... (4 Replies)
Discussion started by: royalibrahim
4 Replies

4. UNIX for Advanced & Expert Users

doubt in df -h

in my parition i hav parition like this Filesystem Size Used Avail Use% Mounted on /dev/sda2 24G 22G 756M 97% / /dev/sda5 248G 1.2G 234G 1% /else /dev/sda1 965M 24M 892M 3% /boot tmpfs 7.0G 0 7.0G 0%... (1 Reply)
Discussion started by: ponmuthu
1 Replies

5. Shell Programming and Scripting

Doubt in Perl Variable declaration

Anyone please say what is the difference between $var and ${var} in perl Sometimes $var used and sometimes ${var} used in same program. Thanks in Advance, Prabhu ---------- Post updated at 09:34 AM ---------- Previous update was at 05:59 AM ---------- Any one please clarify (1 Reply)
Discussion started by: prsampath
1 Replies

6. Shell Programming and Scripting

Perl map doubt

Hello , Please can someone tell me what exactly happens when the below filehandler is chomped into an array and later mapped. $lcpLog="logcopy\@".getTimestamp."\log"; open CFg ,"< $lcpcfg"; chomp(@cfg = <CFG>); close CFG; @cfg=grep { $_ ne ' ' } map { lc + (split /\s*\/\//) }... (0 Replies)
Discussion started by: rmv
0 Replies

7. Shell Programming and Scripting

Perl script doubt?

Dear friends, I have two files. In first file first column ($1), i have numbers. The second file containes, the same number in the fourth column($4). I need a output file, matching the first file column 1 with second file column 4. The main thing is the output file lines will be sorted... (4 Replies)
Discussion started by: vasanth.vadalur
4 Replies

8. Shell Programming and Scripting

perl doubt plz explain....

hi all i wrote a shell script which uses perl script my code is : >cat filename | while read i >do >perl -e 'require "/home/scripts/abc.pl" ; abc("$i")' >done perl script used will simply check syntax of Cobol programs but it didn't work for me so i asked my colleague he suggested... (1 Reply)
Discussion started by: zedex
1 Replies
Login or Register to Ask a Question