>>>>> "Roland" == Roland Corbet <[EMAIL PROTECTED]> writes:

> Is there any easy way to add two characters to the start of each item in a 
> list.

> I have a list, for example, containing "ID" as the first element, and 
> "PRICE" as the second element.  (The quotes are not actually stored in the 
> element.)

> What I need the list to become like is as though it was set up the same as 
> typing:

> @ary = (\$ID,\$PRICE);

> So, I need to add a \ and $ to the start of each item.

> I know I could do this by stepping through the list and joining it onto 
> "\\$" and then pushing it back in to another list.  However, this seems a 
> little bit over complicated.  Surely, Perl has a trick up its sleeve - 
> maybe a substitution of some sort.

How about:

foreach (@ary)
{
   s/^/\\\$/;
}

I tried it and it seems to work.

Sarir

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl

Reply via email to