Change The Value Of A Item In An Array

Posted on 2006-05-21
Last Modified: 2010-03-05

While looping threw an array how do I change the value of a item?

my $NewNameToAdd = "Distance=584";
my $WordToRemove = "Distance::Required=584";

my @Array ('LeftSegmentHeight=45','Distance::Required=584','RightSegmentHeight=789');

my @Array ('LeftSegmentHeight=45','Distance=584','RightSegmentHeight=789');
Question by:blnukem
    LVL 4

    Accepted Solution

    do something like

    foreach(@Array) {
    # modify $_ in here
    # like s/something/something else/;


    @Array = map {s/::.*?=/=/;$_;} @Array;
    LVL 4

    Expert Comment

    for (@Array) {
     if ($_ eq 'Something') {
      $_ = 'something_else';
    LVL 84

    Expert Comment

    s/::.*?=/=/ for @Array;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    Title # Comments Views Activity
    perl rename 2 134
    HTTP Error 502.2 - Bad Gateway 3 181
    Perl string replace for refred url 9 48
    Perl string filter 5 45
    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now