Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

array format question

by janasec (Sexton)
on Jul 26, 2015 at 09:11 UTC ( [id://1136330]=perlquestion: print w/replies, xml ) Need Help??

janasec has asked for the wisdom of the Perl Monks concerning the following question:

I have an array I need some format help,I need to keep this in variable

the code is like this

print "@array_wwpn\n"; chomp @array_wwpn; my $somewwpnNames = join('";', @array_wwpn); print "$somewwpnNames";
@array_wwpn when printed it contains before chomp and join is applied +looks like 10000090fa2edda0 10000090fa2edd9f 10000000c9cdcc6c 10000000c9cdcc6d I need the $somewwpnNames to contain like this $somewwpnNames="10000090fa2edda0";"10000090fa2edd9f";"10000000c9cdcc6 +c";10000000c9cdcc6d";

Replies are listed 'Best First'.
Re: array format question
by pme (Monsignor) on Jul 26, 2015 at 10:06 UTC
    my $somewwpnNames = '"' . join('";"', @array_wwpn) . '";'; print "$somewwpnNames\n";
Re: array format question
by Corion (Patriarch) on Jul 26, 2015 at 09:17 UTC

    Maybe you want to use a proper CSV writer like Text::CSV_XS?

    Also, what is the output you get with your current program, and how is the output you currently get different from what you want? Maybe you are joining the strings with the wrong stuff in the middle?

Re: array format question
by kroach (Pilgrim) on Jul 26, 2015 at 12:19 UTC
    local $"=q(";"); my $somewwpnNames = qq("@array_wwpn";);
Re: array format question
by Laurent_R (Canon) on Jul 26, 2015 at 13:04 UTC
    print join ";", map {'"' . $_ . '"'} @array_wwpn;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1136330]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-28 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found