foreach my $line (<MAKFILE>) {

I personally believe you should know that almost always in Perl (5) the Right™ way to iterate over the lines of a file is a while loop. You should also be using lexical filehandles.

if ($line =~ m/SOURCE=\.\\(.*)$/i) {

I generally chomp too, but incidentally $ matches right before \n too; you may also push the return value of the match operator.

$fileLst = join " ", @fileLst;

Perhaps you prefer to be explicit, and I'm sure many people would say that you're right, but there's a very convenient shortcut for join " ", @fileLst, which is "@fileLst"; also, I see no reason to create an intermediate temporary variable just to return it.

All in all, I will give you an example subroutine which will accept a filename and give you your expected output:

sub domkfile { my ($fname, @flist)=shift; open my $fh, '<', $fname or die "Can't open `$fname': $!\n"; push @flist, /SOURCE=\.\\(.*)$/i while <$fh>; "@flist"; }

If slurping the whole file at once is not a problem, and indeed it should not be in this case, you may avoid the use of the @flist array with a map:

sub domkfile { my $fname=shift; open my $fh, '<', $fname or die "Can't open `$fname': $!\n"; join ' ' => map /SOURCE=\.\\(.*)$/i, <$fh>; }
--
If you can't understand the incipit, then please check the IPB Campaign.

In reply to Re^5: string manipulation by blazar
in thread string manipulation by Noame

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.