J
Jason Quek
Hi
What I need to do is to print only '1|2|3'.
#----------------------------------------------------------------
@array = (
'1',
'1|2',
'1|2|3',
'1|2|3|4',
'1|2|3|4|5',
'1|2|3|4|5|6'
);
$string = '1|2';
foreach (@array)
{
if ($_ =~ /^$string\|([^\|]*)$/)
{
print "$_\n";
}
}
#----------------------------------------------------------------
But the above code prints the entire array out.
I believe the problem lies with ([^\|]*).
How do I correctly tell Perl to recognise the pipe | character inside
([^\|]*)
Any help would be appreciated.
Jason Q.
What I need to do is to print only '1|2|3'.
#----------------------------------------------------------------
@array = (
'1',
'1|2',
'1|2|3',
'1|2|3|4',
'1|2|3|4|5',
'1|2|3|4|5|6'
);
$string = '1|2';
foreach (@array)
{
if ($_ =~ /^$string\|([^\|]*)$/)
{
print "$_\n";
}
}
#----------------------------------------------------------------
But the above code prints the entire array out.
I believe the problem lies with ([^\|]*).
How do I correctly tell Perl to recognise the pipe | character inside
([^\|]*)
Any help would be appreciated.
Jason Q.