I am such a newly hatched user of Perl, I still have eggshells on my pants. This is my first question for perlmonks, and I hope I can find an easy answer.
I've been writing shell scripts and can get around there pretty well. I am trying to rewrite some of the shell scripts into Perl so I can use them both on Unix and Windows.
Working with multiple environments with multiple databases, I have a set of files that tells me stuff about the environment and the databases within the environment. An example: Environment is FOO. FOO has a number of databases. I have a text file called FOO.dbs to tell me about the databases in FOO. Each line of the FOO.dbs file is a pipe-delimited string that tells me the dbname, the host it runs on, the directory the db is on, the directory to do dump&load to, etc. An example of a line in the FOO.dbs would be:
bar|development|/usr/bar/db|/dbdump
Inside a script (shell script or perl) I read each line and pass the line to another script that parses the line and sets up variables for me to use. The subscript (parse-dbinfo) in Unix uses the 'cut' command to return the fields like this:
DB=`echo $1 | cut -f 1 -d "|"` HOST=`echo $1 | cut -f 2 -d "|"` DBDIR=`echo $1 | cut -f 3 -d "|"` DUMPDIR=`echo $1 | cut -f 4 -d "|"`
With this information, my shell script can work with the variables to get work done. I can refer to a specific database by '$DBDIR/$DB' to get '/usr/bar/db/bar'.
How can I duplicate the effect of the 'cut' to load the variables in PERL?

In reply to 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.