![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| regex question | xiamin | Shell Programming and Scripting | 3 | 03-05-2009 02:53 AM |
| Help with grep and regex | raichlea | UNIX for Dummies Questions & Answers | 14 | 04-16-2008 11:25 AM |
| regex in variable | alias47 | UNIX for Dummies Questions & Answers | 4 | 08-08-2007 08:37 AM |
| Regex?? Please help | lunac | UNIX for Dummies Questions & Answers | 7 | 01-30-2007 01:13 PM |
| sed regex | Shakey21 | UNIX for Dummies Questions & Answers | 4 | 01-31-2002 09:16 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Regex
Hi,
i want to match a string using perl that has got 5 pluses(+++++). i am using a function for this. $str1="+++++"; check($str1,"\\+"); sub check{ $str1=$_[0]; $str2=$_[1]; if($str1=~m/^$str2{5}$/){ print "Correct.\n"; }else{ print "Wrong..\n"; } } But i am getting the output as wrong. if i use if($str1=~m/^\+{5}$/) this i will get correct output. Please help me. Thanks, Deepak |
|
||||
|
Code is working fine.
Code:
$ cat spt
#!/usr/bin/perl
$str1="+++++";
check($str1,"\\+");
sub check{
$str1=$_[0];
$str2=$_[1];
if($str1=~m/^$str2{5}$/){
print "Correct.\n";
}else{
print "Wrong..\n";
}
}
$ ./spt
Correct.
|
|
||||
|
ya this is working fine.
but if i change the code like using another variable $no. #!/usr/bin/perl $str1="+++++"; $no=5; check($str1,"\\+",$no); sub check{ $str1=$_[0]; $str2=$_[1]; $str3=$_[2]; if($str1=~m/^$str2{$str3}$/){ print "Correct.\n"; }else{ print "Wrong..\n"; } } perl test1.pl Wrong.. Help me please... Thanks, Deepak |
|
||||
|
Quote:
Without that it would work !!! ![]() Code:
#! /opt/third-party/bin/perl
sub check {
$first = $_[0];
$character = $_[1] . "{" . $_[2] . "}";
print "yes\n" if( $first =~ m/^$character$/ );
}
$str = "+++++";
$no = 5;
check($str, "\\+", $no);
exit 0
|
|
||||
|
Quote:
|
|
||||
|
how about this
do_something if m/[+]{5}/ |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| perl, perl regex, regex |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|