"Quenten Griffith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Hello all I have a script that reads in a control file
> that list a dir. to
> change to inside the control file I have
>
> Dir: /cf/courseware
>
> The part of the Perl script that I run to pull in that
> info is
>
> # Open the control file or log
> my $control_file= "/home/qgriff/FTP.CTL";
>  unless ( open CTL, $control_file ) { $log->write(
> "<Error> Could not open
> $control_file: $!");
>  exit 1;
>   }
>
> my ($site, $user, $password, $dir, $file );
> my $stanza = 0;
>   while ( <CTL> ) {
>     chop;
>     #skip all comments
>     next if /^\s*#/;
>     #skip blank lines
>     next unless length;
> #Check to see the control file has the site listed and
> pass it to $site
>     if ( /^Site:\s+(\w+)/ ) {
>        $site = $1;
>        $stanza = 1;
>        ($user, $password, $dir, $file ) = ('', '', '',
> '' );
>        next;
>        }
> if ($stanza) {
>            $user = $1 if /^User:\s+(\w+)/;
>    $password = $1 if /^Password:\s+(\w+)/;
>            <b>$dir = $1 if /^Dir:\s+(\W\w+\W\w+)/;</b>
>    $file = $1 if /^File:\s+(.+)$/;
>        if ( $user && $password && $dir && $file ) {
>              #Exit the loop
>      $stanza = 0;
>
> #Submit the job for the real work
>      &submit_job($site, $user, $password, $dir,
> $file);
>              }
>    }
>        }
>
> This line is what I am having an issue with $dir = $1
> if
> /^Dir:\s+(\W\w+\W\w+)/;
> That will match /your/path but it will not match /your
> or /your/path/is.

> Is there a better reg.exp. I can use that will match
> anything with a / in and everything after it so I can
> have /your our /your/path or even a dir. ten
> levels deep and it will still match it?

  /^Dir:\s+(\/\S+)/

will capture a slash and all following non-whitespace characters
after "Dir:" and some whitespace. This should do it for you
unless you could have spaces in the path?

By the way, use 'chomp' instead of 'chop'. The latter will
remove the last character from the string whether or not it
is a newline. The last line of a file may not be terminated
by a newline and you will lose valid data.

Cheers,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to