in reply to Removing a Pattern matched in a Scalar

Well, i'd choose to put these things in arrays and hashes if i where you, this is a string, where you use :: and || as delimiters.
In this case, it's easy to remove using a regexp, since you allways start with ::
#!/usr/bin/perl # use strict; my $scalar = "::fruits||apple::fruits||orange::vegetable||celery::vege +table||lettuce"; $scalar =~ s/::vegetable\|\|celery//; print $scalar;
Anyway, play with it, and try something like this:
#!/usr/bin/perl # use strict; use Data::Dumper; my @arr = ( {fruits => "apple"}, {fruits => "orange"}, {vegetable => "celery"}, ); print Dumper(@arr);
"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.

Replies are listed 'Best First'.
Re^2: Removing a Pattern matched in a Scalar
by anonymized user 468275 (Curate) on Jul 25, 2005 at 09:26 UTC
    It looked more natural to me to express the keys and values in reverse, than have to force an array into it:
    my %hash = ( apple => fruits, orange => fruits, celery => vegetable );

    One world, one people