On Tue, 12 Jul 2005, Perl wrote:

> I have this perl script which is taking value from an external 
> appliaction and then after processing it is passing back a value to 
> same application. But I was not able to figure out how can I define 
> the variable my $path (which is taking value from external app). what 
> should be the syntex. Can somebody help me to set the syntex of the 
> variable to accept value from app.
> 
>  use strict;
>  use File::Basename;
>   my $path =  Value from other app;
>   my $base = basename($path);
>   my $dir  = dirname($path);
>   print STDOUT $base;

Try something like this:

    use strict;
    use File::Basename;
    my $path = get_value_from_other_app();
    my $base = basename($path);
    my $dir  = dirname($path);
    print STDOUT $base;

    sub get_value_from_other_app {
        my $app   = '/path/to/app';
        my $value = system( "$app" ) 
          or die "Couldn't successfully run $app: $!\n";
        return $value;
    }

The get_value_from_other_app() could really just be reduced to

    my $path = system( '/path/to/app' )
      or die "Couldn't successfully run $app: $!\n";

but if you want to get any fancier than that -- for example, if you want 
more robust error handling, etc -- then having that code broken out into 
a separate subroutine can make things easier to maintain, as the high 
order functionality of the script is all together up top, and the 
details of how sub-steps are done come later in chunks. 



-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to