in reply to Parsing Login Scripts For Variable Assignment

You can clean up your parsing of continuation lines a bit with something like the following:
LINE: while (<LOGIN>) { chomp; if (s!\\$!!) { $_ .= <LOGIN>; redo LINE; } # At this point, we have gathered all the continuation lines into +1 line. # Now do the rest of the processing. next unless /PATH/; # here you have your PATH line, and can do whatever you need with +it. }
But, as jasonk, holo and Corion have noted, this isn't the biggest problem.

Replies are listed 'Best First'.
Re: Re: Parsing Login Scripts For Variable Assignment
by Limbic~Region (Chancellor) on Dec 09, 2003 at 15:02 UTC
    Paladin,
    Thanks! I still think it looks ugly, but with your suggestion I was able to do away with some code. Here is the modified code:
    my $path; while ( <LOGIN> ) { chomp; if ( s|\\$|| ) { $_ .= <LOGIN>; redo; } if ( /^\s*(export)?\s+PATH=(.*)/ ) { $path .= ':' if $path && substr($path, -1, 1) ne ':'; $path .= $2; } }
    Cheers - L~R