in reply to Re: Perl: Split/format the output and append it to an array
in thread Perl: Split/format the output and append it to an array

The first part worked fine. But before prepend(or)after the array, i would like to have the @xlinkpaths contents also in the same pattern as @exclpaths. That is
1.every value should end with '/'
2. should be enclosed within quotes ""
3. Should have comma ',' at end
How can I achieve this? I want to maintain the same exisitng format in @exclpaths array
  • Comment on Re^2: Perl: Split/format the output and append it to an array

Replies are listed 'Best First'.
Re^3: Perl: Split/format the output and append it to an array
by shmem (Chancellor) on Sep 12, 2014 at 19:52 UTC
    1.every value should end with '/'
    2. should be enclosed within quotes ""
    3. Should have comma ',' at end

    See the concatenation operator '.' in perlop, Additive Operators, and substr.

    Read perlop. All of it.

    I want to maintain the same exisitng format in @exclpaths array

    The format in your @exclpaths is its representation in code. Inside the array, the strings are not enclosed within double quotes, and they don't have a comma at the end:

    my @exclpaths = ( "wefwfewf/fewfff/", "btrtbrtb/gbrgbrg/rttty/", ); print $_,"\n" for @exclpaths; __END__ wefwfewf/fewfff/ btrtbrtb/gbrgbrg/rttty/

    If you want decorations, just add them:

    my @exclpaths = ( "wefwfewf/fewfff/", "btrtbrtb/gbrgbrg/rttty/", ); print "\"$_\",\n" for @exclpaths; __END__ "wefwfewf/fewfff/", "btrtbrtb/gbrgbrg/rttty/",
    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'