If you're just translating shell scripts, you shouldn't have any need to escape the pipes in the data. In that case plum's use of split should work fine and it will keep the code local and minimize dependencies, making it easier to wrap your mind around while you're learning perl.

The other question is where you want to put the data that you parse. You can put the values in individual variables, in a %config hash, or you can put them in the %ENV hash, which is a copy of the shell's environment. Below are examples of each. I included the use of a hash slice. It's beyond what you should already understand as a newbie, but it's not that far of a stretch, if you're in the mood for it, and it has a certain conciceness.

use strict; use warnings; my $str = 'bar|development|/usr/bar/db|/dbdump'; # put the values into individual variables; my ($db,$host,$dbdir,$dumpdir); ($db,$host,$dbdir,$dumpdir) = split '\|',$str; # put the values into a hash my %conf; ( $conf{'DB'}, $conf{'HOST'}, $conf{'DBDIR'}, $conf{'DUMPDIR'} ) = split '\|',$str; # print out the hash with for (keys %conf) { print "$_ => $conf{$_}\n"; } # Use a hash slice. The %conf hash is given # a list of keys. The "=" assigns to each of them in turn @conf{('DB','HOST','DBDIR','DUMPDIR)} = split '\|',$str; # put the values into the %ENV hash, where the other # environment variables are @ENV{qw(DB HOST DBDIR DUMPDIR)} = split '\|',$str;

In reply to Re: Parse a pipe-delimited list by rodion
in thread Parse a pipe-delimited list by jhs3

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.