If you are extracting data from fixed width columns as seems to be the case here then you can use any of a number of techniques:

use strict; use warnings; my $table = <<DATA; LV NAME LPs PPs DISTRIBUTION MOUNT POINT loglv51 1 1 01..00..00..00..00 N/A lvsapinst 64 64 54..10..00..00..00 /tmp/sapinst_i +nstdir lvusrsap 25 25 00..25..00..00..00 /usr/sap DATA open IN, '<', \$table; while (<IN>) { chomp; my $name = substr $_, 0, 22; my $dist = substr $_, 34, 18; my $mount = substr $_, 56; print "$name $dist $mount\n"; } close IN; open IN, '<', \$table; while (<IN>) { chomp; my ($name, $dist, $mount) = /(.{22}).{12}(.{18}).{4}(.*)/; print "$name $dist $mount\n"; } close IN; open IN, '<', \$table; while (<IN>) { chomp; my ($name, undef, $dist, undef, $mount) = unpack ('a22a12a18a4a*', + $_); print "$name $dist $mount\n"; } close IN;

Prints:

LV NAME DISTRIBUTION MOUNT POINT loglv51 01..00..00..00..00 N/A lvsapinst 54..10..00..00..00 /tmp/sapinst_instdir lvusrsap 00..25..00..00..00 /usr/sap LV NAME DISTRIBUTION MOUNT POINT loglv51 01..00..00..00..00 N/A lvsapinst 54..10..00..00..00 /tmp/sapinst_instdir lvusrsap 00..25..00..00..00 /usr/sap LV NAME DISTRIBUTION MOUNT POINT loglv51 01..00..00..00..00 N/A lvsapinst 54..10..00..00..00 /tmp/sapinst_instdir lvusrsap 00..25..00..00..00 /usr/sap

Interestingly, none of these use split.


Perl is environmentally friendly - it saves trees

In reply to Re: split question by GrandFather
in thread split question by mikejones

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.