[ic] perl issue

DB DB at M-and-D.com
Sat Jul 17 19:29:33 EDT 2004


> This is tested code:
> 
> Example 1:
> my $prefix;
> if ($string =~ /^([^-]+-)/) {
> 	$prefix = $1;
> }
> 
> Method 2:
> 
> my $prefix = join('',(split(/(-)/,$string,2))[0..1]);
> 
> 
> Method 3: the last one broken down for clarity;
> 
> my $string = 'ABC-DEF-G';
> 
> my @tmp = split(/(-)/,$string,2);
> # @tmp is ('ABC','-','DEF','-','G')
> 
> my $prefix = $tmp[0] . $tmp[1];

Aha thanks I did get that to work. But I guess I phrased my question 
poorly... I want to keep what remains and discard the $prefix. In other 
words I want to remove the first hyphen and all the comes before it 
leaving everything else. I can probably cobble together somethign based 
on your post but of course I welcome any input.

DB




More information about the interchange-users mailing list