Hi all,
I have a script that I need to write that will clean up an /etc/hosts file which has lines of the format
IPADDRESS alias1 alias2 alias5
IPADDRESS2 alias3 alias4
IPADDRESS2 alias3 alias5
IPADDRESS2 alias3 alias5
for example and I need to rewrite it using a perl script to look like
IPADDRESS alias1 alias2 alias5
IPADDRESS2 alias3 alias4 alias5
Right now I have code to read the file line by line, and split that line. This new array of each line is what I need to work with.
I need to create a
@masterarray
that will contain an array of arrays for example, my final masterarray should be
masterarray[0] = [ IPADDRESS, alias1, alias2, alias5]
masterarray[1] = [ IPADDRESS2, alias3, alias4, alias5]
Is this possible.
My code when looping through each line of the file was originally going to
first check if the first field in
masterarray[0], masterarray[1], masterarray[x] and so on, was the same as the first part of my linearray (gotten from split) but I can't seem to read IPADDRESS out of
masterarray[0] = [ IPADDRESS, alias1, alias2, alias5]
How do i read it... Can I do
masterarray[0, 0] to read it? and also how can I add an extra alias to
masterarray [0] for example...like alias8, can't I just
push (masterarray[0] , alias8)
I get lots of errors when trying to do what I want but I am only a starter in Perl, hopefully one of you can help me out even a little bit!!
Thanks alot guys!
Mark
holli fixed formatting
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.